summaryrefslogtreecommitdiff
path: root/test cases/format
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2024-08-19 15:47:58 -0700
committerDylan Baker <dylan@pnwbakers.com>2024-08-20 11:41:00 -0700
commitab3cfc2da1c481f52a5525e41150626a2f66de3b (patch)
tree5087f1fcf98856c76d62f64891a0ad5dfca5aa05 /test cases/format
parent7280639cb5967beefa85b561dcbd096bcf05db3d (diff)
downloadmeson-ab3cfc2da1c481f52a5525e41150626a2f66de3b.tar.gz
tests/format: Make the compare script more useful
Now it will generate a diff of the expected value and what it actually got
Diffstat (limited to 'test cases/format')
-rw-r--r--test cases/format/5 transform/file_compare.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/test cases/format/5 transform/file_compare.py b/test cases/format/5 transform/file_compare.py
index 7b0d1b856..fd3ce1056 100644
--- a/test cases/format/5 transform/file_compare.py
+++ b/test cases/format/5 transform/file_compare.py
@@ -1,7 +1,31 @@
#!/usr/bin/env python3
+# SPDX-License-Identifier: Apache-2.0
+# Copyright © 2024 Intel Corporation
+import argparse
import sys
+import difflib
-with open(sys.argv[1], 'r', encoding='utf-8') as f, open(sys.argv[2], 'r', encoding='utf-8') as g:
- if f.read() != g.read():
- sys.exit('contents are not equal')
+
+def main() -> int:
+ parser = argparse.ArgumentParser()
+ parser.add_argument('actual', help='The transformed contents')
+ parser.add_argument('expected', help='the contents we expected')
+ args = parser.parse_args()
+
+ with open(args.actual, 'r') as f:
+ actual = f.readlines()
+ with open(args.expected, 'r') as f:
+ expected = f.readlines()
+
+ if actual == expected:
+ return 0
+
+ diff = difflib.ndiff(expected, actual)
+ for line in diff:
+ print(line, file=sys.stderr, end='')
+ return 1
+
+
+if __name__ == "__main__":
+ sys.exit(main())