Files
codeocean/lib/cabal_adapter.rb
2024-09-20 04:25:57 -04:00

32 lines
948 B
Ruby

# frozen_string_literal: true
class CabalAdapter < TestingFrameworkAdapter
# Regular expressions to extract the number of test suites, test cases, and their status
COUNT_REGEXP = /(\d+) of \d+ test suites \((\d+) of \d+ test cases\)/
PASS_REGEXP = /passed/
FAIL_REGEXP = /failed/
def self.framework_name
'Haskell Cabal'
end
# Parse the output from Cabal test suite
def parse_output(output)
# Extract the total count of test suites and test cases
count_match = output[:stdout].scan(COUNT_REGEXP).last
test_cases_count = count_match&.last&.to_i || 0
# Check if the test suite passed or failed
passed = output[:stdout] =~ PASS_REGEXP
failed = output[:stdout] =~ FAIL_REGEXP
if passed
{count: test_cases_count, passed: test_cases_count}
elsif failed
{count: test_cases_count, failed: test_cases_count}
else
{count: test_cases_count, passed: 0, failed: 0}
end
end
end