From 3a17cc11aa1916a13a24afe7fb75f22942586b9a Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 8 Jan 2024 10:22:42 +0100 Subject: [PATCH] Add option to read lists of tests from file. ``` -i FILE, --tests-file=FILE Loads the list of tests to execute from a file. Each line in the file is interpreted as the name of a test, or a group of tests, to execute, just like the tests would be specified on the command line. Empty lines and lines starting with ``#`` are ignored. (This format is compatible with that of the ``btest`` `StateFile `_.) ``` --- README | 10 +++++++++ btest | 27 +++++++++++++++++++++--- testing/Baseline/tests.tests-file/output | 8 +++++++ testing/tests/tests-file.test | 20 ++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 testing/Baseline/tests.tests-file/output create mode 100644 testing/tests/tests-file.test diff --git a/README b/README index eb6dbc9..2765b86 100644 --- a/README +++ b/README @@ -400,6 +400,14 @@ and 1 otherwise. Exit code 1 can also result in case of other errors. Retry any failed tests up to this many times to determine if they are unstable. +-i FILE, --tests-file=FILE + Loads the list of tests to execute from a file. Each line in the + file is interpreted as the name of a test, or a group of tests, to + execute, just like the tests would be specified on the command + line. Empty lines and lines starting with ``#`` are ignored. (This + format is compatible with that of the ``btest`` `StateFile + `_.) + .. _configuration file: configuration_ .. _configuration: @@ -558,6 +566,8 @@ configuration file: range. The default range is "1024-65535". ``StateFile`` + .. _state_file: + The name of the state file to record the names of failing tests. Default is ``.btest.failed.dat``. diff --git a/btest b/btest index be413d7..81ff386 100755 --- a/btest +++ b/btest @@ -193,12 +193,12 @@ def getOption(key, default, section="btest"): reBackticks = re.compile(r"`(([^`]|`)*)`") -def readStateFile(): +def readTestsFile(file): try: # Read state file. tests = [] - for line in open(StateFile): + for line in open(file, encoding="utf-8"): line = line.strip() if not line or line.startswith("#"): continue @@ -2937,6 +2937,15 @@ def parse_options(): "Can be specified multiple times." ), ) + optparser.add_option( + "-i", + "--tests-file", + action="store", + type="string", + dest="tests_file", + default="", + help=("Load list of tests to execute from file."), + ) optparser.set_defaults(mode="TEST") @@ -3201,11 +3210,17 @@ if __name__ == "__main__": Config.configured_tests = findTests(testdirs, True) if args: + if Options.tests_file: + error("cannot specify tests both on command line and with --tests-file") + tests = findTests(args) else: if Options.rerun: - (success, tests) = readStateFile() + if Options.tests_file: + error("cannot specify both --rerun and --tests-file") + + (success, tests) = readTestsFile(StateFile) if success: if not tests: @@ -3216,6 +3231,12 @@ if __name__ == "__main__": warning("cannot read state file, executing all tests") tests = Config.configured_tests + elif Options.tests_file: + (success, tests) = readTestsFile(Options.tests_file) + + if not success: + warning("cannot read file with tests: %s" % Options.tests_file) + else: tests = Config.configured_tests diff --git a/testing/Baseline/tests.tests-file/output b/testing/Baseline/tests.tests-file/output new file mode 100644 index 0000000..67a87e2 --- /dev/null +++ b/testing/Baseline/tests.tests-file/output @@ -0,0 +1,8 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +t1 ... ok +t2 ... failed +t3 ... ok +1 of 3 tests failed +t1 ... ok +t3 ... ok +all 2 tests successful diff --git a/testing/tests/tests-file.test b/testing/tests/tests-file.test new file mode 100644 index 0000000..c46ce9a --- /dev/null +++ b/testing/tests/tests-file.test @@ -0,0 +1,20 @@ +# %TEST-EXEC-FAIL: btest t1 t2 t3 >>output 2>&1 +# %TEST-EXEC: btest -i my-tests >>output 2>&1 +# %TEST-EXEC: btest-diff output + +%TEST-START-FILE t1 +@TEST-EXEC: exit 0 +%TEST-END-FILE + +%TEST-START-FILE t2 +@TEST-EXEC: exit 1 +%TEST-END-FILE + +%TEST-START-FILE t3 +@TEST-EXEC: exit 0 +%TEST-END-FILE + +%TEST-START-FILE my-tests +t1 +t3 +%TEST-END-FILE