From e59c991ecee7e3bbbc2dc538eb5031b01220f78b Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 11 May 2023 22:26:13 +0200 Subject: [PATCH] Add first version of JuliaAdapter The adapter was tested with a first demo exercise, but further adjustments might be necessary to cover all edge cases. --- lib/julia_adapter.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lib/julia_adapter.rb diff --git a/lib/julia_adapter.rb b/lib/julia_adapter.rb new file mode 100644 index 00000000..16dfcd3e --- /dev/null +++ b/lib/julia_adapter.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class JuliaAdapter < TestingFrameworkAdapter + COUNT_REGEXP = /(?[^|\s]*)\s+\|\s+(?\d+)\s+(?>(?\d+)\s+)?(?\d+)\s+(?\d+\.\d+)s/ + ASSERTION_ERROR_REGEXP = /(?[^:]*): (?.*?) at (?[^:]*):(?\d+)\s*(?.*?)\s*Stacktrace:/m + LOAD_ERROR_REGEXP = /ERROR: LoadError: (?.*?)\s*Stacktrace:/m + def self.framework_name + 'Julia Unit Testing' + end + + def parse_output(output) + if output[:stdout].present? + parse_test_results(output[:stdout]) + else + parse_error(output[:stderr]) + end + end + + def parse_test_results(output) + test_lines = output.to_enum(:scan, COUNT_REGEXP).map { Regexp.last_match } || [{}] + test_result = test_lines.last + + passed = test_result[:pass].try(:to_i) || 0 + count = test_result[:total].try(:to_i) || 0 + failed = test_result[:fail].try(:to_i) || (count - passed) || 0 + if failed.zero? + {count:, passed: count} + else + error_matches = output.to_enum(:scan, ASSERTION_ERROR_REGEXP).map { Regexp.last_match } || [] + messages = error_matches.pluck(:message) + {count:, failed:, error_messages: messages.flatten.compact_blank} + end + end + + def parse_error(output) + error_matches = output.to_enum(:scan, LOAD_ERROR_REGEXP).map { Regexp.last_match } || [] + messages = error_matches.pluck(:message) + {count: 1, failed: 1, error_messages: messages.flatten.compact_blank} + end +end