• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import os
4import unittest
5
6from utils import run_header_checker
7
8SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
9INPUT_DIR = os.path.join(SCRIPT_DIR, 'input')
10EXPECTED_DIR = os.path.join(SCRIPT_DIR, 'expected')
11
12class MyTest(unittest.TestCase):
13    @classmethod
14    def setUpClass(cls):
15        cls.maxDiff = None
16
17    def run_and_compare(self, input_path, expected_path, cflags=[]):
18        with open(expected_path, 'r') as f:
19            expected_output = f.read()
20        actual_output = run_header_checker(input_path, cflags)
21        self.assertEqual(actual_output, expected_output)
22
23    def run_and_compare_name(self, name, cflags=[]):
24        input_path = os.path.join(INPUT_DIR, name)
25        expected_path = os.path.join(EXPECTED_DIR, name)
26        self.run_and_compare(input_path, expected_path, cflags)
27
28    def run_and_compare_name_cpp(self, name, cflags=[]):
29        self.run_and_compare_name(name, cflags + ['-x', 'c++', '-std=c++11'])
30
31    def run_and_compare_name_c_cpp(self, name, cflags=[]):
32        self.run_and_compare_name(name, cflags)
33        self.run_and_compare_name_cpp(name, cflags)
34
35    def test_func_decl_no_args(self):
36        self.run_and_compare_name_c_cpp('func_decl_no_args.h')
37
38    def test_func_decl_one_arg(self):
39        self.run_and_compare_name_c_cpp('func_decl_one_arg.h')
40
41    def test_func_decl_two_args(self):
42        self.run_and_compare_name_c_cpp('func_decl_two_args.h')
43
44    def test_func_decl_one_arg_ret(self):
45        self.run_and_compare_name_c_cpp('func_decl_one_arg_ret.h')
46
47    def test_example1(self):
48        self.run_and_compare_name_cpp('example1.h')
49        self.run_and_compare_name_cpp('example2.h')
50
51if __name__ == '__main__':
52    unittest.main()
53