+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()
+
+ 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)
+
+ # 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'))
+
+ finally:
+ try:
+ os.remove('a.out')
+ except OSError:
+ pass
+
+ setattr(InterpreterOutputTests, 'test_' + filename, test)
+
+class CompilerOutputTests(unittest.TestCase):
+ pass
+
+def add_example_compiler_output_test(filename):