class TapReportParser::Report
Attributes
passing[R]
test_count[R]
tests[R]
Public Class Methods
from_file(file)
click to toggle source
# File lib/tap_report_parser.rb, line 15 def self.from_file(file) parser = Report.new(File.read(file)) parser.parse_report parser end
from_text(text)
click to toggle source
# File lib/tap_report_parser.rb, line 22 def self.from_text(text) parser = Report.new(text) parser.parse_report parser end
new(report)
click to toggle source
# File lib/tap_report_parser.rb, line 9 def initialize(report) @report = report @test_count = 0 @tests = [] end
Public Instance Methods
parse_line(line, test_number)
click to toggle source
# File lib/tap_report_parser.rb, line 48 def parse_line(line, test_number) test_count = /1\.\.(\d+)(\s*#\s*.*)?/.match(line)&.captures&.first.to_i if test_count != 0 @test_count = test_count return test_number end matches = /^(ok|not ok)\s*(\d*)\s*-?\s*([^#]*)\s*(#\s*(.*))?/.match(line)&.captures&.map(&:to_s) if matches.present? matches = matches.map(&:strip) matches[0] = matches[0] == "ok" ? "success" : "failure" matches[1] = matches[1].present? ? matches[1].to_i : test_number @tests << Test.new(matches[0], matches[1], matches[2], matches[4]) return matches[1] + 1 end diagnostic = /^(#\s*)?(.*)$/.match(line)&.captures&.last&.rstrip @tests.last.add_diagnostic(diagnostic) if @tests.present? test_number end
parse_report()
click to toggle source
# File lib/tap_report_parser.rb, line 29 def parse_report test_number = 1 @report.strip.split("\n").each do |line| test_number = parse_line(line, test_number) end if @test_count != 0 ((1..@test_count).to_a - @tests.map(&:number)).each do |num| @tests << Test.new("failure", num, "", "") end else @test_count = @tests.count end @passing = @test_count != 0 && @tests.map(&:passing).count(true) == @test_count @tests.each { |test| test.convert_diagnostic_yaml_to_hash } end