grntest 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,208 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "grntest/reporters/base-reporter"
19
+
20
+ module Grntest
21
+ module Reporters
22
+ class InplaceReporter < BaseReporter
23
+ def initialize(tester)
24
+ super
25
+ @last_redraw_time = Time.now
26
+ @minimum_redraw_interval = 0.1
27
+ end
28
+
29
+ def on_start(result)
30
+ @test_suites_result = result
31
+ end
32
+
33
+ def on_worker_start(worker)
34
+ end
35
+
36
+ def on_suite_start(worker)
37
+ redraw
38
+ end
39
+
40
+ def on_test_start(worker)
41
+ redraw
42
+ end
43
+
44
+ def on_test_success(worker, result)
45
+ redraw
46
+ end
47
+
48
+ def on_test_failure(worker, result)
49
+ redraw do
50
+ report_test(worker, result)
51
+ report_failure(result)
52
+ end
53
+ end
54
+
55
+ def on_test_leak(worker, result)
56
+ redraw do
57
+ report_test(worker, result)
58
+ report_marker(result)
59
+ report_actual(result) unless result.checked?
60
+ end
61
+ end
62
+
63
+ def on_test_omission(worker, result)
64
+ redraw do
65
+ report_test(worker, result)
66
+ report_actual(result)
67
+ end
68
+ end
69
+
70
+ def on_test_no_check(worker, result)
71
+ redraw do
72
+ report_test(worker, result)
73
+ report_actual(result)
74
+ end
75
+ end
76
+
77
+ def on_test_finish(worker, result)
78
+ redraw
79
+ end
80
+
81
+ def on_suite_finish(worker)
82
+ redraw
83
+ end
84
+
85
+ def on_worker_finish(worker)
86
+ redraw
87
+ end
88
+
89
+ def on_finish(result)
90
+ draw
91
+ puts
92
+ report_summary(result)
93
+ end
94
+
95
+ private
96
+ def draw
97
+ draw_statistics_header_line
98
+ @test_suites_result.workers.each do |worker|
99
+ draw_status_line(worker)
100
+ draw_test_line(worker)
101
+ end
102
+ draw_progress_line
103
+ end
104
+
105
+ def draw_statistics_header_line
106
+ puts(statistics_header)
107
+ end
108
+
109
+ def draw_status_line(worker)
110
+ clear_line
111
+ left = "[#{colorize(worker.id, worker.result)}] "
112
+ right = " [#{worker.status}]"
113
+ rest_width = @term_width - @current_column
114
+ center_width = rest_width - string_width(left) - string_width(right)
115
+ center = justify(worker.suite_name, center_width)
116
+ puts("#{left}#{center}#{right}")
117
+ end
118
+
119
+ def draw_test_line(worker)
120
+ clear_line
121
+ if worker.test_name
122
+ label = " #{worker.test_name}"
123
+ else
124
+ label = statistics(worker.result)
125
+ end
126
+ puts(justify(label, @term_width))
127
+ end
128
+
129
+ def draw_progress_line
130
+ n_done_tests = @test_suites_result.n_tests
131
+ n_total_tests = @test_suites_result.n_total_tests
132
+ if n_total_tests.zero?
133
+ finished_test_ratio = 0.0
134
+ else
135
+ finished_test_ratio = n_done_tests.to_f / n_total_tests
136
+ end
137
+
138
+ start_mark = "|"
139
+ finish_mark = "|"
140
+ statistics = " [%3d%%]" % (finished_test_ratio * 100)
141
+
142
+ progress_width = @term_width
143
+ progress_width -= start_mark.bytesize
144
+ progress_width -= finish_mark.bytesize
145
+ progress_width -= statistics.bytesize
146
+ finished_mark = "-"
147
+ if n_done_tests == n_total_tests
148
+ progress = colorize(finished_mark * progress_width,
149
+ @test_suites_result)
150
+ else
151
+ current_mark = ">"
152
+ finished_marks_width = (progress_width * finished_test_ratio).ceil
153
+ finished_marks_width -= current_mark.bytesize
154
+ finished_marks_width = [0, finished_marks_width].max
155
+ progress = finished_mark * finished_marks_width + current_mark
156
+ progress = colorize(progress, @test_suites_result)
157
+ progress << " " * (progress_width - string_width(progress))
158
+ end
159
+ puts("#{start_mark}#{progress}#{finish_mark}#{statistics}")
160
+ end
161
+
162
+ def redraw
163
+ synchronize do
164
+ unless block_given?
165
+ return if Time.now - @last_redraw_time < @minimum_redraw_interval
166
+ end
167
+ draw
168
+ if block_given?
169
+ yield
170
+ else
171
+ up_n_lines(n_using_lines)
172
+ end
173
+ @last_redraw_time = Time.now
174
+ end
175
+ end
176
+
177
+ def up_n_lines(n)
178
+ print("\e[1A" * n)
179
+ end
180
+
181
+ def clear_line
182
+ print(" " * @term_width)
183
+ print("\r")
184
+ reset_current_column
185
+ end
186
+
187
+ def n_using_lines
188
+ n_statistics_header_line + n_worker_lines * n_workers + n_progress_lines
189
+ end
190
+
191
+ def n_statistics_header_line
192
+ 1
193
+ end
194
+
195
+ def n_worker_lines
196
+ 2
197
+ end
198
+
199
+ def n_progress_lines
200
+ 1
201
+ end
202
+
203
+ def n_workers
204
+ @tester.n_workers
205
+ end
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,112 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "grntest/reporters/base-reporter"
19
+
20
+ module Grntest
21
+ module Reporters
22
+ class MarkReporter < BaseReporter
23
+ def initialize(tester)
24
+ super
25
+ end
26
+
27
+ def on_start(result)
28
+ end
29
+
30
+ def on_worker_start(worker)
31
+ end
32
+
33
+ def on_suite_start(worker)
34
+ end
35
+
36
+ def on_test_start(worker)
37
+ end
38
+
39
+ def on_test_success(worker, result)
40
+ synchronize do
41
+ report_test_result_mark(".", result)
42
+ end
43
+ end
44
+
45
+ def on_test_failure(worker, result)
46
+ synchronize do
47
+ report_test_result_mark("F", result)
48
+ puts
49
+ report_test(worker, result)
50
+ report_failure(result)
51
+ end
52
+ end
53
+
54
+ def on_test_leak(worker, result)
55
+ synchronize do
56
+ report_test_result_mark("L(#{result.n_leaked_objects})", result)
57
+ unless result.checked?
58
+ puts
59
+ report_test(worker, result)
60
+ report_actual(result)
61
+ end
62
+ end
63
+ end
64
+
65
+ def on_test_omission(worker, result)
66
+ synchronize do
67
+ report_test_result_mark("O", result)
68
+ puts
69
+ report_test(worker, result)
70
+ report_actual(result)
71
+ end
72
+ end
73
+
74
+ def on_test_no_check(worker, result)
75
+ synchronize do
76
+ report_test_result_mark("N", result)
77
+ puts
78
+ report_test(worker, result)
79
+ report_actual(result)
80
+ end
81
+ end
82
+
83
+ def on_test_finish(worker, result)
84
+ end
85
+
86
+ def on_suite_finish(worker)
87
+ end
88
+
89
+ def on_worker_finish(worker_id)
90
+ end
91
+
92
+ def on_finish(result)
93
+ puts
94
+ puts
95
+ report_summary(result)
96
+ end
97
+
98
+ private
99
+ def report_test_result_mark(mark, result)
100
+ if @term_width < @current_column + mark.bytesize
101
+ puts
102
+ end
103
+ print(colorize(mark, result))
104
+ if @term_width <= @current_column
105
+ puts
106
+ else
107
+ @output.flush
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "grntest/reporters/base-reporter"
19
+
20
+ module Grntest
21
+ module Reporters
22
+ class StreamReporter < BaseReporter
23
+ def initialize(tester)
24
+ super
25
+ end
26
+
27
+ def on_start(result)
28
+ end
29
+
30
+ def on_worker_start(worker)
31
+ end
32
+
33
+ def on_suite_start(worker)
34
+ if worker.suite_name.bytesize <= @term_width
35
+ puts(worker.suite_name)
36
+ else
37
+ puts(justify(worker.suite_name, @term_width))
38
+ end
39
+ @output.flush
40
+ end
41
+
42
+ def on_test_start(worker)
43
+ print(" #{worker.test_name}")
44
+ @output.flush
45
+ end
46
+
47
+ def on_test_success(worker, result)
48
+ report_test_result(result, worker.status)
49
+ end
50
+
51
+ def on_test_failure(worker, result)
52
+ report_test_result(result, worker.status)
53
+ report_failure(result)
54
+ end
55
+
56
+ def on_test_leak(worker, result)
57
+ report_test_result(result, worker.status)
58
+ report_actual(result) unless result.checked?
59
+ end
60
+
61
+ def on_test_omission(worker, result)
62
+ report_test_result(result, worker.status)
63
+ report_actual(result)
64
+ end
65
+
66
+ def on_test_no_check(worker, result)
67
+ report_test_result(result, worker.status)
68
+ report_actual(result)
69
+ end
70
+
71
+ def on_test_finish(worker, result)
72
+ end
73
+
74
+ def on_suite_finish(worker)
75
+ end
76
+
77
+ def on_worker_finish(worker_id)
78
+ end
79
+
80
+ def on_finish(result)
81
+ puts
82
+ report_summary(result)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,64 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "json"
19
+ require "msgpack"
20
+
21
+ require "grntest/error"
22
+
23
+ module Grntest
24
+ class ResponseParser
25
+ class << self
26
+ def parse(content, type)
27
+ parser = new(type)
28
+ parser.parse(content)
29
+ end
30
+ end
31
+
32
+ def initialize(type)
33
+ @type = type
34
+ end
35
+
36
+ def parse(content)
37
+ case @type
38
+ when "json", "msgpack"
39
+ parse_result(content.chomp)
40
+ else
41
+ content
42
+ end
43
+ end
44
+
45
+ def parse_result(result)
46
+ case @type
47
+ when "json"
48
+ begin
49
+ JSON.parse(result)
50
+ rescue JSON::ParserError
51
+ raise ParseError.new(@type, result, $!.message)
52
+ end
53
+ when "msgpack"
54
+ begin
55
+ MessagePack.unpack(result.chomp)
56
+ rescue MessagePack::UnpackError, NoMemoryError
57
+ raise ParseError.new(@type, result, $!.message)
58
+ end
59
+ else
60
+ raise ParseError.new(@type, result, "unknown type")
61
+ end
62
+ end
63
+ end
64
+ end