"""Print a nextest filterset per line, one per test that the first `cargo nextest list --message-format json` listing holds and none of the others does. With the `--cfg m2v_cpu_icd` build's listing first and the plain builds' after it, these are the device tests: a test that opens a device compiles only under that cfg, and the plain builds' tests run on the host. Run as `python3 -I only_in.py CFG.json PLAIN.json...`.""" import json import sys def tests(path: str) -> set[tuple[str, str]]: with open(path, encoding="utf-8") as listing: suites = json.load(listing)["rust-suites"] return {(binary, test) for binary, suite in suites.items() for test in suite["testcases"]} def main() -> None: if len(sys.argv) < 3: sys.exit("usage: only_in.py CFG.json PLAIN.json...") plain: set[tuple[str, str]] = set() for path in sys.argv[2:]: plain |= tests(path) only = sorted(tests(sys.argv[1]) - plain) if not only: sys.exit(f"only_in: every test of {sys.argv[1]} is in a plain listing too") for binary, test in only: # A filterset's matcher ends at its closing parenthesis. if any(mark in binary + test for mark in "(),"): sys.exit(f"only_in: {binary} {test} cannot be written as a filterset") print(f"binary_id(={binary}) & test(={test})") main()