aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-09-21 01:38:30 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-09-23 16:10:32 -0400
commit462759dd3319d47f4c09a63ee8dfc5deab7eef63 (patch)
tree73f79c1068516afdcf11fa45b7c21df7381f469f
parentbed5b31079823f1f2a05b43abd5b148d17c777aa (diff)
downloadmeson-462759dd3319d47f4c09a63ee8dfc5deab7eef63.zip
meson-462759dd3319d47f4c09a63ee8dfc5deab7eef63.tar.gz
meson-462759dd3319d47f4c09a63ee8dfc5deab7eef63.tar.bz2
mtest: implement a maxfail option
This allows early exit of the project tests once a certain number of failures are detected. For example `meson test --maxfail=1` will abort as soon as a single test fails. Currently running tests are marked as failed via INTERRUPT. Resolves #9352
-rw-r--r--docs/markdown/snippets/test-maxfail.md6
-rw-r--r--mesonbuild/mtest.py6
2 files changed, 12 insertions, 0 deletions
diff --git a/docs/markdown/snippets/test-maxfail.md b/docs/markdown/snippets/test-maxfail.md
new file mode 100644
index 0000000..1487977
--- /dev/null
+++ b/docs/markdown/snippets/test-maxfail.md
@@ -0,0 +1,6 @@
+## Option to allow meson test to fail fast after the first failing testcase
+
+`meson test --maxfail=1` will now cause all pending or in-progress tests to be
+canceled or interrupted after 1 test is marked as failing. This can be used for
+example to quit a CI run and avoid burning additional time as soon as it is
+known that the overall return status will be failing.
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index c03c3eb..981bc10 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -94,6 +94,9 @@ def determine_worker_count() -> int:
return num_workers
def add_arguments(parser: argparse.ArgumentParser) -> None:
+ parser.add_argument('--maxfail', default=0, type=int,
+ help='Number of failing tests before aborting the '
+ 'test run. (default: 0, to disable aborting on failure)')
parser.add_argument('--repeat', default=1, dest='repeat', type=int,
help='Number of times to run the tests.')
parser.add_argument('--no-rebuild', default=False, action='store_true',
@@ -1912,6 +1915,9 @@ class TestHarness:
return
res = await test.run(self)
self.process_test_result(res)
+ maxfail = self.options.maxfail
+ if maxfail and self.fail_count >= maxfail and res.res.is_bad():
+ cancel_all_tests()
def test_done(f: asyncio.Future) -> None:
if not f.cancelled():