Skip to content

Commit

Permalink
Add meson test --max-lines
Browse files Browse the repository at this point in the history
Let's allow users to configure how many lines are shown at most when
a test fails.
  • Loading branch information
DaanDeMeyer authored and jpakkane committed Jun 17, 2024
1 parent c199faf commit a3d3efd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions data/shell-completions/bash/meson
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ _meson-test() {
quiet
timeout-multiplier
setup
max-lines
test-args
)

Expand Down
1 change: 1 addition & 0 deletions data/shell-completions/zsh/_meson
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down
8 changes: 8 additions & 0 deletions docs/markdown/Unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions docs/markdown/snippets/test_max_lines.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 7 additions & 4 deletions mesonbuild/mtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", '
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -652,10 +655,10 @@ def shorten_log(self, harness: 'TestHarness', result: 'TestRun') -> str:
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:
Expand Down Expand Up @@ -1591,7 +1594,7 @@ def __init__(self, options: argparse.Namespace):
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
Expand Down

0 comments on commit a3d3efd

Please sign in to comment.