2024-07-16 08:30:35 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import argparse, os, sys
|
|
|
|
|
import lib.cmd_utils as cmd_utils
|
2024-07-17 08:22:46 +00:00
|
|
|
import lib.env as env
|
2024-07-16 08:30:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2024-07-17 08:22:46 +00:00
|
|
|
# important: load venv before loading modules that install deps.
|
|
|
|
|
env.ensure_in_venv(__file__)
|
|
|
|
|
|
2024-07-16 08:30:35 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
parser.add_argument("--unit-tests", action="store_true")
|
|
|
|
|
parser.add_argument("--integ-tests", action="store_true")
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--filter-file",
|
|
|
|
|
type=str,
|
|
|
|
|
help="Takes the base filename without extension and uses it as a filter",
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--ignore-return-code",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Ignore the return code of the test command",
|
|
|
|
|
)
|
2024-07-17 08:22:46 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--valgrind",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Run the test command with valgrind",
|
|
|
|
|
)
|
2024-07-16 08:30:35 +00:00
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
binary = get_binary_path(args)
|
2024-07-17 08:22:46 +00:00
|
|
|
|
2024-07-16 08:30:35 +00:00
|
|
|
if args.filter_file:
|
|
|
|
|
file_base = os.path.basename(args.filter_file)
|
|
|
|
|
without_ext = os.path.splitext(file_base)[0]
|
|
|
|
|
command = [binary, f"--gtest_filter={without_ext}*"]
|
|
|
|
|
else:
|
|
|
|
|
command = [binary]
|
|
|
|
|
|
2024-07-17 08:22:46 +00:00
|
|
|
if args.valgrind:
|
|
|
|
|
command = ["valgrind"] + command
|
|
|
|
|
|
2024-07-16 08:30:35 +00:00
|
|
|
result = cmd_utils.run(command, print_cmd=True, check=False)
|
|
|
|
|
if not args.ignore_return_code:
|
|
|
|
|
sys.exit(result.returncode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_binary_path(args):
|
|
|
|
|
base_dir = "./build/bin"
|
|
|
|
|
if args.unit_tests:
|
|
|
|
|
return f"{base_dir}/unittests"
|
|
|
|
|
elif args.integ_tests:
|
|
|
|
|
return f"{base_dir}/integtests"
|
|
|
|
|
else:
|
|
|
|
|
raise RuntimeError("No test type specified")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|