9 FILE_PATH = os.path.dirname(os.path.realpath(__file__))
10 INTEGRATION_TEST_DIRECTORY_PATH = os.path.join(FILE_PATH, 'integration_tests')
13 integration_test_file_names = [
15 for fn in os.listdir(INTEGRATION_TEST_DIRECTORY_PATH) \
16 if fn.endswith('.stt')
19 C_SOURCE_FILE_PATH = os.path.join(FILE_PATH, 'a.c')
20 BINARY_PATH = os.path.join(FILE_PATH, 'a.out')
22 def generate_test(input_file_name):
23 input_file_path = os.path.join(INTEGRATION_TEST_DIRECTORY_PATH, input_file_name)
24 expected_output_file_path = input_file_path[:-4] + '.txt'
27 c_source = subprocess.check_output(['python','stutter.py',input_file_path])
29 self.assertIsNotNone(c_source)
30 self.assertNotEqual(0, len(c_source))
32 with open(C_SOURCE_FILE_PATH,'wb') as c_source_file:
33 c_source_file.write(c_source)
35 cc_result = subprocess.call([CC, C_SOURCE_FILE_PATH])
37 self.assertEqual(0, cc_result)
39 with open(expected_output_file_path, 'rb') as expected_output_file:
40 expected_output = expected_output_file.read()
42 actual_output = subprocess.check_output(BINARY_PATH)
44 self.assertEqual(expected_output, actual_output)
48 class IntegrationTests(unittest.TestCase):
51 os.remove(C_SOURCE_FILE_PATH)
54 if e.errno != errno.ENOENT:
58 os.remove(BINARY_PATH)
61 if e.errno != errno.ENOENT:
64 for integration_test_file_name in integration_test_file_names:
65 test = generate_test(integration_test_file_name)
66 test_name = 'test_{}'.format(integration_test_file_name[:-4])
67 setattr(IntegrationTests, test_name, test)