def test_parse_real_crash(self): import libscanbuild.analyze as sut2 with libear.temporary_directory() as tmp_dir: filename = os.path.join(tmp_dir, 'test.c') with open(filename, 'w') as handle: handle.write('int main() { return 0') # produce failure report opts = { 'clang': 'clang', 'directory': os.getcwd(), 'flags': [], 'source': filename, 'output_dir': tmp_dir, 'language': 'c', 'error_output': 'some output', 'exit_code': 13 } sut2.report_failure(opts) # find the info file pp_files = glob.glob(os.path.join(tmp_dir, 'failures', '*.i')) self.assertIsNot(pp_files, []) pp_file = pp_files[0] # read the failure report back result = sut.parse_crash(pp_file + '.info.txt') self.assertEqual(result['source'], filename) self.assertEqual(result['problem'], 'Other Error') self.assertEqual(result['file'], pp_file) self.assertEqual(result['info'], pp_file + '.info.txt') self.assertEqual(result['stderr'], pp_file + '.stderr.txt')
def test_parse_real_crash(self): import libscanbuild.analyze as sut2 with libear.temporary_directory() as tmp_dir: filename = os.path.join(tmp_dir, 'test.c') with open(filename, 'w') as handle: handle.write('int main() { return 0') # produce failure report opts = { 'clang': 'clang', 'directory': os.getcwd(), 'flags': [], 'source': filename, 'output_dir': tmp_dir, 'language': 'c', 'error_output': 'some output', 'exit_code': 13 } sut2.report_failure(opts) # verify crashes = list(sut.Crash.read(tmp_dir)) self.assertEqual(1, len(crashes)) crash = crashes[0] self.assertEqual(filename, crash.source) self.assertEqual('Other Error', crash.problem) self.assertEqual(crash.file + '.info.txt', crash.info) self.assertEqual(crash.file + '.stderr.txt', crash.stderr)
def test_parse_real_crash(self): import libscanbuild.analyze as sut2 import re with libear.TemporaryDirectory() as tmpdir: filename = os.path.join(tmpdir, 'test.c') with open(filename, 'w') as handle: handle.write('int main() { return 0') # produce failure report opts = { 'clang': 'clang', 'directory': os.getcwd(), 'flags': [], 'file': filename, 'output_dir': tmpdir, 'language': 'c', 'error_type': 'other_error', 'error_output': 'some output', 'exit_code': 13 } sut2.report_failure(opts) # find the info file pp_file = None for root, _, files in os.walk(tmpdir): keys = [os.path.join(root, name) for name in files] for key in keys: if re.match(r'^(.*/)+clang(.*)\.i$', key): pp_file = key self.assertIsNot(pp_file, None) # read the failure report back result = sut.parse_crash(pp_file + '.info.txt') self.assertEqual(result['source'], filename) self.assertEqual(result['problem'], 'Other Error') self.assertEqual(result['file'], pp_file) self.assertEqual(result['info'], pp_file + '.info.txt') self.assertEqual(result['stderr'], pp_file + '.stderr.txt')
def test_report_failure_create_files(self): with libear.TemporaryDirectory() as tmpdir: # create input file filename = os.path.join(tmpdir, 'test.c') with open(filename, 'w') as handle: handle.write('int main() { return 0') uname_msg = ' '.join(os.uname()) + os.linesep error_msg = 'this is my error output' # execute test opts = { 'clang': 'clang', 'directory': os.getcwd(), 'flags': [], 'file': filename, 'output_dir': tmpdir, 'language': 'c', 'error_type': 'other_error', 'error_output': error_msg, 'exit_code': 13 } sut.report_failure(opts) # verify the result result = dict() pp_file = None for root, _, files in os.walk(tmpdir): keys = [os.path.join(root, name) for name in files] for key in keys: with open(key, 'r') as handle: result[key] = handle.readlines() if re.match(r'^(.*/)+clang(.*)\.i$', key): pp_file = key # prepocessor file generated self.assertUnderFailures(pp_file) # info file generated and content dumped info_file = pp_file + '.info.txt' self.assertTrue(info_file in result) self.assertEqual('Other Error\n', result[info_file][1]) self.assertEqual(uname_msg, result[info_file][3]) # error file generated and content dumped error_file = pp_file + '.stderr.txt' self.assertTrue(error_file in result) self.assertEqual([error_msg], result[error_file])
def test_report_failure_create_files(self): with libear.temporary_directory() as tmp_dir: # create input file filename = os.path.join(tmp_dir, 'test.c') with open(filename, 'w') as handle: handle.write('int main() { return 0') uname_msg = ' '.join(platform.uname()).strip() error_msg = 'this is my error output' # execute test opts = { 'clang': 'clang', 'directory': os.getcwd(), 'flags': [], 'source': filename, 'output_dir': tmp_dir, 'language': 'c', 'error_output': [error_msg], 'exit_code': 13 } sut.report_failure(opts) # find the info file pp_files = glob.glob(os.path.join(tmp_dir, 'failures', '*.i')) self.assertIsNot(pp_files, []) pp_file = pp_files[0] # info file generated and content dumped info_file = pp_file + '.info.txt' self.assertTrue(os.path.exists(info_file)) with open(info_file) as info_handler: lines = [ line.strip() for line in info_handler.readlines() if line.strip() ] self.assertEqual('Other Error', lines[1]) self.assertEqual(uname_msg, lines[3]) # error file generated and content dumped error_file = pp_file + '.stderr.txt' self.assertTrue(os.path.exists(error_file)) with open(error_file) as error_handle: self.assertEqual([error_msg], error_handle.readlines())
def test_report_failure_create_files(self): with libear.temporary_directory() as tmp_dir: # create input file filename = os.path.join(tmp_dir, 'test.c') with open(filename, 'w') as handle: handle.write('int main() { return 0') uname_msg = ' '.join(platform.uname()).strip() error_msg = 'this is my error output' # execute test opts = { 'clang': 'clang', 'directory': os.getcwd(), 'flags': [], 'source': filename, 'output_dir': tmp_dir, 'language': 'c', 'error_output': [error_msg], 'exit_code': 13 } sut.report_failure(opts) # find the info file pp_files = glob.glob(os.path.join(tmp_dir, 'failures', '*.i')) self.assertIsNot(pp_files, []) pp_file = pp_files[0] # info file generated and content dumped info_file = pp_file + '.info.txt' self.assertTrue(os.path.exists(info_file)) with open(info_file) as info_handler: lines = [line.strip() for line in info_handler.readlines() if line.strip()] self.assertEqual('Other Error', lines[1]) self.assertEqual(uname_msg, lines[3]) # error file generated and content dumped error_file = pp_file + '.stderr.txt' self.assertTrue(os.path.exists(error_file)) with open(error_file) as error_handle: self.assertEqual([error_msg], error_handle.readlines())