test-unit-runner-gtk2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ === 0.0.1 / 2008-06-18
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday (as a gem)!
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/test/unit/runner/gtk2.rb
6
+ lib/test/unit/ui/gtk2/testrunner.rb
@@ -0,0 +1,25 @@
1
+ = Test::Unit::Runner::GTK2
2
+
3
+ * http://rubyforge.org/projects/test-unit/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Test::Unit::Runner::GTK2 - A Test::Unit UI built on Ruby/GTK2.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * This provides "--runner=gtk2" option to use GTK+ UI.
12
+
13
+ == INSTALL:
14
+
15
+ * sudo gem install test-unit-runner-gtk2
16
+
17
+ == USAGE:
18
+
19
+ require 'test/unit/runner/gtk2'
20
+
21
+ == LICENSE:
22
+
23
+ (The Ruby License)
24
+
25
+ This software is distributed under the same terms as ruby.
@@ -0,0 +1,25 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ gem 'test-unit'
5
+ require 'hoe'
6
+ require './lib/test/unit/runner/gtk2'
7
+
8
+ Test::Unit.run = true
9
+
10
+ version = Test::Unit::Runner::GTK2::VERSION
11
+ ENV["VERSION"] = version
12
+ Hoe.new('test-unit-runner-gtk2', version) do |p|
13
+ p.developer('Kouhei Sutou', 'kou@cozmixng.org')
14
+ p.developer('Ryan Davis', 'ryand-ruby@zenspider.com')
15
+
16
+ p.rubyforge_name = "test-unit"
17
+ end
18
+
19
+ task :tag do
20
+ message = "Released Test::Unit::Runner::GTK+ #{version}!"
21
+ base = "svn+ssh://#{ENV['USER']}@rubyforge.org/var/svn/test-unit/extensions/test-unit-runner-gtk2/"
22
+ sh 'svn', 'copy', '-m', message, "#{base}trunk", "#{base}tags/#{version}"
23
+ end
24
+
25
+ # vim: syntax=Ruby
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+
3
+ module Test
4
+ module Unit
5
+ AutoRunner.register_runner(:gtk2) do |auto_runner|
6
+ require 'test/unit/ui/gtk2/testrunner'
7
+ Test::Unit::UI::GTK2::TestRunner
8
+ end
9
+
10
+ module Runner
11
+ module GTK2
12
+ VERSION = "0.0.1"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,459 @@
1
+ #--
2
+ #
3
+ # Author:: Kenta MURATA.
4
+ # Copyright:: Copyright (c) 2000-2002 Kenta MURATA. All rights reserved.
5
+ # License:: Ruby license.
6
+
7
+ require "gtk2"
8
+ require "test/unit/ui/testrunner"
9
+ require "test/unit/ui/testrunnermediator"
10
+
11
+ module Test
12
+ module Unit
13
+ module UI
14
+ module GTK2
15
+
16
+ Gtk.init
17
+
18
+ class EnhancedLabel < Gtk::Label
19
+ def set_text(text)
20
+ super(text.gsub(/\n\t/, "\n "))
21
+ end
22
+ end
23
+
24
+ class FaultList < Gtk::TreeView
25
+ def initialize
26
+ @faults = []
27
+ @model = Gtk::ListStore.new(String, String)
28
+ super(@model)
29
+ column = Gtk::TreeViewColumn.new
30
+ column.visible = false
31
+ append_column(column)
32
+ renderer = Gtk::CellRendererText.new
33
+ column = Gtk::TreeViewColumn.new("Failures", renderer, {:text => 1})
34
+ append_column(column)
35
+ selection.mode = Gtk::SELECTION_SINGLE
36
+ set_rules_hint(true)
37
+ set_headers_visible(false)
38
+ end # def initialize
39
+
40
+ def add_fault(fault)
41
+ @faults.push(fault)
42
+ iter = @model.append
43
+ iter.set_value(0, (@faults.length - 1).to_s)
44
+ iter.set_value(1, fault.short_display)
45
+ end # def add_fault(fault)
46
+
47
+ def get_fault(iter)
48
+ @faults[iter.get_value(0).to_i]
49
+ end # def get_fault
50
+
51
+ def clear
52
+ model.clear
53
+ end # def clear
54
+ end
55
+
56
+ class TestRunner < UI::TestRunner
57
+ def lazy_initialize(symbol)
58
+ if !instance_eval("defined?(@#{symbol})") then
59
+ yield
60
+ end
61
+ return instance_eval("@#{symbol}")
62
+ end
63
+ private :lazy_initialize
64
+
65
+ def status_entry
66
+ lazy_initialize(:status_entry) do
67
+ @status_entry = Gtk::Entry.new
68
+ @status_entry.editable = false
69
+ end
70
+ end
71
+ private :status_entry
72
+
73
+ def status_panel
74
+ lazy_initialize(:status_panel) do
75
+ @status_panel = Gtk::HBox.new
76
+ @status_panel.border_width = 10
77
+ @status_panel.pack_start(status_entry, true, true, 0)
78
+ end
79
+ end
80
+ private :status_panel
81
+
82
+ def fault_detail_label
83
+ lazy_initialize(:fault_detail_label) do
84
+ @fault_detail_label = EnhancedLabel.new("")
85
+ # style = Gtk::Style.new
86
+ # font = Gdk::Font.
87
+ # font_load("-*-Courier 10 Pitch-medium-r-normal--*-120-*-*-*-*-*-*")
88
+ # style.set_font(font)
89
+ # @fault_detail_label.style = style
90
+ @fault_detail_label.justify = Gtk::JUSTIFY_LEFT
91
+ @fault_detail_label.wrap = false
92
+ end
93
+ end
94
+ private :fault_detail_label
95
+
96
+ def inner_detail_sub_panel
97
+ lazy_initialize(:inner_detail_sub_panel) do
98
+ @inner_detail_sub_panel = Gtk::HBox.new
99
+ @inner_detail_sub_panel.pack_start(fault_detail_label, false, false, 0)
100
+ end
101
+ end
102
+ private :inner_detail_sub_panel
103
+
104
+ def outer_detail_sub_panel
105
+ lazy_initialize(:outer_detail_sub_panel) do
106
+ @outer_detail_sub_panel = Gtk::VBox.new
107
+ @outer_detail_sub_panel.pack_start(inner_detail_sub_panel, false, false, 0)
108
+ end
109
+ end
110
+ private :outer_detail_sub_panel
111
+
112
+ def detail_scrolled_window
113
+ lazy_initialize(:detail_scrolled_window) do
114
+ @detail_scrolled_window = Gtk::ScrolledWindow.new
115
+ @detail_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
116
+ @detail_scrolled_window.
117
+ set_size_request(400, @detail_scrolled_window.allocation.height)
118
+ @detail_scrolled_window.add_with_viewport(outer_detail_sub_panel)
119
+ end
120
+ end
121
+ private :detail_scrolled_window
122
+
123
+ def detail_panel
124
+ lazy_initialize(:detail_panel) do
125
+ @detail_panel = Gtk::HBox.new
126
+ @detail_panel.border_width = 10
127
+ @detail_panel.pack_start(detail_scrolled_window, true, true, 0)
128
+ end
129
+ end
130
+ private :detail_panel
131
+
132
+ def fault_list
133
+ lazy_initialize(:fault_list) do
134
+ @fault_list = FaultList.new
135
+ end
136
+ end
137
+ private :fault_list
138
+
139
+ def list_scrolled_window
140
+ lazy_initialize(:list_scrolled_window) do
141
+ @list_scrolled_window = Gtk::ScrolledWindow.new
142
+ @list_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
143
+ @list_scrolled_window.
144
+ set_size_request(@list_scrolled_window.allocation.width, 150)
145
+ @list_scrolled_window.add_with_viewport(fault_list)
146
+ end
147
+ end
148
+ private :list_scrolled_window
149
+
150
+ def list_panel
151
+ lazy_initialize(:list_panel) do
152
+ @list_panel = Gtk::HBox.new
153
+ @list_panel.border_width = 10
154
+ @list_panel.pack_start(list_scrolled_window, true, true, 0)
155
+ end
156
+ end
157
+ private :list_panel
158
+
159
+ def error_count_label
160
+ lazy_initialize(:error_count_label) do
161
+ @error_count_label = Gtk::Label.new("0")
162
+ @error_count_label.justify = Gtk::JUSTIFY_LEFT
163
+ end
164
+ end
165
+ private :error_count_label
166
+
167
+ def failure_count_label
168
+ lazy_initialize(:failure_count_label) do
169
+ @failure_count_label = Gtk::Label.new("0")
170
+ @failure_count_label.justify = Gtk::JUSTIFY_LEFT
171
+ end
172
+ end
173
+ private :failure_count_label
174
+
175
+ def assertion_count_label
176
+ lazy_initialize(:assertion_count_label) do
177
+ @assertion_count_label = Gtk::Label.new("0")
178
+ @assertion_count_label.justify = Gtk::JUSTIFY_LEFT
179
+ end
180
+ end
181
+ private :assertion_count_label
182
+
183
+ def run_count_label
184
+ lazy_initialize(:run_count_label) do
185
+ @run_count_label = Gtk::Label.new("0")
186
+ @run_count_label.justify = Gtk::JUSTIFY_LEFT
187
+ end
188
+ end
189
+ private :run_count_label
190
+
191
+ def info_panel
192
+ lazy_initialize(:info_panel) do
193
+ @info_panel = Gtk::HBox.new(false, 0)
194
+ @info_panel.border_width = 10
195
+ @info_panel.pack_start(Gtk::Label.new("Runs:"), false, false, 0)
196
+ @info_panel.pack_start(run_count_label, true, false, 0)
197
+ @info_panel.pack_start(Gtk::Label.new("Assertions:"), false, false, 0)
198
+ @info_panel.pack_start(assertion_count_label, true, false, 0)
199
+ @info_panel.pack_start(Gtk::Label.new("Failures:"), false, false, 0)
200
+ @info_panel.pack_start(failure_count_label, true, false, 0)
201
+ @info_panel.pack_start(Gtk::Label.new("Errors:"), false, false, 0)
202
+ @info_panel.pack_start(error_count_label, true, false, 0)
203
+ end
204
+ end # def info_panel
205
+ private :info_panel
206
+
207
+ def green_style
208
+ lazy_initialize(:green_style) do
209
+ @green_style = Gtk::Style.new
210
+ @green_style.set_bg(Gtk::STATE_PRELIGHT, 0x0000, 0xFFFF, 0x0000)
211
+ end
212
+ end # def green_style
213
+ private :green_style
214
+
215
+ def red_style
216
+ lazy_initialize(:red_style) do
217
+ @red_style = Gtk::Style.new
218
+ @red_style.set_bg(Gtk::STATE_PRELIGHT, 0xFFFF, 0x0000, 0x0000)
219
+ end
220
+ end # def red_style
221
+ private :red_style
222
+
223
+ def test_progress_bar
224
+ lazy_initialize(:test_progress_bar) {
225
+ @test_progress_bar = Gtk::ProgressBar.new
226
+ @test_progress_bar.fraction = 0.0
227
+ @test_progress_bar.
228
+ set_size_request(@test_progress_bar.allocation.width,
229
+ info_panel.size_request[1])
230
+ @test_progress_bar.style = green_style
231
+ }
232
+ end # def test_progress_bar
233
+ private :test_progress_bar
234
+
235
+ def progress_panel
236
+ lazy_initialize(:progress_panel) do
237
+ @progress_panel = Gtk::HBox.new(false, 10)
238
+ @progress_panel.border_width = 10
239
+ @progress_panel.pack_start(test_progress_bar, true, true, 0)
240
+ end
241
+ end # def progress_panel
242
+
243
+ def run_button
244
+ lazy_initialize(:run_button) do
245
+ @run_button = Gtk::Button.new("Run")
246
+ end
247
+ end # def run_button
248
+
249
+ def suite_name_entry
250
+ lazy_initialize(:suite_name_entry) do
251
+ @suite_name_entry = Gtk::Entry.new
252
+ @suite_name_entry.editable = false
253
+ end
254
+ end # def suite_name_entry
255
+ private :suite_name_entry
256
+
257
+ def suite_panel
258
+ lazy_initialize(:suite_panel) do
259
+ @suite_panel = Gtk::HBox.new(false, 10)
260
+ @suite_panel.border_width = 10
261
+ @suite_panel.pack_start(Gtk::Label.new("Suite:"), false, false, 0)
262
+ @suite_panel.pack_start(suite_name_entry, true, true, 0)
263
+ @suite_panel.pack_start(run_button, false, false, 0)
264
+ end
265
+ end # def suite_panel
266
+ private :suite_panel
267
+
268
+ def main_panel
269
+ lazy_initialize(:main_panel) do
270
+ @main_panel = Gtk::VBox.new(false, 0)
271
+ @main_panel.pack_start(suite_panel, false, false, 0)
272
+ @main_panel.pack_start(progress_panel, false, false, 0)
273
+ @main_panel.pack_start(info_panel, false, false, 0)
274
+ @main_panel.pack_start(list_panel, false, false, 0)
275
+ @main_panel.pack_start(detail_panel, true, true, 0)
276
+ @main_panel.pack_start(status_panel, false, false, 0)
277
+ end
278
+ end # def main_panel
279
+ private :main_panel
280
+
281
+ def main_window
282
+ lazy_initialize(:main_window) do
283
+ @main_window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
284
+ @main_window.set_title("Test::Unit TestRunner")
285
+ @main_window.set_default_size(800, 600)
286
+ @main_window.set_resizable(true)
287
+ @main_window.add(main_panel)
288
+ end
289
+ end # def main_window
290
+ private :main_window
291
+
292
+ def setup_ui
293
+ main_window.signal_connect("destroy", nil) { stop }
294
+ main_window.show_all
295
+ fault_list.selection.signal_connect("changed", nil) do
296
+ |selection, data|
297
+ if selection.selected then
298
+ show_fault(fault_list.get_fault(selection.selected))
299
+ else
300
+ clear_fault
301
+ end
302
+ end
303
+ end # def setup_ui
304
+ private :setup_ui
305
+
306
+ def output_status(string)
307
+ status_entry.set_text(string)
308
+ end # def output_status(string)
309
+ private :output_status
310
+
311
+ def finished(elapsed_time)
312
+ test_progress_bar.fraction = 1.0
313
+ output_status("Finished in #{elapsed_time} seconds")
314
+ end # def finished(elapsed_time)
315
+ private :finished
316
+
317
+ def test_started(test_name)
318
+ output_status("Running #{test_name}...")
319
+ end # def test_started(test_name)
320
+ private :test_started
321
+
322
+ def started(result)
323
+ @result = result
324
+ output_status("Started...")
325
+ end # def started(result)
326
+ private :started
327
+
328
+ def test_finished(result)
329
+ test_progress_bar.fraction += 1.0 / @count
330
+ end # def test_finished(result)
331
+
332
+ def result_changed(result)
333
+ run_count_label.label = result.run_count.to_s
334
+ assertion_count_label.label = result.assertion_count.to_s
335
+ failure_count_label.label = result.failure_count.to_s
336
+ error_count_label.label = result.error_count.to_s
337
+ end # def result_changed(result)
338
+ private :result_changed
339
+
340
+ def clear_fault
341
+ raw_show_fault("")
342
+ end # def clear_fault
343
+ private :clear_fault
344
+
345
+ def raw_show_fault(string)
346
+ fault_detail_label.set_text(string)
347
+ outer_detail_sub_panel.queue_resize
348
+ end # def raw_show_fault(string)
349
+ private :raw_show_fault
350
+
351
+ def show_fault(fault)
352
+ raw_show_fault(fault.long_display)
353
+ end # def show_fault(fault)
354
+ private :show_fault
355
+
356
+ def add_fault(fault)
357
+ if not @red then
358
+ test_progress_bar.style = red_style
359
+ @red = true
360
+ end
361
+ fault_list.add_fault(fault)
362
+ end # def add_fault(fault)
363
+ private :add_fault
364
+
365
+ def reset_ui(count)
366
+ test_progress_bar.style = green_style
367
+ test_progress_bar.fraction = 0.0
368
+ @count = count + 1
369
+ @red = false
370
+
371
+ run_count_label.set_text("0")
372
+ assertion_count_label.set_text("0")
373
+ failure_count_label.set_text("0")
374
+ error_count_label.set_text("0")
375
+
376
+ fault_list.clear
377
+ end # def reset_ui(count)
378
+ private :reset_ui
379
+
380
+ def stop
381
+ Gtk.main_quit
382
+ end # def stop
383
+ private :stop
384
+
385
+ def run_test
386
+ @runner.raise(@restart_signal)
387
+ end
388
+ private :run_test
389
+
390
+ def start_ui
391
+ @viewer.run
392
+ running = false
393
+ begin
394
+ loop do
395
+ if (running ^= true)
396
+ run_button.child.text = "Stop"
397
+ @mediator.run_suite
398
+ else
399
+ run_button.child.text = "Run"
400
+ @viewer.join
401
+ break
402
+ end
403
+ end
404
+ rescue @restart_signal
405
+ retry
406
+ rescue
407
+ end
408
+ end # def start_ui
409
+ private :start_ui
410
+
411
+ def attach_to_mediator
412
+ run_button.signal_connect("clicked", nil) { run_test }
413
+ @mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui))
414
+ @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
415
+ @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
416
+ @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
417
+ @mediator.add_listener(TestResult::CHANGED, &method(:result_changed))
418
+ @mediator.add_listener(TestCase::STARTED, &method(:test_started))
419
+ @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
420
+ end # def attach_to_mediator
421
+ private :attach_to_mediator
422
+
423
+ def setup_mediator
424
+ @mediator = TestRunnerMediator.new(@suite)
425
+ suite_name = @suite.to_s
426
+ if @suite.kind_of?(Module) then
427
+ suite_name = @suite.name
428
+ end
429
+ suite_name_entry.set_text(suite_name)
430
+ end # def setup_mediator
431
+ private :setup_mediator
432
+
433
+ def start
434
+ setup_mediator
435
+ setup_ui
436
+ attach_to_mediator
437
+ start_ui
438
+ @result
439
+ end # def start
440
+
441
+ def initialize(suite, options={})
442
+ super
443
+ @result = nil
444
+
445
+ @runner = Thread.current
446
+ @restart_signal = Class.new(Exception)
447
+ @viewer = Thread.start do
448
+ @runner.join rescue @runner.run
449
+ Gtk.main
450
+ end
451
+ @viewer.join rescue nil # wait deadlock to handshake
452
+ end # def initialize
453
+
454
+ end # class TestRunner
455
+
456
+ end # module GTK2
457
+ end # module UI
458
+ end # module Unit
459
+ end # module Test
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test-unit-runner-gtk2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kouhei Sutou
8
+ - Ryan Davis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-06-18 00:00:00 +09:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: hoe
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.6.0
24
+ version:
25
+ description: Test::Unit::Runner::GTK2 - A Test::Unit UI built on Ruby/GTK2.
26
+ email:
27
+ - kou@cozmixng.org
28
+ - ryand-ruby@zenspider.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files:
34
+ - History.txt
35
+ - Manifest.txt
36
+ - README.txt
37
+ files:
38
+ - History.txt
39
+ - Manifest.txt
40
+ - README.txt
41
+ - Rakefile
42
+ - lib/test/unit/runner/gtk2.rb
43
+ - lib/test/unit/ui/gtk2/testrunner.rb
44
+ has_rdoc: true
45
+ homepage: http://rubyforge.org/projects/test-unit/
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --main
49
+ - README.txt
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: test-unit
67
+ rubygems_version: 1.1.1
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Test::Unit::Runner::GTK2 - A Test::Unit UI built on Ruby/GTK2.
71
+ test_files: []
72
+