6 # Go to the directory of the current file so we know where we are in the filesystem
7 os.chdir(os.path.dirname(os.path.abspath(__file__)))
9 class OutputTests(unittest.TestCase):
12 def add_example_output_test(filename):
14 compile_fur_to_c_result = subprocess.call([
17 os.path.join('examples', filename),
20 if compile_fur_to_c_result != 0:
21 raise Exception('Example "{}" did not compile'.format(filename))
23 compile_c_to_executable_result = subprocess.call([
25 os.path.join('examples', filename + '.c'),
28 if compile_c_to_executable_result != 0:
29 raise Exception('Example output "{}" did not compile'.format(filename + '.c'))
32 actual_output = subprocess.check_output(['./a.out'])
34 with open(os.path.join('examples', filename + '.output.txt'), 'rb') as f:
35 expected_output = f.read()
37 self.assertEqual(expected_output, actual_output)
39 # We don't clean up the C file in the finally clause because it can be useful to have in case of errors
40 os.remove(os.path.join('examples', filename + '.c'))
48 setattr(OutputTests, 'test_' + filename, test)
52 for entry in os.scandir('examples')
54 if entry.name.endswith('.fur')
57 for filename in filenames:
58 add_example_output_test(filename)