X-Git-Url: https://code.kerkeslager.com/?p=fur;a=blobdiff_plain;f=integration_tests.py;fp=integration_tests.py;h=ddf444b3d5ff9803373b3f8c81521adf8e32c810;hp=0000000000000000000000000000000000000000;hb=6c2894f00c8daca3d85c7ce850da711b9f7effc5;hpb=4ba4fcfbb2712a22a9f3211182c9ec6cee9dd0f8 diff --git a/integration_tests.py b/integration_tests.py new file mode 100644 index 0000000..ddf444b --- /dev/null +++ b/integration_tests.py @@ -0,0 +1,49 @@ +import os +import os.path +import subprocess +import unittest + +EXAMPLES_PATH = os.path.join(os.path.dirname(__file__), 'examples') + +class OutputTests(unittest.TestCase): + pass + +def add_example_output_test(filename): + def test(self): + compile_fur_to_c_result = subprocess.call([ + 'python', + 'main.py', + os.path.join(EXAMPLES_PATH, filename), + ]) + + if compile_fur_to_c_result != 0: + raise Exception('Example "{}" did not compile'.format(filename)) + + compile_c_to_executable_result = subprocess.call([ + 'gcc', + os.path.join(EXAMPLES_PATH, filename + '.c'), + ]) + + if compile_c_to_executable_result != 0: + raise Exception('Example output "{}" did not compile'.format(filename + '.c')) + + actual_output = subprocess.check_output(['./a.out']) + + with open(os.path.join(EXAMPLES_PATH, filename + '.output.txt'), 'rb') as f: + expected_output = f.read() + + self.assertEqual(expected_output, actual_output) + + setattr(OutputTests, 'test_' + filename, test) + +filenames = ( + entry.name + for entry in os.scandir(EXAMPLES_PATH) + if entry.is_file() + if entry.name.endswith('.fur') +) + +for filename in filenames: + add_example_output_test(filename) + +unittest.main()