6 EXAMPLES_PATH = os.path.join(os.path.dirname(__file__), 'examples')
8 class OutputTests(unittest.TestCase):
11 def add_example_output_test(filename):
13 compile_fur_to_c_result = subprocess.call([
16 os.path.join(EXAMPLES_PATH, filename),
19 if compile_fur_to_c_result != 0:
20 raise Exception('Example "{}" did not compile'.format(filename))
22 compile_c_to_executable_result = subprocess.call([
24 os.path.join(EXAMPLES_PATH, filename + '.c'),
27 if compile_c_to_executable_result != 0:
28 raise Exception('Example output "{}" did not compile'.format(filename + '.c'))
30 actual_output = subprocess.check_output(['./a.out'])
32 with open(os.path.join(EXAMPLES_PATH, filename + '.output.txt'), 'rb') as f:
33 expected_output = f.read()
35 self.assertEqual(expected_output, actual_output)
37 setattr(OutputTests, 'test_' + filename, test)
41 for entry in os.scandir(EXAMPLES_PATH)
43 if entry.name.endswith('.fur')
46 for filename in filenames:
47 add_example_output_test(filename)