Skip to content

Commit

Permalink
Add a test for executeAndWait
Browse files Browse the repository at this point in the history
---
Signed-off-by: Michael Ferguson <[email protected]>
  • Loading branch information
mppf committed Aug 11, 2022
1 parent 503bd17 commit 6b98355
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/dyno/test/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

comp_unit_test(testQuoteStrings)
comp_unit_test(testQueryTimingAndTrace)
comp_unit_test(testIteratorAdapters)
comp_unit_test(testLLVMsupport)
comp_unit_test(testQueryTimingAndTrace)
comp_unit_test(testQuoteStrings)
comp_unit_test(testSubprocess)
77 changes: 77 additions & 0 deletions compiler/dyno/test/util/testSubprocess.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2021-2022 Hewlett Packard Enterprise Development LP
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "chpl/util/subprocess.h"

#include <cassert>

// always check assertions in this test
#ifdef NDEBUG
#undef NDEBUG
#endif

using namespace chpl;

// check that trying to run a nonexistant command returns an error
static void checkNonexistent() {
int rc;
std::vector<std::string> cmd;

cmd.clear();
cmd.push_back("./nonexistent-command");
rc = executeAndWait(cmd, "nonexistent-command description", true);
assert(rc != 0);

cmd.clear();
cmd.push_back("./nonexistent-command");
cmd.push_back("arg");
rc = executeAndWait(cmd, "nonexistent-command description", true);
assert(rc != 0);

cmd.clear();
cmd.push_back("/this/path/does/not/exist");
rc = executeAndWait(cmd, "path does not exist description", true);
assert(rc != 0);

cmd.clear();
cmd.push_back("/this/path/does/not/exist");
cmd.push_back("arg");
rc = executeAndWait(cmd, "path does not exist description", true);
assert(rc != 0);
}

// check that we can run /usr/bin/env and get 0 return code from it
static void checkEnv() {
int rc;
std::vector<std::string> cmd;

cmd.clear();
cmd.push_back("/usr/bin/env");
rc = executeAndWait(cmd, "testing that env can be run", true);
assert(rc == 0);

}

int main(int argc, char** argv) {

checkNonexistent();
checkEnv();

return 0;
}

0 comments on commit 6b98355

Please sign in to comment.