Debian Codegraph @

test cases/format/7 recurse subprojects/compare_format_diff.py

raw
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: Apache-2.0
3 # Copyright © 2026 Arthur Grillo
4
5 import argparse
6 import subprocess
7 import sys
8 import difflib
9
10
11 def compare(actual: str, expected: str) -> int:
12 if actual == expected:
13 return 0
14
15 diff = difflib.ndiff(expected, actual)
16 for line in diff:
17 print(line, file=sys.stderr, end='')
18 return 1
19
20 def main() -> int:
21 parser = argparse.ArgumentParser()
22 parser.add_argument('meson_cmd_path', nargs='+')
23
24 args = parser.parse_args()
25
26 result = subprocess.run([
27 *args.meson_cmd_path,
28 'format',
29 '--recursive',
30 '--subprojects',
31 '--check-diff',
32 ], capture_output=True, text=True)
33
34 with open('subprojects/find-me/expected.diff', 'r', encoding='utf-8') as f:
35 actual = result.stdout.replace('\\', '/')
36 expected = f.read()
37
38 return compare(
39 actual,
40 expected,
41 )
42
43 if __name__ == "__main__":
44 sys.exit(main())