Class: Teresa::Parser::TAP
Overview
Implements Test Anything Protocol and Knock test output format.
Instance Method Summary collapse
-
#initialize(string) ⇒ TAP
constructor
A new instance of TAP.
- #parse ⇒ Object
Methods inherited from Generic
Constructor Details
#initialize(string) ⇒ TAP
Returns a new instance of TAP.
10 11 12 |
# File 'lib/teresa/parser/tap.rb', line 10 def initialize(string) @string = string end |
Instance Method Details
#parse ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/teresa/parser/tap.rb', line 14 def parse scanner = StringScanner.new(@string) version = scanner.scan(/TAP version (\d+)\n/) ? scanner[1].to_i : 12 maximum = scanner.scan(/1\.\.(\d+)\n/) && scanner[1] expected = 0 raise "TAP #{version} is not supported" unless version.between? 12, 13 while scanner.scan_until(/^(not )?ok\b/) expected += 1 test = Test.new test.state = :failed if scanner[1] test.id = scanner.scan(/ +(\d+)/) ? scanner[1].to_i : expected test. = scanner.scan(/ +.+/).to_s.gsub(/^\s*-|-\s*$/, '').strip test.name = test..gsub(/(\: FAILED)?(#.*)?$/, '') test.state = :skipped if test. =~ /# *(SKIP|TODO)/i expected = test.id test.name = "Test ##{test.id}" if test.name.empty? test. = nil if test..empty? if version >= 13 and scanner.scan(/^([ \t]+)---\n$/) test.output = "meta data:\n\n\t---\n" prefix = scanner[1] while scanner.scan(/^#{prefix}(.*)\n/) test.output << scanner[1] test. = scanner[1][/message: *"?(.*)"?/, 1] if scanner[1].start_with? "message:" end test.output << "\n" end while scanner.scan(/^# ?(.*\n)/) test.output ||= "" test.output << scanner[1] end yield test end unless scanner.scan_until(/^Bail out!\b/) maximum ||= scanner.scan_until(/1\.\.(\d+)\n/) && scanner[1] expected.upto(maximum.to_i) { |i| yield Test.new(state: :failed, id: i, name: "Test ##{i}") } end end |