tapout 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ require 'tapout/reporters/abstract'
3
3
  module TapOut::Reporters
4
4
 
5
5
  # Tap Reporter
6
- class Tap < Abstract
6
+ class TapReporter < Abstract
7
7
 
8
8
  #
9
9
  def start_suite(entry)
@@ -54,7 +54,7 @@ module TapOut::Reporters
54
54
  end
55
55
 
56
56
  #
57
- def err(entry)
57
+ def error(entry)
58
58
  super(entry)
59
59
 
60
60
  @i += 1
@@ -0,0 +1,178 @@
1
+ require 'tapout/reporters/abstract'
2
+ require 'stringio'
3
+
4
+ module TapOut
5
+
6
+ module Reporters
7
+
8
+ # The test report format made famous by Tim Piece and his Turn project.
9
+ #
10
+ #--
11
+ # TODO: Should we fit reporter output to width of console?
12
+ # TODO: Running percentages?
13
+ #++
14
+ class TurnReporter < Abstract #Reporter
15
+
16
+ PASS = "PASS".ansi(:green)
17
+ FAIL = "FAIL".ansi(:red)
18
+ ERROR = "ERROR".ansi(:yellow)
19
+
20
+ #
21
+ def start_suite(suite)
22
+ @io = $stdout
23
+ @suite = suite
24
+ @time = Time.now
25
+ @stdout = StringIO.new
26
+ @stderr = StringIO.new
27
+ #files = suite.collect{ |s| s.file }.join(' ')
28
+ puts "LOADED SUITE" # #{suite.name}"
29
+ #puts "Started"
30
+ end
31
+
32
+ #
33
+ def start_case(kase)
34
+ puts("#{kase['label']}".ansi(:bold))
35
+ end
36
+
37
+ #
38
+ def start_test(test)
39
+ #if @file != test.file
40
+ # @file = test.file
41
+ # puts(test.file)
42
+ #end
43
+
44
+ name = if @natural
45
+ " #{test['label'].gsub("test_", "").gsub(/_/, " ")}"
46
+ else
47
+ " #{test['label']}"
48
+ end
49
+
50
+ print " %-69s" % name
51
+
52
+ @stdout.rewind
53
+ @stderr.rewind
54
+
55
+ $stdout = @stdout
56
+ $stderr = @stderr unless $DEBUG
57
+ end
58
+
59
+ #
60
+ def pass(doc)
61
+ puts " #{PASS}"
62
+ #if message
63
+ # message = Colorize.magenta(message)
64
+ # message = message.to_s.tabto(8)
65
+ # puts(message)
66
+ #end
67
+ end
68
+
69
+ #
70
+ def fail(doc)
71
+ message = doc['exception']['message'].to_s
72
+ backtrace = clean_backtrace(doc['exception']['backtrace'] || [])
73
+
74
+ puts(" #{FAIL}")
75
+ puts message.ansi(:bold).tabto(8)
76
+
77
+ unless backtrace.empty?
78
+ label = "Assertion at "
79
+ tabsize = 8
80
+ backtrace1 = label + backtrace.shift
81
+ puts(backtrace1.tabto(tabsize))
82
+ if trace = TapOut.trace
83
+ puts backtrace[0,depth].map{|l| l.tabto(label.length + tabsize) }.join("\n")
84
+ end
85
+ end
86
+ show_captured_output
87
+ end
88
+
89
+ # TODO: TAP-Y/J needs a field for the error class
90
+ def error(doc)
91
+ message = doc['exception']['message'].to_s
92
+ #backtrace = "Exception `#{exception.class}' at " + clean_backtrace(exception.backtrace).join("\n")
93
+ backtrace = "Exception at " + clean_backtrace(doc['exception']['backtrace'] || []).join("\n")
94
+ message = message.ansi(:bold)
95
+ puts("#{ERROR}")
96
+ puts(message.tabto(8))
97
+ puts "STDERR:".tabto(8)
98
+ puts(backtrace.tabto(8))
99
+ show_captured_output
100
+ end
101
+
102
+ #
103
+ def finish_test(test)
104
+ $stdout = STDOUT
105
+ $stderr = STDERR
106
+ end
107
+
108
+ #
109
+ def show_captured_output
110
+ show_captured_stdout
111
+ #show_captured_stderr
112
+ end
113
+
114
+ #
115
+ def show_captured_stdout
116
+ @stdout.rewind
117
+ return if @stdout.eof?
118
+ STDOUT.puts(<<-output.tabto(8))
119
+ \nSTDOUT:
120
+ #{@stdout.read}
121
+ output
122
+ end
123
+
124
+ # No longer used b/c of error messages are fairly extraneous.
125
+ =begin
126
+ def show_captured_stderr
127
+ @stderr.rewind
128
+ return if @stderr.eof?
129
+ STDOUT.puts(<<-output.tabto(8))
130
+ \nSTDERR:
131
+ #{@stderr.read}
132
+ output
133
+ end
134
+ =end
135
+
136
+ #
137
+ #def finish_case(kase)
138
+ #end
139
+
140
+ #
141
+ def finish_suite(suite)
142
+ total = suite['counts']['total']
143
+ pass = suite['counts']['pass']
144
+ failure = suite['counts']['fail']
145
+ error = suite['counts']['error']
146
+ #pass = total - failure - error
147
+
148
+ bar = '=' * 78
149
+ if $ansi
150
+ bar = if pass == total then bar.ansi(:green)
151
+ else bar.ansi(:red) end
152
+ end
153
+
154
+ #tally = [total, suite.count_assertions]
155
+ tally = [total]
156
+
157
+ puts bar
158
+ puts " pass: %d, fail: %d, error: %d" % [pass, failure, error]
159
+ #puts " total: %d tests with %d assertions in #{Time.new - @time} seconds" % tally
160
+ puts " total: %d tests in #{Time.new - @time} seconds" % tally
161
+ puts bar
162
+ end
163
+
164
+ #
165
+ def puts(str)
166
+ @io.puts(str)
167
+ end
168
+
169
+ #
170
+ def print(str)
171
+ @io.print(str)
172
+ end
173
+
174
+ end
175
+
176
+ end
177
+
178
+ end
@@ -1,7 +1,20 @@
1
1
  module TapOut
