diff --git a/lib/cpp_catch2_adapter.rb b/lib/cpp_catch2_adapter.rb index ea0c21b0..02dc9ea0 100644 --- a/lib/cpp_catch2_adapter.rb +++ b/lib/cpp_catch2_adapter.rb @@ -14,10 +14,10 @@ class CppCatch2Adapter < TestingFrameworkAdapter if ALL_PASSED_REGEXP.match(output[:stdout]) {count: Regexp.last_match(1).to_i, passed: Regexp.last_match(1).to_i} else - count = COUNT_REGEXP.match(output[:stdout]).try(:captures).try(:first).try(:to_i) || 0 - failed = FAILURES_REGEXP.match(output[:stdout]).try(:captures).try(:first).try(:to_i) || 0 - error_matches = ASSERTION_ERROR_REGEXP.match(output[:stdout]).try(:captures) || [] - {count: count, failed: failed, error_messages: error_matches} + count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0 + failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0 + error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || [] + {count: count, failed: failed, error_messages: error_matches.flatten.reject(&:blank?)} end end end diff --git a/lib/junit5_adapter.rb b/lib/junit5_adapter.rb index d442fdfc..e253293b 100644 --- a/lib/junit5_adapter.rb +++ b/lib/junit5_adapter.rb @@ -10,13 +10,13 @@ class Junit5Adapter < TestingFrameworkAdapter end def parse_output(output) - count = COUNT_REGEXP.match(output[:stdout]).try(:captures).try(:first).try(:to_i) || 0 - failed = FAILURES_REGEXP.match(output[:stdout]).try(:captures).try(:first).try(:to_i) || 0 + count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0 + failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0 if failed.zero? {count: count, passed: count} else - error_matches = ASSERTION_ERROR_REGEXP.match(output[:stdout]).try(:captures) || [] - {count: count, failed: failed, error_messages: error_matches} + error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || [] + {count: count, failed: failed, error_messages: error_matches.flatten.reject(&:blank?)} end end end diff --git a/lib/junit_adapter.rb b/lib/junit_adapter.rb index 9a56fe7e..b920a56a 100644 --- a/lib/junit_adapter.rb +++ b/lib/junit_adapter.rb @@ -3,7 +3,7 @@ class JunitAdapter < TestingFrameworkAdapter COUNT_REGEXP = /Tests run: (\d+)/.freeze FAILURES_REGEXP = /Failures: (\d+)/.freeze - SUCCESS_REGEXP = /OK \((\d+) tests?\)/.freeze + SUCCESS_REGEXP = /OK \((\d+) tests?\)\s*(?:\x1B\]0;)?\z/.freeze ASSERTION_ERROR_REGEXP = /java\.lang\.AssertionError:?\s(.*?)\tat org.junit|org\.junit\.ComparisonFailure:\s(.*?)\tat org.junit/m.freeze def self.framework_name @@ -14,10 +14,10 @@ class JunitAdapter < TestingFrameworkAdapter if SUCCESS_REGEXP.match(output[:stdout]) {count: Regexp.last_match(1).to_i, passed: Regexp.last_match(1).to_i} else - count = COUNT_REGEXP.match(output[:stdout]).try(:captures).try(:first).try(:to_i) || 0 - failed = FAILURES_REGEXP.match(output[:stdout]).try(:captures).try(:first).try(:to_i) || 0 - error_matches = ASSERTION_ERROR_REGEXP.match(output[:stdout]).try(:captures) || [] - {count: count, failed: failed, error_messages: error_matches} + count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0 + failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0 + error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || [] + {count: count, failed: failed, error_messages: error_matches.flatten.reject(&:blank?)} end end end diff --git a/lib/mocha_adapter.rb b/lib/mocha_adapter.rb index 7d5bb7b3..016bcb63 100644 --- a/lib/mocha_adapter.rb +++ b/lib/mocha_adapter.rb @@ -9,10 +9,8 @@ class MochaAdapter < TestingFrameworkAdapter end def parse_output(output) - matches_success = SUCCESS_REGEXP.match(output[:stdout]) - matches_failed = FAILURES_REGEXP.match(output[:stdout]) - failed = matches_failed ? matches_failed.captures.first.to_i : 0 - success = matches_success ? matches_success.captures.first.to_i : 0 + success = output[:stdout].scan(SUCCESS_REGEXP).try(:last).try(:first).try(:to_i) || 0 + failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0 {count: success + failed, failed: failed} end end diff --git a/lib/py_lint_adapter.rb b/lib/py_lint_adapter.rb index d132b7f7..0bc6f5aa 100644 --- a/lib/py_lint_adapter.rb +++ b/lib/py_lint_adapter.rb @@ -9,12 +9,12 @@ class PyLintAdapter < TestingFrameworkAdapter end def parse_output(output) - regex_match = REGEXP.match(output[:stdout]) + regex_match = output[:stdout].scan(REGEXP).try(:last) if regex_match.blank? count = 0 failed = 0 else - captures = regex_match.captures.map(&:to_f) + captures = regex_match.map(&:to_f) count = captures.second passed = captures.first >= 0 ? captures.first : 0 failed = count - passed @@ -39,9 +39,13 @@ class PyLintAdapter < TestingFrameworkAdapter Sentry.capture_message({stdout: output[:stdout], regex: ASSERTION_ERROR_REGEXP}.to_json) assertion_error_matches = [] end - concatenated_errors = assertion_error_matches.map {|result| "#{result[:name]}: #{result[:result]}" }.flatten - {count: count, failed: failed, error_messages: concatenated_errors, -detailed_linter_results: assertion_error_matches} + concatenated_errors = assertion_error_matches.map {|result| "#{result[:name]}: #{result[:result]}" } + { + count: count, + failed: failed, + error_messages: concatenated_errors.flatten.reject(&:blank?), + detailed_linter_results: assertion_error_matches.flatten.reject(&:blank?) + } end def self.translate_linter(assessment, locale) diff --git a/lib/py_unit_adapter.rb b/lib/py_unit_adapter.rb index 8b3b2093..9d52dad4 100644 --- a/lib/py_unit_adapter.rb +++ b/lib/py_unit_adapter.rb @@ -12,11 +12,9 @@ class PyUnitAdapter < TestingFrameworkAdapter def parse_output(output) # PyUnit is expected to print test results on Stderr! - count = COUNT_REGEXP.match(output[:stderr]).captures.first.to_i - failures_matches = FAILURES_REGEXP.match(output[:stderr]) - failed = failures_matches ? failures_matches.captures.try(:first).to_i : 0 - error_matches = ERRORS_REGEXP.match(output[:stderr]) - errors = error_matches ? error_matches.captures.try(:first).to_i : 0 + count = output[:stderr].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0 + failed = output[:stderr].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0 + errors = output[:stderr].scan(ERRORS_REGEXP).try(:last).try(:first).try(:to_i) || 0 begin assertion_error_matches = Timeout.timeout(2.seconds) do output[:stderr].scan(ASSERTION_ERROR_REGEXP).map do |match| @@ -28,12 +26,12 @@ class PyUnitAdapter < TestingFrameworkAdapter else "#{testname}: #{error}" end - end.flatten || [] + end || [] end rescue Timeout::Error Sentry.capture_message({stderr: output[:stderr], regex: ASSERTION_ERROR_REGEXP}.to_json) assertion_error_matches = [] end - {count: count, failed: failed + errors, error_messages: assertion_error_matches} + {count: count, failed: failed + errors, error_messages: assertion_error_matches.flatten.reject(&:blank?)} end end diff --git a/lib/r_script_adapter.rb b/lib/r_script_adapter.rb index bd65af51..6fdb04c6 100644 --- a/lib/r_script_adapter.rb +++ b/lib/r_script_adapter.rb @@ -9,11 +9,11 @@ class RScriptAdapter < TestingFrameworkAdapter end def parse_output(output) - captures = REGEXP.match(output[:stdout]).captures.map(&:to_i) + captures = output[:stdout].scan(REGEXP).try(:last).map(&:to_i) count = captures.first passed = captures.second failed = count - passed - assertion_error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP).flatten || [] - {count: count, failed: failed, error_messages: assertion_error_matches} + assertion_error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || [] + {count: count, failed: failed, error_messages: assertion_error_matches.flatten.reject(&:blank?)} end end diff --git a/lib/rspec_adapter.rb b/lib/rspec_adapter.rb index 80d8a4d6..52a39b6a 100644 --- a/lib/rspec_adapter.rb +++ b/lib/rspec_adapter.rb @@ -8,7 +8,7 @@ class RspecAdapter < TestingFrameworkAdapter end def parse_output(output) - captures = REGEXP.match(output[:stdout]).captures.map(&:to_i) + captures = output[:stdout].scan(REGEXP).try(:last).map(&:to_i) count = captures.first failed = captures.second {count: count, failed: failed}