MCPcopy Create free account
hub / github.com/Kitware/VTK / TestExecutableRunner

Function TestExecutableRunner

Common/System/Testing/Cxx/TestExecutableRunner.cxx:13–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <vector>
12
13int TestExecutableRunner(int, char*[])
14{
15 vtkNew<vtkExecutableRunner> process;
16 process->SetCommand("echo Hello World");
17 process->Execute();
18 std::string out = process->GetStdOut();
19 std::string err = process->GetStdErr();
20 int code = process->GetReturnValue();
21 int returnValue = EXIT_SUCCESS;
22
23 // ---
24 if (code != 0)
25 {
26 std::cerr << " === ERROR: command did not succeed" << std::endl;
27 returnValue = EXIT_FAILURE;
28 }
29 if (out != "Hello World")
30 {
31 std::cerr << " === ERROR: wrong command output. Got '" << out << "' but expected 'Hello World'."
32 << std::endl;
33 returnValue = EXIT_FAILURE;
34 }
35 if (!err.empty())
36 {
37 std::cerr << " === ERROR: there is output in the error stream : \n --- \n"
38 << err << "\n --- " << std::endl;
39 returnValue = EXIT_FAILURE;
40 }
41
42 // ---
43 process->Execute();
44 if (process->GetStdOut() != out || process->GetStdErr() != err ||
45 process->GetReturnValue() != code)
46 {
47 std::cerr << " === ERROR: ran twice the same command, expected the same result" << std::endl;
48 returnValue = EXIT_FAILURE;
49 }
50
51 // ---
52 process->SetCommand("abcdefghijklmnopqrstuvw");
53 // Disable global logger for this test as we don't want the error returned by the filter
54 // to mess with our test
55 int warning = vtkObject::GetGlobalWarningDisplay();
56 vtkObject::SetGlobalWarningDisplay(0);
57 process->Execute();
58 vtkObject::SetGlobalWarningDisplay(warning);
59 code = process->GetReturnValue();
60 if (code == 0)
61 {
62 std::cerr << " === ERROR: command did not return a failure but was supposed to." << std::endl;
63 returnValue = EXIT_FAILURE;
64 }
65
66 // ---
67 process->SetExecuteInSystemShell(false);
68#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
69 process->SetCommand("cmd.exe");
70 process->AddArgument("/c");

Callers

nothing calls this directly

Calls 4

GetReturnValueMethod · 0.80
ExecuteMethod · 0.45
emptyMethod · 0.45
AddArgumentMethod · 0.45

Tested by

no test coverage detected