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
174 if os.path.exists(filepath):
175 raise BaseException(
'The test source at "{}" already exists.'.format(filepath))
176 if not os.path.exists(existingSource):
178 'The template source at "{}" does not exist.'.format(existingSource)
181 suites = [
"Integration"] + suite
183 templateContent = [
"BOOST_AUTO_TEST_SUITE({})".format(s)
for s
in suites]
185 "BOOST_AUTO_TEST_CASE({})".format(name),
186 "/* Test body goes here */",
188 templateContent += [
"// ORIGINAL START"]
190 with open(existingSource)
as f:
191 templateContent += [line.rstrip(
"\n")
for line
in f.readlines()]
193 templateContent += [
"// ORIGINAL END"]
194 templateContent += [
"BOOST_AUTO_TEST_SUITE_END() // " + s
for s
in reversed(suites)]
196 with open(filepath,
"w")
as f:
197 f.writelines([line +
"\n" for line
in templateContent])
208 parser = argparse.ArgumentParser(
209 description=
"preCICE integration test creation tool."
213 metavar=
"[test-suite/]TestCase",
215 help=
"The path to the test, the last component being the test name. "
216 "If executed within tests/, then the test will be created relative to the local directory. "
217 "Otherwise, the path will be assumed to be relative to the tests directory.",
220 "-n",
"--dry-run", action=
"store_true", help=
"print actions only"
225 metavar=
"[test-suite/]TestCase[.cpp|.xml]",
228 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.",
230 args = parser.parse_args()
232 print(
"Create directory {}".format(args.test.location))
234 os.makedirs(args.test.location, exist_ok=
True)
236 source = args.test.name +
".cpp"
237 config = args.test.name +
".xml"
238 sourcePath = args.test.location.joinpath(source)
239 configPath = args.test.location.joinpath(config)
241 if not args.template:
243 print(
"Create test source {}".format(source))
247 print(
"Create test config {}".format(config))
254 print(
"Create test source {} from {}".format(source, existingSource))
257 args.test.name, args.test.suites, sourcePath, existingSource
260 print(
"Copy test config {} from {}".format(config, existingConfig))
262 shutil.copyfile(existingConfig, configPath)
264 print(
"Remember to run tools/building/updateSourceFiles.py or make sourcesIndex")