Add meson test --max-lines

Let's allow users to configure how many lines are shown at most when
a test fails.
pull/13302/head
Daan De Meyer 11 months ago committed by Jussi Pakkanen
parent c199faf980
commit a3d3efd3cf
  1. 1
      data/shell-completions/bash/meson
  2. 1
      data/shell-completions/zsh/_meson
  3. 8
      docs/markdown/Unit-tests.md
  4. 6
      docs/markdown/snippets/test_max_lines.md
  5. 11
      mesonbuild/mtest.py

@ -580,6 +580,7 @@ _meson-test() {
quiet
timeout-multiplier
setup
max-lines
test-args
)

@ -196,6 +196,7 @@ local -a meson_commands=(
'(--quiet -q)'{'--quiet','-q'}'[produce less output to the terminal]'
'(--timeout-multiplier -t)'{'--timeout-multiplier','-t'}'[a multiplier for test timeouts]:Python floating-point number: '
'--setup[which test setup to use]:test setup: '
'--max-lines[Maximum number of lines to show from a long test log]:Python integer number: '
'--test-args[arguments to pass to the tests]: : '
'*:Meson tests:__meson_test_names'
)

@ -274,6 +274,14 @@ other useful information as the environmental variables. This is
useful, for example, when you run the tests on Travis-CI, Jenkins and
the like.
By default, the output from tests will be limited to the last 100 lines. The
maximum number of lines to show can be configured with the `--max-lines` option
*(added 1.5.0)*:
```console
$ meson test --max-lines=1000 testname
```
**Timeout**
In the test case options, the `timeout` option is specified in a number of seconds.

@ -0,0 +1,6 @@
## The Meson test program supports a new "--max-lines" argument
By default `meson test` only shows the last 100 lines of test output from tests
that produce large amounts of output. This default can now be changed with the
new `--max-lines` option. For example, `--max-lines=1000` will increase the
maximum number of log output lines from 100 to 1000.

@ -161,6 +161,8 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
help='Which test setup to use.')
parser.add_argument('--test-args', default=[], type=split_args,
help='Arguments to pass to the specified test(s) or all tests')
parser.add_argument('--max-lines', default=100, dest='max_lines', type=int,
help='Maximum number of lines to show from a long test log. Since 1.5.0.')
parser.add_argument('args', nargs='*',
help='Optional list of test names to run. "testname" to run all tests with that name, '
'"subprojname:testname" to specifically run "testname" from "subprojname", '
@ -510,7 +512,8 @@ class ConsoleLogger(TestLogger):
HLINE = "\u2015"
RTRI = "\u25B6 "
def __init__(self) -> None:
def __init__(self, max_lines: int) -> None:
self.max_lines = max_lines
self.running_tests: OrderedSet['TestRun'] = OrderedSet()
self.progress_test: T.Optional['TestRun'] = None
self.progress_task: T.Optional[asyncio.Future] = None
@ -652,10 +655,10 @@ class ConsoleLogger(TestLogger):
return log
lines = log.splitlines()
if len(lines) < 100:
if len(lines) < self.max_lines:
return log
else:
return str(mlog.bold('Listing only the last 100 lines from a long log.\n')) + '\n'.join(lines[-100:])
return str(mlog.bold(f'Listing only the last {self.max_lines} lines from a long log.\n')) + '\n'.join(lines[-self.max_lines:])
def print_log(self, harness: 'TestHarness', result: 'TestRun') -> None:
if not result.verbose:
@ -1591,7 +1594,7 @@ class TestHarness:
self.name_max_len = 0
self.is_run = False
self.loggers: T.List[TestLogger] = []
self.console_logger = ConsoleLogger()
self.console_logger = ConsoleLogger(options.max_lines)
self.loggers.append(self.console_logger)
self.need_console = False
self.ninja: T.List[str] = None

Loading…
Cancel
Save