def check_log_for_fails( path_to_log, testname, exe ): # Normal logs are expected to have in last line: # "All tests passed (11 assertions in 1 test case)" # Tests that have failures, however, will show: # "test cases: 1 | 1 failed # assertions: 9 | 6 passed | 3 failed" if path_to_log is None: return False for ctx in grep( r'^test cases:\s*(\d+) \|\s*(\d+) (passed|failed)', path_to_log ): m = ctx['match'] total = int(m.group(1)) passed = int(m.group(2)) if m.group(3) == 'failed': # "test cases: 1 | 1 failed" passed = total - passed if passed < total: if total == 1 or passed == 0: desc = 'failed' else: desc = str(total - passed) + ' of ' + str(total) + ' failed' if log.is_verbose_on(): log.e( log.red + testname + log.reset + ': ' + desc ) log.i( 'Executable:', exe ) log.i( 'Log: >>>' ) log.out() cat( path_to_log ) log.out( '<<<' ) else: log.e( log.red + testname + log.reset + ': ' + desc + '; see ' + path_to_log ) return True return False
def check_log_for_fails(path_to_log, testname, configuration=None, repetition=1): # Normal logs are expected to have in last line: # "All tests passed (11 assertions in 1 test case)" # Tests that have failures, however, will show: # "test cases: 1 | 1 failed # assertions: 9 | 6 passed | 3 failed" # We make sure we look at the log written by the last run of the test by ignoring anything before the last # line with "----...---" that separate between 2 separate runs of he test if path_to_log is None: return False results = None for ctx in file.grep( r'^test cases:\s*(\d+) \|\s*(\d+) (passed|failed)|^----------TEST-SEPARATOR----------$', path_to_log): m = ctx['match'] if m.string == "----------TEST-SEPARATOR----------": results = None else: results = m if not results: return False total = int(results.group(1)) passed = int(results.group(2)) if results.group(3) == 'failed': # "test cases: 1 | 1 failed" passed = total - passed if passed < total: if total == 1 or passed == 0: desc = 'failed' else: desc = str(total - passed) + ' of ' + str(total) + ' failed' if log.is_verbose_on(): log.e(log.red + testname + log.reset + ': ' + configuration_str(configuration, repetition, suffix=' ') + desc) log.i('Log: >>>') log.out() file.cat(path_to_log) log.out('<<<') else: log.e(log.red + testname + log.reset + ': ' + configuration_str(configuration, repetition, suffix=' ') + desc + '; see ' + path_to_log) return True return False