test-unit-runner-tk 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/tk.rb
6
+ lib/test/unit/ui/tk/testrunner.rb
@@ -0,0 +1,25 @@
1
+ = Test::Unit::Runner::Tk
2
+
3
+ * http://rubyforge.org/projects/test-unit/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Test::Unit::Runner::Tk - A Test::Unit UI built on Ruby/Tk.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * This provides "--runner=tk" option to use Tk UI.
12
+
13
+ == INSTALL:
14
+
15
+ * sudo gem install test-unit-runner-tk
16
+
17
+ == USAGE:
18
+
19
+ require 'test/unit/runner/tk'
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/tk'
7
+
8
+ Test::Unit.run = true
9
+
10
+ version = Test::Unit::Runner::Tk::VERSION
11
+ ENV["VERSION"] = version
12
+ Hoe.new('test-unit-runner-tk', 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::Tk #{version}!"
21
+ base = "svn+ssh://#{ENV['USER']}@rubyforge.org/var/svn/test-unit/extensions/test-unit-runner-tk/"
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(:tk) do |auto_runner|
6
+ require 'test/unit/ui/tk/testrunner'
7
+ Test::Unit::UI::Tk::TestRunner
8
+ end
9
+
10
+ module Runner
11
+ module Tk
12
+ VERSION = "0.0.1"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,260 @@
1
+ #--
2
+ #
3
+ # Original Author:: Nathaniel Talbott.
4
+ # Author:: Kazuhiro NISHIYAMA.
5
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
6
+ # Copyright:: Copyright (c) 2003 Kazuhiro NISHIYAMA. All rights reserved.
7
+ # License:: Ruby license.
8
+
9
+ require 'tk'
10
+ require 'test/unit/ui/testrunnermediator'
11
+ require 'test/unit/ui/testrunnerutilities'
12
+
13
+ module Test
14
+ module Unit
15
+ module UI
16
+ module Tk
17
+
18
+ # Runs a Test::Unit::TestSuite in a Tk UI. Obviously,
19
+ # this one requires you to have Tk
20
+ # and the Ruby Tk extension installed.
21
+ class TestRunner
22
+ extend TestRunnerUtilities
23
+
24
+ # Creates a new TestRunner for running the passed
25
+ # suite.
26
+ def initialize(suite, output_level = NORMAL)
27
+ if (suite.respond_to?(:suite))
28
+ @suite = suite.suite
29
+ else
30
+ @suite = suite
31
+ end
32
+ @result = nil
33
+
34
+ @red = false
35
+ @fault_detail_list = []
36
+ @runner = Thread.current
37
+ @restart_signal = Class.new(Exception)
38
+ @viewer = Thread.start do
39
+ @runner.join rescue @runner.run
40
+ ::Tk.mainloop
41
+ end
42
+ @viewer.join rescue nil # wait deadlock to handshake
43
+ end
44
+
45
+ # Begins the test run.
46
+ def start
47
+ setup_ui
48
+ setup_mediator
49
+ attach_to_mediator
50
+ start_ui
51
+ @result
52
+ end
53
+
54
+ private
55
+ def setup_mediator
56
+ @mediator = TestRunnerMediator.new(@suite)
57
+ suite_name = @suite.to_s
58
+ if ( @suite.kind_of?(Module) )
59
+ suite_name = @suite.name
60
+ end
61
+ @suite_name_entry.value = suite_name
62
+ end
63
+
64
+ def attach_to_mediator
65
+ @run_button.command(method(:run_test))
66
+ @fault_list.bind('ButtonPress-1', proc{|y|
67
+ fault = @fault_detail_list[@fault_list.nearest(y)]
68
+ if fault
69
+ show_fault(fault)
70
+ end
71
+ }, '%y')
72
+ @mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui))
73
+ @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
74
+ @mediator.add_listener(TestResult::CHANGED, &method(:result_changed))
75
+ @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
76
+ @mediator.add_listener(TestCase::STARTED, &method(:test_started))
77
+ @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
78
+ end
79
+
80
+ def run_test
81
+ @runner.raise(@restart_signal)
82
+ end
83
+
84
+ def start_ui
85
+ @viewer.run
86
+ running = false
87
+ begin
88
+ loop do
89
+ if (running ^= true)
90
+ @run_button.configure('text'=>'Stop')
91
+ @mediator.run_suite
92
+ else
93
+ @run_button.configure('text'=>'Run')
94
+ @viewer.join
95
+ break
96
+ end
97
+ end
98
+ rescue @restart_signal
99
+ retry
100
+ rescue
101
+ end
102
+ end
103
+
104
+ def stop
105
+ ::Tk.exit
106
+ end
107
+
108
+ def reset_ui(count)
109
+ @test_total_count = count.to_f
110
+ @test_progress_bar.configure('background'=>'green')
111
+ @test_progress_bar.place('relwidth'=>(count.zero? ? 0 : 0/count))
112
+ @red = false
113
+
114
+ @test_count_label.value = 0
115
+ @assertion_count_label.value = 0
116
+ @failure_count_label.value = 0
117
+ @error_count_label.value = 0
118
+
119
+ @fault_list.delete(0, 'end')
120
+ @fault_detail_list = []
121
+ clear_fault
122
+ end
123
+
124
+ def add_fault(fault)
125
+ if ( ! @red )
126
+ @test_progress_bar.configure('background'=>'red')
127
+ @red = true
128
+ end
129
+ @fault_detail_list.push fault
130
+ @fault_list.insert('end', fault.short_display)
131
+ end
132
+
133
+ def show_fault(fault)
134
+ raw_show_fault(fault.long_display)
135
+ end
136
+
137
+ def raw_show_fault(string)
138
+ @detail_text.value = string
139
+ end
140
+
141
+ def clear_fault
142
+ raw_show_fault("")
143
+ end
144
+
145
+ def result_changed(result)
146
+ @test_count_label.value = result.run_count
147
+ @test_progress_bar.place('relwidth'=>result.run_count/@test_total_count)
148
+ @assertion_count_label.value = result.assertion_count
149
+ @failure_count_label.value = result.failure_count
150
+ @error_count_label.value = result.error_count
151
+ end
152
+
153
+ def started(result)
154
+ @result = result
155
+ output_status("Started...")
156
+ end
157
+
158
+ def test_started(test_name)
159
+ output_status("Running #{test_name}...")
160
+ end
161
+
162
+ def finished(elapsed_time)
163
+ output_status("Finished in #{elapsed_time} seconds")
164
+ end
165
+
166
+ def output_status(string)
167
+ @status_entry.value = string
168
+ end
169
+
170
+ def setup_ui
171
+ @status_entry = TkVariable.new
172
+ l = TkLabel.new(nil, 'textvariable'=>@status_entry, 'relief'=>'sunken')
173
+ l.pack('side'=>'bottom', 'fill'=>'x')
174
+
175
+ suite_frame = TkFrame.new.pack('fill'=>'x')
176
+
177
+ @run_button = TkButton.new(suite_frame, 'text'=>'Run')
178
+ @run_button.pack('side'=>'right')
179
+
180
+ TkLabel.new(suite_frame, 'text'=>'Suite:').pack('side'=>'left')
181
+ @suite_name_entry = TkVariable.new
182
+ l = TkLabel.new(suite_frame, 'textvariable'=>@suite_name_entry, 'relief'=>'sunken')
183
+ l.pack('side'=>'left', 'fill'=>'x', 'expand'=>true)
184
+
185
+ f = TkFrame.new(nil, 'relief'=>'sunken', 'borderwidth'=>3, 'height'=>20).pack('fill'=>'x', 'padx'=>1)
186
+ @test_progress_bar = TkFrame.new(f, 'background'=>'green').place('anchor'=>'nw', 'relwidth'=>0.0, 'relheight'=>1.0)
187
+
188
+ info_frame = TkFrame.new.pack('fill'=>'x')
189
+ @test_count_label = create_count_label(info_frame, 'Tests:')
190
+ @assertion_count_label = create_count_label(info_frame, 'Assertions:')
191
+ @failure_count_label = create_count_label(info_frame, 'Failures:')
192
+ @error_count_label = create_count_label(info_frame, 'Errors:')
193
+
194
+ if (::Tk.info('command', TkPanedWindow::TkCommandNames[0]) != "")
195
+ # use panedwindow
196
+ paned_frame = TkPanedWindow.new("orient"=>"vertical").pack('fill'=>'both', 'expand'=>true)
197
+
198
+ fault_list_frame = TkFrame.new(paned_frame)
199
+ detail_frame = TkFrame.new(paned_frame)
200
+
201
+ paned_frame.add(fault_list_frame, detail_frame)
202
+ else
203
+ # no panedwindow
204
+ paned_frame = nil
205
+ fault_list_frame = TkFrame.new.pack('fill'=>'both', 'expand'=>true)
206
+ detail_frame = TkFrame.new.pack('fill'=>'both', 'expand'=>true)
207
+ end
208
+
209
+ TkGrid.rowconfigure(fault_list_frame, 0, 'weight'=>1, 'minsize'=>0)
210
+ TkGrid.columnconfigure(fault_list_frame, 0, 'weight'=>1, 'minsize'=>0)
211
+
212
+ fault_scrollbar_y = TkScrollbar.new(fault_list_frame)
213
+ fault_scrollbar_x = TkScrollbar.new(fault_list_frame)
214
+ @fault_list = TkListbox.new(fault_list_frame)
215
+ @fault_list.yscrollbar(fault_scrollbar_y)
216
+ @fault_list.xscrollbar(fault_scrollbar_x)
217
+
218
+ TkGrid.rowconfigure(detail_frame, 0, 'weight'=>1, 'minsize'=>0)
219
+ TkGrid.columnconfigure(detail_frame, 0, 'weight'=>1, 'minsize'=>0)
220
+
221
+ ::Tk.grid(@fault_list, fault_scrollbar_y, 'sticky'=>'news')
222
+ ::Tk.grid(fault_scrollbar_x, 'sticky'=>'news')
223
+
224
+ detail_scrollbar_y = TkScrollbar.new(detail_frame)
225
+ detail_scrollbar_x = TkScrollbar.new(detail_frame)
226
+ @detail_text = TkText.new(detail_frame, 'height'=>10, 'wrap'=>'none') {
227
+ bindtags(bindtags - [TkText])
228
+ }
229
+ @detail_text.yscrollbar(detail_scrollbar_y)
230
+ @detail_text.xscrollbar(detail_scrollbar_x)
231
+
232
+ ::Tk.grid(@detail_text, detail_scrollbar_y, 'sticky'=>'news')
233
+ ::Tk.grid(detail_scrollbar_x, 'sticky'=>'news')
234
+
235
+ # rubber-style pane
236
+ if paned_frame
237
+ ::Tk.update
238
+ @height = paned_frame.winfo_height
239
+ paned_frame.bind('Configure', proc{|h|
240
+ paned_frame.sash_place(0, 0, paned_frame.sash_coord(0)[1] * h / @height)
241
+ @height = h
242
+ }, '%h')
243
+ end
244
+ end
245
+
246
+ def create_count_label(parent, label)
247
+ TkLabel.new(parent, 'text'=>label).pack('side'=>'left', 'expand'=>true)
248
+ v = TkVariable.new(0)
249
+ TkLabel.new(parent, 'textvariable'=>v).pack('side'=>'left', 'expand'=>true)
250
+ v
251
+ end
252
+ end
253
+ end
254
+ end
255
+ end
256
+ end
257
+
258
+ if __FILE__ == $0
259
+ Test::Unit::UI::Tk::TestRunner.start_command_line_test
260
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test-unit-runner-tk
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::Tk - A Test::Unit UI built on Ruby/Tk.
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/tk.rb
43
+ - lib/test/unit/ui/tk/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::Tk - A Test::Unit UI built on Ruby/Tk.
71
+ test_files: []
72
+