[18425] | 1 | #--
|
---|
| 2 | #
|
---|
| 3 | # Author:: Nathaniel Talbott.
|
---|
| 4 | # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
---|
| 5 | # License:: Ruby license.
|
---|
| 6 |
|
---|
| 7 | require 'fox'
|
---|
| 8 | require 'test/unit/ui/testrunnermediator'
|
---|
| 9 | require 'test/unit/ui/testrunnerutilities'
|
---|
| 10 |
|
---|
| 11 | include Fox
|
---|
| 12 |
|
---|
| 13 | module Test
|
---|
| 14 | module Unit
|
---|
| 15 | module UI
|
---|
| 16 | module Fox
|
---|
| 17 |
|
---|
| 18 | # Runs a Test::Unit::TestSuite in a Fox UI. Obviously,
|
---|
| 19 | # this one requires you to have Fox
|
---|
| 20 | # (http://www.fox-toolkit.org/fox.html) and the Ruby
|
---|
| 21 | # Fox extension (http://fxruby.sourceforge.net/)
|
---|
| 22 | # installed.
|
---|
| 23 | class TestRunner
|
---|
| 24 |
|
---|
| 25 | extend TestRunnerUtilities
|
---|
| 26 |
|
---|
| 27 | RED_STYLE = FXRGBA(0xFF,0,0,0xFF) #0xFF000000
|
---|
| 28 | GREEN_STYLE = FXRGBA(0,0xFF,0,0xFF) #0x00FF0000
|
---|
| 29 |
|
---|
| 30 | # Creates a new TestRunner for running the passed
|
---|
| 31 | # suite.
|
---|
| 32 | def initialize(suite, output_level = NORMAL)
|
---|
| 33 | if (suite.respond_to?(:suite))
|
---|
| 34 | @suite = suite.suite
|
---|
| 35 | else
|
---|
| 36 | @suite = suite
|
---|
| 37 | end
|
---|
| 38 |
|
---|
| 39 | @result = nil
|
---|
| 40 | @red = false
|
---|
| 41 | end
|
---|
| 42 |
|
---|
| 43 | # Begins the test run.
|
---|
| 44 | def start
|
---|
| 45 | setup_ui
|
---|
| 46 | setup_mediator
|
---|
| 47 | attach_to_mediator
|
---|
| 48 | start_ui
|
---|
| 49 | @result
|
---|
| 50 | end
|
---|
| 51 |
|
---|
| 52 | def setup_mediator
|
---|
| 53 | @mediator = TestRunnerMediator.new(@suite)
|
---|
| 54 | suite_name = @suite.to_s
|
---|
| 55 | if ( @suite.kind_of?(Module) )
|
---|
| 56 | suite_name = @suite.name
|
---|
| 57 | end
|
---|
| 58 | @suite_name_entry.text = suite_name
|
---|
| 59 | end
|
---|
| 60 |
|
---|
| 61 | def attach_to_mediator
|
---|
| 62 | @mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui))
|
---|
| 63 | @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
|
---|
| 64 | @mediator.add_listener(TestResult::CHANGED, &method(:result_changed))
|
---|
| 65 | @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
|
---|
| 66 | @mediator.add_listener(TestCase::STARTED, &method(:test_started))
|
---|
| 67 | @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
|
---|
| 68 | end
|
---|
| 69 |
|
---|
| 70 | def start_ui
|
---|
| 71 | @application.create
|
---|
| 72 | @window.show(PLACEMENT_SCREEN)
|
---|
| 73 | @application.addTimeout(1) do
|
---|
| 74 | @mediator.run_suite
|
---|
| 75 | end
|
---|
| 76 | @application.run
|
---|
| 77 | end
|
---|
| 78 |
|
---|
| 79 | def stop
|
---|
| 80 | @application.exit(0)
|
---|
| 81 | end
|
---|
| 82 |
|
---|
| 83 | def reset_ui(count)
|
---|
| 84 | @test_progress_bar.barColor = GREEN_STYLE
|
---|
| 85 | @test_progress_bar.total = count
|
---|
| 86 | @test_progress_bar.progress = 0
|
---|
| 87 | @red = false
|
---|
| 88 |
|
---|
| 89 | @test_count_label.text = "0"
|
---|
| 90 | @assertion_count_label.text = "0"
|
---|
| 91 | @failure_count_label.text = "0"
|
---|
| 92 | @error_count_label.text = "0"
|
---|
| 93 |
|
---|
| 94 | @fault_list.clearItems
|
---|
| 95 | end
|
---|
| 96 |
|
---|
| 97 | def add_fault(fault)
|
---|
| 98 | if ( ! @red )
|
---|
| 99 | @test_progress_bar.barColor = RED_STYLE
|
---|
| 100 | @red = true
|
---|
| 101 | end
|
---|
| 102 | item = FaultListItem.new(fault)
|
---|
| 103 | @fault_list.appendItem(item)
|
---|
| 104 | end
|
---|
| 105 |
|
---|
| 106 | def show_fault(fault)
|
---|
| 107 | raw_show_fault(fault.long_display)
|
---|
| 108 | end
|
---|
| 109 |
|
---|
| 110 | def raw_show_fault(string)
|
---|
| 111 | @detail_text.setText(string)
|
---|
| 112 | end
|
---|
| 113 |
|
---|
| 114 | def clear_fault
|
---|
| 115 | raw_show_fault("")
|
---|
| 116 | end
|
---|
| 117 |
|
---|
| 118 | def result_changed(result)
|
---|
| 119 | @test_progress_bar.progress = result.run_count
|
---|
| 120 |
|
---|
| 121 | @test_count_label.text = result.run_count.to_s
|
---|
| 122 | @assertion_count_label.text = result.assertion_count.to_s
|
---|
| 123 | @failure_count_label.text = result.failure_count.to_s
|
---|
| 124 | @error_count_label.text = result.error_count.to_s
|
---|
| 125 |
|
---|
| 126 | # repaint now!
|
---|
| 127 | @info_panel.repaint
|
---|
| 128 | @application.flush
|
---|
| 129 | end
|
---|
| 130 |
|
---|
| 131 | def started(result)
|
---|
| 132 | @result = result
|
---|
| 133 | output_status("Started...")
|
---|
| 134 | end
|
---|
| 135 |
|
---|
| 136 | def test_started(test_name)
|
---|
| 137 | output_status("Running #{test_name}...")
|
---|
| 138 | end
|
---|
| 139 |
|
---|
| 140 | def finished(elapsed_time)
|
---|
| 141 | output_status("Finished in #{elapsed_time} seconds")
|
---|
| 142 | end
|
---|
| 143 |
|
---|
| 144 | def output_status(string)
|
---|
| 145 | @status_entry.text = string
|
---|
| 146 | @status_entry.repaint
|
---|
| 147 | end
|
---|
| 148 |
|
---|
| 149 | def setup_ui
|
---|
| 150 | @application = create_application
|
---|
| 151 | create_tooltip(@application)
|
---|
| 152 |
|
---|
| 153 | @window = create_window(@application)
|
---|
| 154 |
|
---|
| 155 | @status_entry = create_entry(@window)
|
---|
| 156 |
|
---|
| 157 | main_panel = create_main_panel(@window)
|
---|
| 158 |
|
---|
| 159 | suite_panel = create_suite_panel(main_panel)
|
---|
| 160 | create_label(suite_panel, "Suite:")
|
---|
| 161 | @suite_name_entry = create_entry(suite_panel)
|
---|
| 162 | create_button(suite_panel, "&Run\tRun the current suite", proc { @mediator.run_suite })
|
---|
| 163 |
|
---|
| 164 | @test_progress_bar = create_progress_bar(main_panel)
|
---|
| 165 |
|
---|
| 166 | @info_panel = create_info_panel(main_panel)
|
---|
| 167 | create_label(@info_panel, "Tests:")
|
---|
| 168 | @test_count_label = create_label(@info_panel, "0")
|
---|
| 169 | create_label(@info_panel, "Assertions:")
|
---|
| 170 | @assertion_count_label = create_label(@info_panel, "0")
|
---|
| 171 | create_label(@info_panel, "Failures:")
|
---|
| 172 | @failure_count_label = create_label(@info_panel, "0")
|
---|
| 173 | create_label(@info_panel, "Errors:")
|
---|
| 174 | @error_count_label = create_label(@info_panel, "0")
|
---|
| 175 |
|
---|
| 176 | list_panel = create_list_panel(main_panel)
|
---|
| 177 | @fault_list = create_fault_list(list_panel)
|
---|
| 178 |
|
---|
| 179 | detail_panel = create_detail_panel(main_panel)
|
---|
| 180 | @detail_text = create_text(detail_panel)
|
---|
| 181 | end
|
---|
| 182 |
|
---|
| 183 | def create_application
|
---|
| 184 | app = FXApp.new("TestRunner", "Test::Unit")
|
---|
| 185 | app.init([])
|
---|
| 186 | app
|
---|
| 187 | end
|
---|
| 188 |
|
---|
| 189 | def create_window(app)
|
---|
| 190 | FXMainWindow.new(app, "Test::Unit TestRunner", nil, nil, DECOR_ALL, 0, 0, 450)
|
---|
| 191 | end
|
---|
| 192 |
|
---|
| 193 | def create_tooltip(app)
|
---|
| 194 | FXTooltip.new(app)
|
---|
| 195 | end
|
---|
| 196 |
|
---|
| 197 | def create_main_panel(parent)
|
---|
| 198 | panel = FXVerticalFrame.new(parent, LAYOUT_FILL_X | LAYOUT_FILL_Y)
|
---|
| 199 | panel.vSpacing = 10
|
---|
| 200 | panel
|
---|
| 201 | end
|
---|
| 202 |
|
---|
| 203 | def create_suite_panel(parent)
|
---|
| 204 | FXHorizontalFrame.new(parent, LAYOUT_SIDE_LEFT | LAYOUT_FILL_X)
|
---|
| 205 | end
|
---|
| 206 |
|
---|
| 207 | def create_button(parent, text, action)
|
---|
| 208 | FXButton.new(parent, text).connect(SEL_COMMAND, &action)
|
---|
| 209 | end
|
---|
| 210 |
|
---|
| 211 | def create_progress_bar(parent)
|
---|
| 212 | FXProgressBar.new(parent, nil, 0, PROGRESSBAR_NORMAL | LAYOUT_FILL_X)
|
---|
| 213 | end
|
---|
| 214 |
|
---|
| 215 | def create_info_panel(parent)
|
---|
| 216 | FXMatrix.new(parent, 1, MATRIX_BY_ROWS | LAYOUT_FILL_X)
|
---|
| 217 | end
|
---|
| 218 |
|
---|
| 219 | def create_label(parent, text)
|
---|
| 220 | FXLabel.new(parent, text, nil, JUSTIFY_CENTER_X | LAYOUT_FILL_COLUMN)
|
---|
| 221 | end
|
---|
| 222 |
|
---|
| 223 | def create_list_panel(parent)
|
---|
| 224 | FXHorizontalFrame.new(parent, LAYOUT_FILL_X | FRAME_SUNKEN | FRAME_THICK)
|
---|
| 225 | end
|
---|
| 226 |
|
---|
| 227 | def create_fault_list(parent)
|
---|
| 228 | list = FXList.new(parent, 10, nil, 0, LIST_SINGLESELECT | LAYOUT_FILL_X) #, 0, 0, 0, 150)
|
---|
| 229 | list.connect(SEL_COMMAND) do |sender, sel, ptr|
|
---|
| 230 | if sender.retrieveItem(sender.currentItem).selected?
|
---|
| 231 | show_fault(sender.retrieveItem(sender.currentItem).fault)
|
---|
| 232 | else
|
---|
| 233 | clear_fault
|
---|
| 234 | end
|
---|
| 235 | end
|
---|
| 236 | list
|
---|
| 237 | end
|
---|
| 238 |
|
---|
| 239 | def create_detail_panel(parent)
|
---|
| 240 | FXHorizontalFrame.new(parent, LAYOUT_FILL_X | LAYOUT_FILL_Y | FRAME_SUNKEN | FRAME_THICK)
|
---|
| 241 | end
|
---|
| 242 |
|
---|
| 243 | def create_text(parent)
|
---|
| 244 | FXText.new(parent, nil, 0, TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y)
|
---|
| 245 | end
|
---|
| 246 |
|
---|
| 247 | def create_entry(parent)
|
---|
| 248 | entry = FXTextField.new(parent, 30, nil, 0, TEXTFIELD_NORMAL | LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X)
|
---|
| 249 | entry.disable
|
---|
| 250 | entry
|
---|
| 251 | end
|
---|
| 252 | end
|
---|
| 253 |
|
---|
| 254 | class FaultListItem < FXListItem
|
---|
| 255 | attr_reader(:fault)
|
---|
| 256 | def initialize(fault)
|
---|
| 257 | super(fault.short_display)
|
---|
| 258 | @fault = fault
|
---|
| 259 | end
|
---|
| 260 | end
|
---|
| 261 | end
|
---|
| 262 | end
|
---|
| 263 | end
|
---|
| 264 | end
|
---|
| 265 |
|
---|
| 266 | if __FILE__ == $0
|
---|
| 267 | Test::Unit::UI::Fox::TestRunner.start_command_line_test
|
---|
| 268 | end
|
---|