2
- # Current version of TAPOUT project.
3
- VERSION = "0.2.3"
4
-
5
2
  # The current revision of the TAP-Y/J format.
6
- REVISION = "2"
3
+ REVISION = "3"
4
+
5
+ # Project metadata.
6
+ #
7
+ # @return [Hash] metadata from .ruby file
8
+ def self.metadata
9
+ @metadata ||= (
10
+ require 'yaml'
11
+ YAML.load_file(File.join(File.dirname(__FILE__), 'tapout.yml'))
12
+ )
13
+ end
14
+
15
+ # Any missing constant will be looked for in
16
+ # project metadata.
17
+ def self.const_missing(name)
18
+ metadata[name.to_s.downcase] || super(name)
19
+ end
7
20
  end
@@ -0,0 +1,5 @@
1
+ require 'stringio'
2
+
3
+ When 'Given a legacy TAP stream' do |text|
4
+ @tap = text
5
+ end
@@ -0,0 +1,68 @@
1
+ = TAP Parser
2
+
3
+ require 'tapout'
4
+
5
+ Given a legacy TAP stream:
6
+
7
+ 1..3
8
+ ok 1 - Example A
9
+ not ok 2 - Example B
10
+ ---
11
+ file: foo.rb
12
+ line: 45
13
+ description: this is that
14
+ found: this
15
+ wanted: that
16
+ raw_test: assert_equal('that', 'this')
17
+ extensions:
18
+ THAC0: 16
19
+ ...
20
+ ok 3
21
+
22
+ The PerlAdapter can convert the stream into TAP-Y.
23
+
24
+ stream = StringIO.new(@tap)
25
+
26
+ adapter = TapOut::PerlAdapter.new(stream)
27
+
28
+ entries = adapter.to_a
29
+
30
+ Once converted, there should five entries --a header and footer, two
31
+ passing tests and one failing test.
32
+
33
+ entries.size.assert == 5
34
+
35
+ Or pipe the converted stream directly to another stream.
36
+
37
+ stream = StringIO.new(@tap)
38
+
39
+ adapter = TapOut::PerlAdapter.new(stream)
40
+
41
+ output = ""
42
+
43
+ tapy = adapter | output
44
+
45
+ Given a legacy TAP stream:
46
+
47
+ 1..5
48
+ # test by equality
49
+ ok 1 - pass-thru 1
50
+ ok 2 - pass-thru 2
51
+ ok 3 - pass-thru 3
52
+ ok 4 - pass-thru 4
53
+ ok 5 - pass-thru 5
54
+ 1..5
55
+
56
+ Let's see if this works.
57
+
58
+ stream = StringIO.new(@tap)
59
+
60
+ adapter = TapOut::PerlAdapter.new(stream)
61
+
62
+ entries = adapter.to_a
63
+
64
+ Once converted, there should eight entries --a header and footer, one note
65
+ and five passing tests.
66
+
67
+ entries.size.assert == 8
68
+
@@ -0,0 +1,13 @@
1
+ require 'tapout'
2
+
3
+ When 'Using the following TAP-Y sample' do |text|
4
+ @tapy = text
5
+ end
6
+
7
+ When '(((\w+))) reporter should run without error' do |format|
8
+ $stdin = StringIO.new(@tapy)
9
+ $stdout = StringIO.new(out = '')
10
+
11
+ TapOut.cli(format)
12
+ end
13
+
@@ -0,0 +1,78 @@
1
+ ---
2
+ type: suite
3
+ start: '2011-10-06 18:48:08'
4
+ count: 3
5
+ seed: 36440
6
+ rev: 2
7
+ ---
8
+ type: case
9
+ subtype: ''
10
+ label: ExampleTestCase
11
+ level: 0
12
+ ---
13
+ type: test
14
+ subtype: ''
15
+ status: error
16
+ label: test_error
17
+ exception:
18
+ message: ! 'RuntimeError:'
19
+ file: example.rb
20
+ line: 10
21
+ snippet:
22
+ - 8: ''
23
+ - 9: ! ' def test_error'
24
+ - 10: ! ' raise'
25
+ - 11: ! ' end'
26
+ - 12: ''
27
+ backtrace:
28
+ - example.rb:10
29
+ time: 0.001054606
30
+ ---
31
+ type: test
32
+ subtype: ''
33
+ status: fail
34
+ label: test_failing
35
+ exception:
36
+ message: ! "Expected: \"1\"\n Actual: \"2\""
37
+ file: example.rb
38
+ line: 14
39
+ snippet:
40
+ - 12: ''
41
+ - 13: ! ' def test_failing'
42
+ - 14: ! ' assert_equal(''1'', ''2'')'
43
+ - 15: ! ' end'
44
+ - 16: ''
45
+ backtrace:
46
+ - example.rb:14
47
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:456
48
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:103
49
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:88
50
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:88
51
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:88
52
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:73
53
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:73
54
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:73
55
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:146
56
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:72
57
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:48
58
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:47
59
+ - /home/trans/com/programs/rubyworks/minitap/lib/minitap.rb:47
60
+ time: 0.046170916
61
+ ---
62
+ type: test
63
+ subtype: ''
64
+ status: pass
65
+ label: test_passing
66
+ time: 1.04997403
67
+ ---
68
+ type: tally
69
+ time: 1.000800203
70
+ counts:
71
+ total: 3
72
+ pass: 1
73
+ fail: 1
74
+ error: 1
75
+ omit: 0
76
+ todo: 0
77
+ ...
78
+
@@ -0,0 +1,86 @@
1
+ == Reporters
2
+
3
+ Using the following TAP-Y sample:
4
+
5
+ ---
6
+ type: suite
7
+ start: '2011-10-06 18:48:08'
8
+ count: 3
9
+ seed: 36440
10
+ rev: 2
11
+ ---
12
+ type: case
13
+ subtype: ''
14
+ label: ExampleTestCase
15
+ level: 0
16
+ ---
17
+ type: test
18
+ subtype: ''
19
+ status: error
20
+ label: test_error
21
+ exception:
22
+ message: ! 'RuntimeError:'
23
+ file: example.rb
24
+ line: 10
25
+ snippet:
26
+ - 8: ''
27
+ - 9: ! ' def test_error'
28
+ - 10: ! ' raise'
29
+ - 11: ! ' end'
30
+ - 12: ''
31
+ backtrace:
32
+ - example.rb:10
33
+ time: 0.001054606
34
+ ---
35
+ type: test
36
+ subtype: ''
37
+ status: fail
38
+ label: test_failing
39
+ exception:
40
+ message: ! "Expected: \"1\"\n Actual: \"2\""
41
+ file: example.rb
42
+ line: 14
43
+ snippet:
44
+ - 12: ''
45
+ - 13: ! ' def test_failing'
46
+ - 14: ! ' assert_equal(''1'', ''2'')'
47
+ - 15: ! ' end'
48
+ - 16: ''
49
+ backtrace:
50
+ - example.rb:14
51
+ time: 0.046170916
52
+ ---
53
+ type: test
54
+ subtype: ''
55
+ status: pass
56
+ label: test_passing
57
+ time: 1.04997403
58
+ ---
59
+ type: tally
60
+ time: 1.000800203
61
+ counts:
62
+ total: 3
63
+ pass: 1
64
+ fail: 1
65
+ error: 1
66
+ omit: 0
67
+ todo: 0
68
+ ...
69
+
70
+
71
+ The dot reporter should run without error.
72
+
73
+ The progress reporter should run without error.
74
+
75
+ The html reporter should run without error.
76
+
77
+ The outline reporter should run without error.
78
+
79
+ The breakdown reporter should run without error.
80
+
81
+ The tap reporter should run without error.
82
+
83
+ The turn reporter should run without error.
84
+
85
+ The pretty reporter should run without error.
86
+