Skip to content

Commit

Permalink
mtest: rust: allow parsing doctest output
Browse files Browse the repository at this point in the history
Doctests have a slightly different output compared to what "protocol: rust"
supports:

   running 2 tests
   test rust/qemu-api/libqemu_api.rlib.p/structured/lib.rs - QemuAllocator (line 49) ... ignored
   test rust/qemu-api/libqemu_api.rlib.p/structured/zeroable.rs - zeroable::Zeroable (line 9) ... ok

   test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.11s

Add a little more parsing in order to parse this correctly.  I plan to
contribute an extension of the rust module to invoke doctests, for now
this allows running rustdoc --test with "protocol: rust" and get
information about the subtests:

   2/3 qemu:unit+rust / rust-qemu-api-doctests           RUNNING
   ...
   ▶ 2/3 test rust/qemu-api/libqemu_api.rlib.p/structured/lib.rs:QemuAllocator:49 SKIP
   ▶ 2/3 test rust/qemu-api/libqemu_api.rlib.p/structured/zeroable.rs:zeroable.Zeroable:9 OK
   2/3 qemu:unit+rust / rust-qemu-api-doctests           OK              1.20s   1 subtests passed

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Nov 15, 2024
1 parent bfce145 commit a2cca71
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mesonbuild/mtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
UNENCODABLE_XML_CHR_RANGES = [fr'{chr(low)}-{chr(high)}' for (low, high) in UNENCODABLE_XML_UNICHRS]
UNENCODABLE_XML_CHRS_RE = re.compile('([' + ''.join(UNENCODABLE_XML_CHR_RANGES) + '])')

RUST_TEST_RE = re.compile(r'^test (?!result)(.*) \.\.\. (.*)$')
RUST_DOCTEST_RE = re.compile(r'^(.*?) - (.*?) \(line (\d+)\)')


def is_windows() -> bool:
platname = platform.system().lower()
Expand Down Expand Up @@ -1157,8 +1160,12 @@ def parse_res(n: int, name: str, result: str) -> TAPParser.Test:

n = 1
async for line in lines:
if line.startswith('test ') and not line.startswith('test result'):
_, name, _, result = line.rstrip().split(' ')
match = RUST_TEST_RE.match(line)
if match:
name, result = match.groups()
doctest = RUST_DOCTEST_RE.match(name)
if doctest:
name = ':'.join(doctest.groups())
name = name.replace('::', '.')
t = parse_res(n, name, result)
self.results.append(t)
Expand Down

0 comments on commit a2cca71

Please sign in to comment.