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

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