54 raise argparse.ArgumentTypeError(
55 'The given suite name "{}" cannot contain spaces.'.format(arg)
58 raise argparse.ArgumentTypeError(
59 'The given suite name "{}" cannot contain the file extensions.'.format(arg)
61 if re.search(
r"[^a-z-]", arg)
is not None:
62 raise argparse.ArgumentTypeError(
63 'The given suite dir "{}" must be dashed-lower-case.'.format(arg)
65 if re.search(
r"^[a-z]", arg)
is None:
66 raise argparse.ArgumentTypeError(
67 'The given suite dir "{}" must start with a lowercase letter'.format(arg)
69 if re.search(
r"[a-z]$", arg)
is None:
70 raise argparse.ArgumentTypeError(
71 'The given suite dir "{}" must end with a lowercase letter'.format(arg)
95 Checks the given test argument and computes:
96 - the location as pathlib.PurePath
97 - the suites as a list of suite names
98 - the name of the test
100 parts = pathlib.PurePath(arg).parts
101 dirs, name = parts[:-1], parts[-1]
106 full = pathlib.Path(arg).absolute()
109 parts = full.relative_to(tests).parts
110 dirs, name = parts[:-1], parts[-1]
114 location = tests.joinpath(*dirs)
115 if location.exists()
and not location.is_dir():
116 raise argparse.ArgumentTypeError(
117 'The given test location "{}" exists, but is not a directory.'.format(
123 return collections.namedtuple(
"TestSetup",
"location suites name")(
124 location, suites, name
175 if os.path.exists(filepath):
176 raise BaseException(
'The test source at "{}" already exists.'.format(filepath))
177 if not os.path.exists(existingSource):
179 'The template source at "{}" does not exist.'.format(existingSource)
182 suites = [
"Integration"] + suite
184 templateContent = [
"BOOST_AUTO_TEST_SUITE({})".format(s)
for s
in suites]
186 "BOOST_AUTO_TEST_CASE({})".format(name),
187 "/* Test body goes here */",
189 templateContent += [
"// ORIGINAL START"]
191 with open(existingSource)
as f:
192 templateContent += [line.rstrip(
"\n")
for line
in f.readlines()]
194 templateContent += [
"// ORIGINAL END"]
195 templateContent += [
"BOOST_AUTO_TEST_SUITE_END() // " + s
for s
in reversed(suites)]
197 with open(filepath,
"w")
as f:
198 f.writelines([line +
"\n" for line
in templateContent])
209 parser = argparse.ArgumentParser(
210 description=
"preCICE integration test creation tool."
214 metavar=
"[test-suite/]TestCase",
216 help=
"The path to the test, the last component being the test name. "
217 "If executed within tests/, then the test will be created relative to the local directory. "
218 "Otherwise, the path will be assumed to be relative to the tests directory.",
221 "-n",
"--dry-run", action=
"store_true", help=
"print actions only"
226 metavar=
"[test-suite/]TestCase[.cpp|.xml]",
229 help=
"Test to use the given cpp and xml as a template to create a new test. Adds a comment to the top of the test to help changes.",
231 args = parser.parse_args()
233 print(
"Create directory {}".format(args.test.location))
235 os.makedirs(args.test.location, exist_ok=
True)
237 source = args.test.name +
".cpp"
238 config = args.test.name +
".xml"
239 sourcePath = args.test.location.joinpath(source)
240 configPath = args.test.location.joinpath(config)
242 if not args.template:
244 print(
"Create test source {}".format(source))
248 print(
"Create test config {}".format(config))
255 print(
"Create test source {} from {}".format(source, existingSource))
258 args.test.name, args.test.suites, sourcePath, existingSource
261 print(
"Copy test config {} from {}".format(config, existingConfig))
263 shutil.copyfile(existingConfig, configPath)
265 print(
"Remember to run tools/building/updateSourceFiles.py or make sourcesIndex")