X-Git-Url: https://code.kerkeslager.com/?p=fur;a=blobdiff_plain;f=integration_tests.py;h=7cc6d1a490edf6e2ce6a8b9219a8be40aa750d7c;hp=b5ad3219492c6013561d4c1c2dc7880cffff129a;hb=d70666abc2db430300d48691046ada2395b2f0d5;hpb=732b4ed7f693a328509b94d7137f3210c9c4042f diff --git a/integration_tests.py b/integration_tests.py index b5ad321..7cc6d1a 100644 --- a/integration_tests.py +++ b/integration_tests.py @@ -11,45 +11,38 @@ class InterpreterOutputTests(unittest.TestCase): def add_example_interpreter_output_test(filename): def test(self): - try: - p = subprocess.Popen( - 'python main.py interpret {}'.format( - os.path.join('examples', filename), - ), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - - actual_stdout, actual_stderr = p.communicate() + p = subprocess.Popen( + ( + 'python', + 'main.py', + 'interpret', + os.path.join('examples', filename), + ), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) - 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'' + actual_stdout, actual_stderr = p.communicate() - expected_stderr_path = os.path.join('examples', filename + '.stderr.txt') + expected_stdout_path = os.path.join('examples', filename + '.stdout.txt') - if os.path.isfile(expected_stderr_path): - with open(expected_stderr_path, 'rb') as f: - expected_stderr = f.read() - else: - expected_stderr = b'' + if os.path.isfile(expected_stdout_path): + with open(expected_stdout_path, 'rb') as f: + expected_stdout = f.read() + else: + expected_stdout = b'' - self.assertEqual(expected_stderr, actual_stderr) + expected_stderr_path = os.path.join('examples', filename + '.stderr.txt') - # We don't clean up the C file in the finally clause because it can be useful to have in case of errors - os.remove(os.path.join('examples', filename + '.c')) + if os.path.isfile(expected_stderr_path): + with open(expected_stderr_path, 'rb') as f: + expected_stderr = f.read() + else: + expected_stderr = b'' - finally: - try: - os.remove('a.out') - except OSError: - pass + self.assertEqual(expected_stderr, actual_stderr) - setattr(InterpreterOutputTests, 'test_' + filename, test) + setattr(InterpreterOutputTests, 'test_' + filename[:-4], test) class CompilerOutputTests(unittest.TestCase): pass @@ -105,7 +98,7 @@ def add_example_compiler_output_test(filename): except OSError: pass - setattr(CompilerOutputTests, 'test_' + filename, test) + setattr(CompilerOutputTests, 'test_' + filename[:-4], test) class MemoryLeakTests(unittest.TestCase): pass @@ -160,7 +153,7 @@ def add_example_memory_leak_test(filename): except OSError: pass - setattr(MemoryLeakTests, 'test_' + filename, test) + setattr(MemoryLeakTests, 'test_' + filename[:-4], test) filenames = ( entry.name