1#!/usr/bin/env python
2from __future__ import print_function
3import sys
4
5def normalize(content):
6    # Ignore newline differences (e.g. on Windows, std::endl is "\r\n") and any extra whitespace
7    # at beginning/end of content
8    return content.replace('\r\n', '\n').strip()
9
10if __name__ == '__main__':
11    assert len(sys.argv) == 4
12
13    test_name = sys.argv[1]
14    a_file_path = sys.argv[2]
15    b_file_path = sys.argv[3]
16    assert a_file_path != b_file_path
17
18    with open(a_file_path, 'rb') as a:
19        with open(b_file_path, 'rb') as b:
20            a_content = normalize(a.read())
21            b_content = normalize(b.read())
22            if a_content == b_content:
23                exit(0)
24            import difflib
25            diff = difflib.ndiff(a_content.splitlines(), b_content.splitlines(),
26                                 charjunk=lambda c: False)
27            diff = list(diff)
28
29            if diff:
30                print('Output headers of test %s differ:' % test_name, file=sys.stderr)
31                for line in diff:
32                    print(line, file=sys.stderr)
33                exit(1)
34