X-Git-Url: https://code.kerkeslager.com/?p=fur;a=blobdiff_plain;f=integration_tests.py;h=7cc6d1a490edf6e2ce6a8b9219a8be40aa750d7c;hp=7669aea8652044b5898b75ea03d05dabc230c38b;hb=HEAD;hpb=ad9360cb4b392987edff8e3a650a2fbbc51f7046 diff --git a/integration_tests.py b/integration_tests.py index 7669aea..7cc6d1a 100644 --- a/integration_tests.py +++ b/integration_tests.py @@ -6,14 +6,53 @@ import unittest # Go to the directory of the current file so we know where we are in the filesystem os.chdir(os.path.dirname(os.path.abspath(__file__))) -class OutputTests(unittest.TestCase): +class InterpreterOutputTests(unittest.TestCase): pass -def add_example_output_test(filename): +def add_example_interpreter_output_test(filename): + def test(self): + p = subprocess.Popen( + ( + 'python', + 'main.py', + 'interpret', + os.path.join('examples', filename), + ), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + + actual_stdout, actual_stderr = p.communicate() + + expected_stdout_path = os.path.join('examples', filename + '.stdout.txt') + + if os.path.isfile(expected_stdout_path): + with open(expected_stdout_path, 'rb') as f: + expected_stdout = f.read() + else: + expected_stdout = b'' + + expected_stderr_path = os.path.join('examples', filename + '.stderr.txt') + + if os.path.isfile(expected_stderr_path): + with open(expected_stderr_path, 'rb') as f: + expected_stderr = f.read() + else: + expected_stderr = b'' + + self.assertEqual(expected_stderr, actual_stderr) + + setattr(InterpreterOutputTests, 'test_' + filename[:-4], test) + +class CompilerOutputTests(unittest.TestCase): + pass + +def add_example_compiler_output_test(filename): def test(self): compile_fur_to_c_result = subprocess.call([ 'python', 'main.py', + 'compile', os.path.join('examples', filename), ]) @@ -59,9 +98,9 @@ def add_example_output_test(filename): except OSError: pass - setattr(OutputTests, 'test_' + filename, test) + setattr(CompilerOutputTests, 'test_' + filename[:-4], test) -class MemoryLeakTest(unittest.TestCase): +class MemoryLeakTests(unittest.TestCase): pass def add_example_memory_leak_test(filename): @@ -95,7 +134,7 @@ def add_example_memory_leak_test(filename): '--show-reachable=yes', '--num-callers=20', '--track-fds=yes', - '--error-exitcode=666', + '--error-exitcode=42', '-q', './a.out', ], @@ -114,7 +153,7 @@ def add_example_memory_leak_test(filename): except OSError: pass - setattr(MemoryLeakTest, 'test_' + filename, test) + setattr(MemoryLeakTests, 'test_' + filename[:-4], test) filenames = ( entry.name @@ -124,7 +163,8 @@ filenames = ( ) for filename in filenames: - add_example_output_test(filename) + add_example_compiler_output_test(filename) + add_example_interpreter_output_test(filename) add_example_memory_leak_test(filename) unittest.main()