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)
50 class MemoryLeakTest(unittest.TestCase):
53 def add_example_memory_leak_test(filename):
55 compile_fur_to_c_result = subprocess.call([
58 os.path.join('examples', filename),
61 if compile_fur_to_c_result != 0:
62 raise Exception('Example "{}" did not compile'.format(filename))
64 compile_c_to_executable_result = subprocess.call([
67 os.path.join('examples', filename + '.c'),
70 if compile_c_to_executable_result != 0:
71 raise Exception('Example output "{}" did not compile'.format(filename + '.c'))
74 with open(os.devnull, 'w') as devnull:
76 actual_return = subprocess.call(
81 '--show-reachable=yes',
84 '--error-exitcode=666',
92 self.assertEqual(expected_return, actual_return)
94 # We don't clean up the C file in the finally clause because it can be useful to have in case of errors
95 os.remove(os.path.join('examples', filename + '.c'))
103 setattr(MemoryLeakTest, 'test_' + filename, test)
107 for entry in os.scandir('examples')
109 if entry.name.endswith('.fur')
112 for filename in filenames:
113 add_example_output_test(filename)
114 add_example_memory_leak_test(filename)