summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Unit-tests.md3
-rw-r--r--docs/markdown/snippets/test_iteration.md5
-rw-r--r--mesonbuild/mtest.py5
3 files changed, 11 insertions, 2 deletions
diff --git a/docs/markdown/Unit-tests.md b/docs/markdown/Unit-tests.md
index 73e58dc68..6fda0f5f6 100644
--- a/docs/markdown/Unit-tests.md
+++ b/docs/markdown/Unit-tests.md
@@ -208,6 +208,9 @@ Sometimes you need to run the tests multiple times, which is done like this:
$ meson test --repeat=10
```
+Meson will set the `MESON_TEST_ITERATION` environment variable to the
+current iteration of the test *(added 1.5.0)*.
+
Invoking tests via a helper executable such as Valgrind can be done with the
`--wrap` argument
diff --git a/docs/markdown/snippets/test_iteration.md b/docs/markdown/snippets/test_iteration.md
new file mode 100644
index 000000000..67daf2781
--- /dev/null
+++ b/docs/markdown/snippets/test_iteration.md
@@ -0,0 +1,5 @@
+## meson test now sets the `MESON_TEST_ITERATION` environment variable
+
+`meson test` will now set the `MESON_TEST_ITERATION` environment variable to the
+current iteration of the test. This will always be `1` unless `--repeat` is used
+to run the same test multiple times.
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index 460a44c49..03d2eb254 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -1709,7 +1709,7 @@ class TestHarness:
sys.exit('Conflict: both test setup and command line specify an exe wrapper.')
return current.env.get_env(os.environ.copy())
- def get_test_runner(self, test: TestSerialisation) -> SingleTestRunner:
+ def get_test_runner(self, test: TestSerialisation, iteration: int) -> SingleTestRunner:
name = self.get_pretty_suite(test)
options = deepcopy(self.options)
if self.options.setup:
@@ -1721,6 +1721,7 @@ class TestHarness:
if (test.is_cross_built and test.needs_exe_wrapper and
test.exe_wrapper and test.exe_wrapper.found()):
env['MESON_EXE_WRAPPER'] = join_args(test.exe_wrapper.get_command())
+ env['MESON_TEST_ITERATION'] = str(iteration + 1)
return SingleTestRunner(test, env, name, options)
def process_test_result(self, result: TestRun) -> None:
@@ -1822,7 +1823,7 @@ class TestHarness:
os.chdir(self.options.wd)
runners: T.List[SingleTestRunner] = []
for i in range(self.options.repeat):
- runners.extend(self.get_test_runner(test) for test in tests)
+ runners.extend(self.get_test_runner(test, i) for test in tests)
if i == 0:
self.duration_max_len = max(len(str(int(runner.timeout or 99)))
for runner in runners)