1#!/usr/bin/env python
2#
3# Checks the formatting of uncrustify's own sources.
4#
5# * @author  Matthew Woehlke    June 2018
6#
7
8import argparse
9import os
10import sys
11
12import test_uncrustify as tu
13
14
15# -----------------------------------------------------------------------------
16def main(argv):
17    parser = argparse.ArgumentParser(description='Run uncrustify source tests')
18    tu.add_source_tests_arguments(parser)
19    args = tu.parse_args(parser)
20
21    # Get required filesystem information
22    root = os.path.dirname(tu.test_dir)
23    src_dir = os.path.join(root, 'src')
24    config = os.path.join(root, 'forUncrustifySources.cfg')
25
26    # Create tests
27    tests = []
28    for s in os.listdir(src_dir):
29        if os.path.splitext(s)[1] in ('.cpp', '.h'):
30            t = tu.SourceTest()
31            filepath = os.path.join(src_dir, s)
32            t.build(test_input=filepath, test_lang='CPP', test_config=config,
33                    test_expected=filepath)
34            tests.append(t)
35
36    counts = tu.run_tests(tests, args)
37    tu.report(counts)
38
39    if counts['failing'] > 0:
40        sys.exit(2)
41    if counts['mismatch'] > 0:
42        sys.exit(1)
43
44
45# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46
47if __name__ == '__main__':
48    sys.exit(main(sys.argv))
49