1 """generate_test_macros.py 3 A simple module and default main execution to generate a listing of 4 ADD_TEST CMake macros for all non-disabled tests in a 5 google-test-based executable. 7 The default main function writes a list of macros to the given output 10 from __future__
import print_function
19 import pyne._argparse
as ap
22 """Return a list of google test names. 26 test_lines -- a list of the output of a google test exectuable 27 using the --gtest_list_tests flag. If the output is in a file, 28 test_lines are the result of file.readlines(). 32 for test_line
in test_lines:
33 line = test_line.decode().strip()
37 assert current_test
is not None 38 if str(line).lower().find(
"disabled") == -1:
39 tests.append(current_test + line)
43 """writes a list of test names as ADD_TEST cmake macros to an 47 tests -- a list of all test names to be added as ADD_TEST macros 49 exectuable -- the name of the test executable 50 output -- the output file to write to, if output is not 51 specified, the list of ADD_TEST macros will be written to stdout 56 lines.append(
"ADD_TEST(" + test +
" " + \
57 executable +
" " +
"--gtest_filter=" + test +
")")
59 lines.append(
"ADD_TEST(RegressionTests nosetests -v -w " + \
66 with open(output,
'a')
as f:
71 description =
"A simple script to add CTest ADD_TEST macros to a "+\
72 "file for every test in a google-test executable." 73 parser = ap.ArgumentParser(description=description)
75 executable =
'the path to the test exectuable to call' 76 parser.add_argument(
'--executable', help=executable, required=
True)
78 reg_dir =
"the regression tests directory" 79 parser.add_argument(
'--reg_dir', help=reg_dir, required=
True)
81 output =
"the file to write the ADD_TEST macros to "+\
82 "(nominally CTestTestfile.cmake)" 83 parser.add_argument(
'--output', help=output, required=
True)
85 args = parser.parse_args()
87 assert os.path.exists(args.executable)
88 assert os.path.exists(args.output)
90 rtn = subprocess.Popen([args.executable,
"--gtest_list_tests"],
91 stdout=subprocess.PIPE, shell=(os.name==
'nt'))
93 if rtn.returncode != 0:
94 raise OSError(
'Could not generate test list, return code: ' 95 + str(rtn.returncode) +
'.')
104 if __name__ ==
"__main__":
def write_macros_to_output(tests, executable, reg_dir, output=None)
def parse_tests(test_lines)