| 1 |
/*========================================================================= |
| 2 |
* |
| 3 |
* Copyright NumFOCUS |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
* |
| 17 |
*=========================================================================*/ |
| 18 |
// Put kwssys/Configure.h first for proper compiler warning suppression: |
| 19 |
#include <kwssys/Configure.h> |
| 20 |
|
| 21 |
#include <iostream> |
| 22 |
#include <kwssys/Process.h> |
| 23 |
|
| 24 |
int kwsRunKWStyleTest(int , char* argv[] ) |
| 25 |
{ |
| 26 |
argv++; |
| 27 |
|
| 28 |
// Run KWSTyle |
| 29 |
kwssysProcess* gp = kwssysProcess_New(); |
| 30 |
kwssysProcess_SetCommand(gp,argv); |
| 31 |
kwssysProcess_Execute(gp); |
| 32 |
|
| 33 |
kwssysProcess_WaitForExit(gp, nullptr); |
| 34 |
|
| 35 |
int result = 1; |
| 36 |
switch(kwssysProcess_GetState(gp)) |
| 37 |
{ |
| 38 |
case kwssysProcess_State_Exited: |
| 39 |
{ |
| 40 |
result = kwssysProcess_GetExitValue(gp); |
| 41 |
} break; |
| 42 |
case kwssysProcess_State_Error: |
| 43 |
{ |
| 44 |
std::cerr << "Error: Could not run " << argv[0] << ":\n"; |
| 45 |
std::cerr << kwssysProcess_GetErrorString(gp) << "\n"; |
| 46 |
} break; |
| 47 |
case kwssysProcess_State_Exception: |
| 48 |
{ |
| 49 |
std::cerr << "Error: " << argv[0] |
| 50 |
<< " terminated with an exception: " |
| 51 |
<< kwssysProcess_GetExceptionString(gp) << "\n"; |
| 52 |
} break; |
| 53 |
case kwssysProcess_State_Starting: |
| 54 |
case kwssysProcess_State_Executing: |
| 55 |
case kwssysProcess_State_Expired: |
| 56 |
case kwssysProcess_State_Killed: |
| 57 |
{ |
| 58 |
// Should not get here. |
| 59 |
std::cerr << "Unexpected ending state after running " << argv[0] |
| 60 |
<< std::endl; |
| 61 |
} break; |
| 62 |
} |
| 63 |
kwssysProcess_Delete(gp); |
| 64 |
|
| 65 |
return 0; |
| 66 |
} |