|
46 | 46 | import easybuild.tools.utilities |
47 | 47 | from easybuild.tools.build_log import EasyBuildError, init_logging, stop_logging |
48 | 48 | from easybuild.tools.filetools import adjust_permissions, read_file, write_file |
49 | | -from easybuild.tools.run import get_output_from_process, run_cmd, run_cmd_qa, parse_log_for_error |
| 49 | +from easybuild.tools.run import get_output_from_process, run_cmd, run_cmd_qa, parse_log_for_error, check_log_for_errors |
| 50 | +from easybuild.tools.config import ERROR, IGNORE, WARN |
50 | 51 |
|
51 | 52 |
|
52 | 53 | class RunTest(EnhancedTestCase): |
@@ -508,6 +509,59 @@ def test_run_cmd_stream(self): |
508 | 509 | ]) |
509 | 510 | self.assertEqual(stdout, expected) |
510 | 511 |
|
| 512 | + def test_check_log_for_errors(self): |
| 513 | + fd, logfile = tempfile.mkstemp(suffix='.log', prefix='eb-test-') |
| 514 | + os.close(fd) |
| 515 | + |
| 516 | + self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [42]) |
| 517 | + self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [(42, IGNORE)]) |
| 518 | + self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [("42", "invalid-mode")]) |
| 519 | + self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [("42", IGNORE, "")]) |
| 520 | + |
| 521 | + input_text = "\n".join([ |
| 522 | + "OK", |
| 523 | + "error found", |
| 524 | + "test failed", |
| 525 | + "msg: allowed-test failed", |
| 526 | + "enabling -Werror", |
| 527 | + "the process crashed with 0" |
| 528 | + ]) |
| 529 | + expected_error_msg = r"Found 2 errors in command output \(output: error found, the process crashed with 0\)" |
| 530 | + |
| 531 | + self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text, |
| 532 | + [r"\b(error|crashed)\b"]) |
| 533 | + self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text, |
| 534 | + [re.compile(r"\b(error|crashed)\b")]) |
| 535 | + self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text, |
| 536 | + [(r"\b(error|crashed)\b", ERROR)]) |
| 537 | + self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text, |
| 538 | + [(re.compile(r"\b(error|crashed)\b"), ERROR)]) |
| 539 | + |
| 540 | + expected_error_msg = "Found 2 potential errors in command output " \ |
| 541 | + "(output: error found, the process crashed with 0)" |
| 542 | + init_logging(logfile, silent=True) |
| 543 | + check_log_for_errors(input_text, [(r"\b(error|crashed)\b", WARN)]) |
| 544 | + stop_logging(logfile) |
| 545 | + self.assertTrue(expected_error_msg in read_file(logfile)) |
| 546 | + write_file(logfile, '') |
| 547 | + init_logging(logfile, silent=True) |
| 548 | + check_log_for_errors(input_text, [(re.compile(r"\b(error|crashed)\b"), WARN)]) |
| 549 | + stop_logging(logfile) |
| 550 | + self.assertTrue(expected_error_msg in read_file(logfile)) |
| 551 | + |
| 552 | + expected_error_msg = r"Found 2 errors in command output \(output: error found, test failed\)" |
| 553 | + write_file(logfile, '') |
| 554 | + init_logging(logfile, silent=True) |
| 555 | + self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text, [ |
| 556 | + r"\berror\b", |
| 557 | + (r"\ballowed-test failed\b", IGNORE), |
| 558 | + (re.compile(r"\bCRASHED\b", re.I), WARN), |
| 559 | + "fail" |
| 560 | + ]) |
| 561 | + stop_logging(logfile) |
| 562 | + expected_error_msg = "Found 1 potential errors in command output (output: the process crashed with 0)" |
| 563 | + self.assertTrue(expected_error_msg in read_file(logfile)) |
| 564 | + |
511 | 565 |
|
512 | 566 | def suite(): |
513 | 567 | """ returns all the testcases in this module """ |
|
0 commit comments