Test Adapters: Always use the last output for score runs

* This prevents learners from cheating by printing the required status line themselves
This commit is contained in:
Sebastian Serth
2021-11-02 15:52:49 +01:00
parent d7e515f1c6
commit 3d3478d859
8 changed files with 33 additions and 33 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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}