From 0877509ef6b9f6c44d0b11279c320c20d91a9f39 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 15 Nov 2024 11:11:41 +0100 Subject: [PATCH] mtest: rust: allow parsing doctest output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- mesonbuild/mtest.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 503cb14325dd..7742f6fc705f 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -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() @@ -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)