diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:02:05 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:02:05 +0000 |
commit | 0dc342de848a642ecce8db697b8fecd83a63e117 (patch) | |
tree | 2b7ed4724aff1f86073e4740134bda9c4aac1a39 /trunk/lib/test/unit/ui | |
parent | ef70cf7138ab8034b5b806f466e4b484b24f0f88 (diff) |
added tag v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/lib/test/unit/ui')
-rw-r--r-- | trunk/lib/test/unit/ui/console/testrunner.rb | 130 | ||||
-rw-r--r-- | trunk/lib/test/unit/ui/fox/testrunner.rb | 268 | ||||
-rw-r--r-- | trunk/lib/test/unit/ui/gtk/testrunner.rb | 416 | ||||
-rw-r--r-- | trunk/lib/test/unit/ui/gtk2/testrunner.rb | 465 | ||||
-rw-r--r-- | trunk/lib/test/unit/ui/testrunnermediator.rb | 68 | ||||
-rw-r--r-- | trunk/lib/test/unit/ui/testrunnerutilities.rb | 46 | ||||
-rw-r--r-- | trunk/lib/test/unit/ui/tk/testrunner.rb | 260 |
7 files changed, 1653 insertions, 0 deletions
diff --git a/trunk/lib/test/unit/ui/console/testrunner.rb b/trunk/lib/test/unit/ui/console/testrunner.rb new file mode 100644 index 0000000000..b6475c0037 --- /dev/null +++ b/trunk/lib/test/unit/ui/console/testrunner.rb @@ -0,0 +1,130 @@ +#-- +# +# Author:: Nathaniel Talbott. +# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. +# License:: Ruby license. + +require 'test/unit/ui/testrunnermediator' +require 'test/unit/ui/testrunnerutilities' + +module Test + module Unit + module UI + module Console # :nodoc: + + # Runs a Test::Unit::TestSuite on the console. + class TestRunner + extend TestRunnerUtilities + + # Creates a new TestRunner for running the passed + # suite. If quiet_mode is true, the output while + # running is limited to progress dots, errors and + # failures, and the final result. io specifies + # where runner output should go to; defaults to + # STDOUT. + def initialize(suite, output_level=NORMAL, io=STDOUT) + if (suite.respond_to?(:suite)) + @suite = suite.suite + else + @suite = suite + end + @output_level = output_level + @io = io + @already_outputted = false + @faults = [] + end + + # Begins the test run. + def start + setup_mediator + attach_to_mediator + return start_mediator + end + + private + def setup_mediator # :nodoc: + @mediator = create_mediator(@suite) + suite_name = @suite.to_s + if ( @suite.kind_of?(Module) ) + suite_name = @suite.name + end + output("Loaded suite #{suite_name}") + end + + def create_mediator(suite) # :nodoc: + return TestRunnerMediator.new(suite) + end + + def attach_to_mediator # :nodoc: + @mediator.add_listener(TestResult::FAULT, &method(:add_fault)) + @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started)) + @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished)) + @mediator.add_listener(TestCase::STARTED, &method(:test_started)) + @mediator.add_listener(TestCase::FINISHED, &method(:test_finished)) + end + + def start_mediator # :nodoc: + return @mediator.run_suite + end + + def add_fault(fault) # :nodoc: + @faults << fault + output_single(fault.single_character_display, PROGRESS_ONLY) + @already_outputted = true + end + + def started(result) + @result = result + output("Started") + end + + def finished(elapsed_time) + nl + output("Finished in #{elapsed_time} seconds.") + @faults.each_with_index do |fault, index| + nl + output("%3d) %s" % [index + 1, fault.long_display]) + end + nl + output(@result) + end + + def test_started(name) + $program_name = $0 + alias $0 $program_name + $PROGRAM_NAME += "\0#{name}" + output_single(name + ": ", VERBOSE) + end + + def test_finished(name) + output_single(".", PROGRESS_ONLY) unless (@already_outputted) + nl(VERBOSE) + @already_outputted = false + end + + def nl(level=NORMAL) + output("", level) + end + + def output(something, level=NORMAL) + @io.puts(something) if (output?(level)) + @io.flush + end + + def output_single(something, level=NORMAL) + @io.write(something) if (output?(level)) + @io.flush + end + + def output?(level) + level <= @output_level + end + end + end + end + end +end + +if __FILE__ == $0 + Test::Unit::UI::Console::TestRunner.start_command_line_test +end diff --git a/trunk/lib/test/unit/ui/fox/testrunner.rb b/trunk/lib/test/unit/ui/fox/testrunner.rb new file mode 100644 index 0000000000..34a8ff1288 --- /dev/null +++ b/trunk/lib/test/unit/ui/fox/testrunner.rb @@ -0,0 +1,268 @@ +#-- +# +# Author:: Nathaniel Talbott. +# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. +# License:: Ruby license. + +require 'fox' +require 'test/unit/ui/testrunnermediator' +require 'test/unit/ui/testrunnerutilities' + +include Fox + +module Test + module Unit + module UI + module Fox # :nodoc: + + # Runs a Test::Unit::TestSuite in a Fox UI. Obviously, + # this one requires you to have Fox + # (http://www.fox-toolkit.org/fox.html) and the Ruby + # Fox extension (http://fxruby.sourceforge.net/) + # installed. + class TestRunner + + extend TestRunnerUtilities + + RED_STYLE = FXRGBA(0xFF,0,0,0xFF) #0xFF000000 + GREEN_STYLE = FXRGBA(0,0xFF,0,0xFF) #0x00FF0000 + + # Creates a new TestRunner for running the passed + # suite. + def initialize(suite, output_level = NORMAL) + if (suite.respond_to?(:suite)) + @suite = suite.suite + else + @suite = suite + end + + @result = nil + @red = false + end + + # Begins the test run. + def start + setup_ui + setup_mediator + attach_to_mediator + start_ui + @result + end + + def setup_mediator # :nodoc: + @mediator = TestRunnerMediator.new(@suite) + suite_name = @suite.to_s + if ( @suite.kind_of?(Module) ) + suite_name = @suite.name + end + @suite_name_entry.text = suite_name + end + + def attach_to_mediator # :nodoc: + @mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui)) + @mediator.add_listener(TestResult::FAULT, &method(:add_fault)) + @mediator.add_listener(TestResult::CHANGED, &method(:result_changed)) + @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started)) + @mediator.add_listener(TestCase::STARTED, &method(:test_started)) + @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished)) + end + + def start_ui # :nodoc: + @application.create + @window.show(PLACEMENT_SCREEN) + @application.addTimeout(1) do + @mediator.run_suite + end + @application.run + end + + def stop # :nodoc: + @application.exit(0) + end + + def reset_ui(count) # :nodoc: + @test_progress_bar.barColor = GREEN_STYLE + @test_progress_bar.total = count + @test_progress_bar.progress = 0 + @red = false + + @test_count_label.text = "0" + @assertion_count_label.text = "0" + @failure_count_label.text = "0" + @error_count_label.text = "0" + + @fault_list.clearItems + end + + def add_fault(fault) # :nodoc: + if ( ! @red ) + @test_progress_bar.barColor = RED_STYLE + @red = true + end + item = FaultListItem.new(fault) + @fault_list.appendItem(item) + end + + def show_fault(fault) # :nodoc: + raw_show_fault(fault.long_display) + end + + def raw_show_fault(string) # :nodoc: + @detail_text.setText(string) + end + + def clear_fault # :nodoc: + raw_show_fault("") + end + + def result_changed(result) # :nodoc: + @test_progress_bar.progress = result.run_count + + @test_count_label.text = result.run_count.to_s + @assertion_count_label.text = result.assertion_count.to_s + @failure_count_label.text = result.failure_count.to_s + @error_count_label.text = result.error_count.to_s + + # repaint now! + @info_panel.repaint + @application.flush + end + + def started(result) # :nodoc: + @result = result + output_status("Started...") + end + + def test_started(test_name) + output_status("Running #{test_name}...") + end + + def finished(elapsed_time) + output_status("Finished in #{elapsed_time} seconds") + end + + def output_status(string) + @status_entry.text = string + @status_entry.repaint + end + + def setup_ui # :nodoc: + @application = create_application + create_tooltip(@application) + + @window = create_window(@application) + + @status_entry = create_entry(@window) + + main_panel = create_main_panel(@window) + + suite_panel = create_suite_panel(main_panel) + create_label(suite_panel, "Suite:") + @suite_name_entry = create_entry(suite_panel) + create_button(suite_panel, "&Run\tRun the current suite", proc { @mediator.run_suite }) + + @test_progress_bar = create_progress_bar(main_panel) + + @info_panel = create_info_panel(main_panel) + create_label(@info_panel, "Tests:") + @test_count_label = create_label(@info_panel, "0") + create_label(@info_panel, "Assertions:") + @assertion_count_label = create_label(@info_panel, "0") + create_label(@info_panel, "Failures:") + @failure_count_label = create_label(@info_panel, "0") + create_label(@info_panel, "Errors:") + @error_count_label = create_label(@info_panel, "0") + + list_panel = create_list_panel(main_panel) + @fault_list = create_fault_list(list_panel) + + detail_panel = create_detail_panel(main_panel) + @detail_text = create_text(detail_panel) + end + + def create_application # :nodoc: + app = FXApp.new("TestRunner", "Test::Unit") + app.init([]) + app + end + + def create_window(app) + FXMainWindow.new(app, "Test::Unit TestRunner", nil, nil, DECOR_ALL, 0, 0, 450) + end + + def create_tooltip(app) + FXTooltip.new(app) + end + + def create_main_panel(parent) # :nodoc: + panel = FXVerticalFrame.new(parent, LAYOUT_FILL_X | LAYOUT_FILL_Y) + panel.vSpacing = 10 + panel + end + + def create_suite_panel(parent) # :nodoc: + FXHorizontalFrame.new(parent, LAYOUT_SIDE_LEFT | LAYOUT_FILL_X) + end + + def create_button(parent, text, action) # :nodoc: + FXButton.new(parent, text).connect(SEL_COMMAND, &action) + end + + def create_progress_bar(parent) # :nodoc: + FXProgressBar.new(parent, nil, 0, PROGRESSBAR_NORMAL | LAYOUT_FILL_X) + end + + def create_info_panel(parent) # :nodoc: + FXMatrix.new(parent, 1, MATRIX_BY_ROWS | LAYOUT_FILL_X) + end + + def create_label(parent, text) + FXLabel.new(parent, text, nil, JUSTIFY_CENTER_X | LAYOUT_FILL_COLUMN) + end + + def create_list_panel(parent) # :nodoc: + FXHorizontalFrame.new(parent, LAYOUT_FILL_X | FRAME_SUNKEN | FRAME_THICK) + end + + def create_fault_list(parent) # :nodoc: + list = FXList.new(parent, 10, nil, 0, LIST_SINGLESELECT | LAYOUT_FILL_X) #, 0, 0, 0, 150) + list.connect(SEL_COMMAND) do |sender, sel, ptr| + if sender.retrieveItem(sender.currentItem).selected? + show_fault(sender.retrieveItem(sender.currentItem).fault) + else + clear_fault + end + end + list + end + + def create_detail_panel(parent) # :nodoc: + FXHorizontalFrame.new(parent, LAYOUT_FILL_X | LAYOUT_FILL_Y | FRAME_SUNKEN | FRAME_THICK) + end + + def create_text(parent) # :nodoc: + FXText.new(parent, nil, 0, TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y) + end + + def create_entry(parent) # :nodoc: + entry = FXTextField.new(parent, 30, nil, 0, TEXTFIELD_NORMAL | LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X) + entry.disable + entry + end + end + + class FaultListItem < FXListItem # :nodoc: all + attr_reader(:fault) + def initialize(fault) + super(fault.short_display) + @fault = fault + end + end + end + end + end +end + +if __FILE__ == $0 + Test::Unit::UI::Fox::TestRunner.start_command_line_test +end diff --git a/trunk/lib/test/unit/ui/gtk/testrunner.rb b/trunk/lib/test/unit/ui/gtk/testrunner.rb new file mode 100644 index 0000000000..c63cc6a39b --- /dev/null +++ b/trunk/lib/test/unit/ui/gtk/testrunner.rb @@ -0,0 +1,416 @@ +#-- +# +# Author:: Nathaniel Talbott. +# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. +# License:: Ruby license. + +require 'gtk' +require 'test/unit/ui/testrunnermediator' +require 'test/unit/ui/testrunnerutilities' + +module Test + module Unit + module UI + module GTK # :nodoc: + + # Runs a Test::Unit::TestSuite in a Gtk UI. Obviously, + # this one requires you to have Gtk + # (http://www.gtk.org/) and the Ruby Gtk extension + # (http://ruby-gnome.sourceforge.net/) installed. + class TestRunner + extend TestRunnerUtilities + + # Creates a new TestRunner for running the passed + # suite. + def initialize(suite, output_level = NORMAL) + if (suite.respond_to?(:suite)) + @suite = suite.suite + else + @suite = suite + end + @result = nil + + @runner = Thread.current + @restart_signal = Class.new(Exception) + @viewer = Thread.start do + @runner.join rescue @runner.run + Gtk.main + end + @viewer.join rescue nil # wait deadlock to handshake + end + + # Begins the test run. + def start + setup_mediator + setup_ui + attach_to_mediator + start_ui + @result + end + + private + def setup_mediator # :nodoc: + @mediator = TestRunnerMediator.new(@suite) + suite_name = @suite.to_s + if ( @suite.kind_of?(Module) ) + suite_name = @suite.name + end + suite_name_entry.set_text(suite_name) + end + + def attach_to_mediator # :nodoc: + run_button.signal_connect("clicked", nil, &method(:run_test)) + @mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui)) + @mediator.add_listener(TestResult::FAULT, &method(:add_fault)) + @mediator.add_listener(TestResult::CHANGED, &method(:result_changed)) + @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started)) + @mediator.add_listener(TestCase::STARTED, &method(:test_started)) + @mediator.add_listener(TestCase::FINISHED, &method(:test_finished)) + @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished)) + end + + def run_test(*) + @runner.raise(@restart_signal) + end + + def start_ui # :nodoc: + @viewer.run + running = false + begin + loop do + if (running ^= true) + run_button.child.text = "Stop" + @mediator.run_suite + else + run_button.child.text = "Run" + @viewer.join + break + end + end + rescue @restart_signal + retry + rescue + end + end + + def stop(*) # :nodoc: + Gtk.main_quit + end + + def reset_ui(count) # :nodoc: + test_progress_bar.set_style(green_style) + test_progress_bar.configure(0, 0, count) + @red = false + + run_count_label.set_text("0") + assertion_count_label.set_text("0") + failure_count_label.set_text("0") + error_count_label.set_text("0") + + fault_list.remove_items(fault_list.children) + end + + def add_fault(fault) # :nodoc: + if ( ! @red ) + test_progress_bar.set_style(red_style) + @red = true + end + item = FaultListItem.new(fault) + item.show + fault_list.append_items([item]) + end + + def show_fault(fault) # :nodoc: + raw_show_fault(fault.long_display) + end + + def raw_show_fault(string) # :nodoc: + fault_detail_label.set_text(string) + outer_detail_sub_panel.queue_resize + end + + def clear_fault # :nodoc: + raw_show_fault("") + end + + def result_changed(result) # :nodoc: + run_count_label.set_text(result.run_count.to_s) + assertion_count_label.set_text(result.assertion_count.to_s) + failure_count_label.set_text(result.failure_count.to_s) + error_count_label.set_text(result.error_count.to_s) + end + + def started(result) # :nodoc: + @result = result + output_status("Started...") + end + + def test_started(test_name) + output_status("Running #{test_name}...") + end + + def test_finished(test_name) + test_progress_bar.set_value(test_progress_bar.get_value + 1) + end + + def finished(elapsed_time) + output_status("Finished in #{elapsed_time} seconds") + end + + def output_status(string) # :nodoc: + status_entry.set_text(string) + end + + def setup_ui # :nodoc: + main_window.signal_connect("destroy", nil, &method(:stop)) + main_window.show_all + fault_list.signal_connect("select-child", nil) { + | list, item, data | + show_fault(item.fault) + } + fault_list.signal_connect("unselect-child", nil) { + clear_fault + } + @red = false + end + + def main_window # :nodoc: + lazy_initialize(:main_window) { + @main_window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL) + @main_window.set_title("Test::Unit TestRunner") + @main_window.set_usize(800, 600) + @main_window.set_uposition(20, 20) + @main_window.set_policy(true, true, false) + @main_window.add(main_panel) + } + end + + def main_panel # :nodoc: + lazy_initialize(:main_panel) { + @main_panel = Gtk::VBox.new(false, 0) + @main_panel.pack_start(suite_panel, false, false, 0) + @main_panel.pack_start(progress_panel, false, false, 0) + @main_panel.pack_start(info_panel, false, false, 0) + @main_panel.pack_start(list_panel, false, false, 0) + @main_panel.pack_start(detail_panel, true, true, 0) + @main_panel.pack_start(status_panel, false, false, 0) + } + end + + def suite_panel # :nodoc: + lazy_initialize(:suite_panel) { + @suite_panel = Gtk::HBox.new(false, 10) + @suite_panel.border_width(10) + @suite_panel.pack_start(Gtk::Label.new("Suite:"), false, false, 0) + @suite_panel.pack_start(suite_name_entry, true, true, 0) + @suite_panel.pack_start(run_button, false, false, 0) + } + end + + def suite_name_entry # :nodoc: + lazy_initialize(:suite_name_entry) { + @suite_name_entry = Gtk::Entry.new + @suite_name_entry.set_editable(false) + } + end + + def run_button # :nodoc: + lazy_initialize(:run_button) { + @run_button = Gtk::Button.new("Run") + } + end + + def progress_panel # :nodoc: + lazy_initialize(:progress_panel) { + @progress_panel = Gtk::HBox.new(false, 10) + @progress_panel.border_width(10) + @progress_panel.pack_start(test_progress_bar, true, true, 0) + } + end + + def test_progress_bar # :nodoc: + lazy_initialize(:test_progress_bar) { + @test_progress_bar = EnhancedProgressBar.new + @test_progress_bar.set_usize(@test_progress_bar.allocation.width, + info_panel.size_request.height) + @test_progress_bar.set_style(green_style) + } + end + + def green_style # :nodoc: + lazy_initialize(:green_style) { + @green_style = Gtk::Style.new + @green_style.set_bg(Gtk::STATE_PRELIGHT, 0x0000, 0xFFFF, 0x0000) + } + end + + def red_style # :nodoc: + lazy_initialize(:red_style) { + @red_style = Gtk::Style.new + @red_style.set_bg(Gtk::STATE_PRELIGHT, 0xFFFF, 0x0000, 0x0000) + } + end + + def info_panel # :nodoc: + lazy_initialize(:info_panel) { + @info_panel = Gtk::HBox.new(false, 0) + @info_panel.border_width(10) + @info_panel.pack_start(Gtk::Label.new("Runs:"), false, false, 0) + @info_panel.pack_start(run_count_label, true, false, 0) + @info_panel.pack_start(Gtk::Label.new("Assertions:"), false, false, 0) + @info_panel.pack_start(assertion_count_label, true, false, 0) + @info_panel.pack_start(Gtk::Label.new("Failures:"), false, false, 0) + @info_panel.pack_start(failure_count_label, true, false, 0) + @info_panel.pack_start(Gtk::Label.new("Errors:"), false, false, 0) + @info_panel.pack_start(error_count_label, true, false, 0) + } + end + + def run_count_label # :nodoc: + lazy_initialize(:run_count_label) { + @run_count_label = Gtk::Label.new("0") + @run_count_label.set_justify(Gtk::JUSTIFY_LEFT) + } + end + + def assertion_count_label # :nodoc: + lazy_initialize(:assertion_count_label) { + @assertion_count_label = Gtk::Label.new("0") + @assertion_count_label.set_justify(Gtk::JUSTIFY_LEFT) + } + end + + def failure_count_label # :nodoc: + lazy_initialize(:failure_count_label) { + @failure_count_label = Gtk::Label.new("0") + @failure_count_label.set_justify(Gtk::JUSTIFY_LEFT) + } + end + + def error_count_label # :nodoc: + lazy_initialize(:error_count_label) { + @error_count_label = Gtk::Label.new("0") + @error_count_label.set_justify(Gtk::JUSTIFY_LEFT) + } + end + + def list_panel # :nodoc: + lazy_initialize(:list_panel) { + @list_panel = Gtk::HBox.new + @list_panel.border_width(10) + @list_panel.pack_start(list_scrolled_window, true, true, 0) + } + end + + def list_scrolled_window # :nodoc: + lazy_initialize(:list_scrolled_window) { + @list_scrolled_window = Gtk::ScrolledWindow.new + @list_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) + @list_scrolled_window.set_usize(@list_scrolled_window.allocation.width, 150) + @list_scrolled_window.add_with_viewport(fault_list) + } + end + + def fault_list # :nodoc: + lazy_initialize(:fault_list) { + @fault_list = Gtk::List.new + } + end + + def detail_panel # :nodoc: + lazy_initialize(:detail_panel) { + @detail_panel = Gtk::HBox.new + @detail_panel.border_width(10) + @detail_panel.pack_start(detail_scrolled_window, true, true, 0) + } + end + + def detail_scrolled_window # :nodoc: + lazy_initialize(:detail_scrolled_window) { + @detail_scrolled_window = Gtk::ScrolledWindow.new + @detail_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) + @detail_scrolled_window.set_usize(400, @detail_scrolled_window.allocation.height) + @detail_scrolled_window.add_with_viewport(outer_detail_sub_panel) + } + end + + def outer_detail_sub_panel # :nodoc: + lazy_initialize(:outer_detail_sub_panel) { + @outer_detail_sub_panel = Gtk::VBox.new + @outer_detail_sub_panel.pack_start(inner_detail_sub_panel, false, false, 0) + } + end + + def inner_detail_sub_panel # :nodoc: + lazy_initialize(:inner_detail_sub_panel) { + @inner_detail_sub_panel = Gtk::HBox.new + @inner_detail_sub_panel.pack_start(fault_detail_label, false, false, 0) + } + end + + def fault_detail_label # :nodoc: + lazy_initialize(:fault_detail_label) { + @fault_detail_label = EnhancedLabel.new("") + style = Gtk::Style.new + font = Gdk::Font.font_load("-*-Courier New-medium-r-normal--*-120-*-*-*-*-*-*") + begin + style.set_font(font) + rescue ArgumentError; end + @fault_detail_label.set_style(style) + @fault_detail_label.set_justify(Gtk::JUSTIFY_LEFT) + @fault_detail_label.set_line_wrap(false) + } + end + + def status_panel # :nodoc: + lazy_initialize(:status_panel) { + @status_panel = Gtk::HBox.new + @status_panel.border_width(10) + @status_panel.pack_start(status_entry, true, true, 0) + } + end + + def status_entry # :nodoc: + lazy_initialize(:status_entry) { + @status_entry = Gtk::Entry.new + @status_entry.set_editable(false) + } + end + + def lazy_initialize(symbol) # :nodoc: + if (!instance_eval("defined?(@#{symbol.to_s})")) + yield + end + return instance_eval("@" + symbol.to_s) + end + end + + class EnhancedProgressBar < Gtk::ProgressBar # :nodoc: all + def set_style(style) + super + hide + show + end + end + + class EnhancedLabel < Gtk::Label # :nodoc: all + def set_text(text) + super(text.gsub(/\n\t/, "\n" + (" " * 4))) + end + end + + class FaultListItem < Gtk::ListItem # :nodoc: all + attr_reader(:fault) + def initialize(fault) + super(fault.short_display) + @fault = fault + end + end + end + end + end +end + +if __FILE__ == $0 + Test::Unit::UI::GTK::TestRunner.start_command_line_test +end diff --git a/trunk/lib/test/unit/ui/gtk2/testrunner.rb b/trunk/lib/test/unit/ui/gtk2/testrunner.rb new file mode 100644 index 0000000000..128424cf34 --- /dev/null +++ b/trunk/lib/test/unit/ui/gtk2/testrunner.rb @@ -0,0 +1,465 @@ +#-- +# +# Author:: Kenta MURATA. +# Copyright:: Copyright (c) 2000-2002 Kenta MURATA. All rights reserved. +# License:: Ruby license. + +require "gtk2" +require "test/unit/ui/testrunnermediator" +require "test/unit/ui/testrunnerutilities" + +module Test + module Unit + module UI + module GTK2 # :nodoc: all + + Gtk.init + + class EnhancedLabel < Gtk::Label # :nodoc: all + def set_text(text) + super(text.gsub(/\n\t/, "\n ")) + end + end + + class FaultList < Gtk::TreeView # :nodoc: all + def initialize + @faults = [] + @model = Gtk::ListStore.new(String, String) + super(@model) + column = Gtk::TreeViewColumn.new + column.visible = false + append_column(column) + renderer = Gtk::CellRendererText.new + column = Gtk::TreeViewColumn.new("Failures", renderer, {:text => 1}) + append_column(column) + selection.mode = Gtk::SELECTION_SINGLE + set_rules_hint(true) + set_headers_visible(false) + end # def initialize + + def add_fault(fault) + @faults.push(fault) + iter = @model.append + iter.set_value(0, (@faults.length - 1).to_s) + iter.set_value(1, fault.short_display) + end # def add_fault(fault) + + def get_fault(iter) + @faults[iter.get_value(0).to_i] + end # def get_fault + + def clear + model.clear + end # def clear + end + + class TestRunner + extend TestRunnerUtilities + + def lazy_initialize(symbol) # :nodoc: + if !instance_eval("defined?(@#{symbol})") then + yield + end + return instance_eval("@#{symbol}") + end + private :lazy_initialize + + def status_entry # :nodoc: + lazy_initialize(:status_entry) do + @status_entry = Gtk::Entry.new + @status_entry.editable = false + end + end + private :status_entry + + def status_panel # :nodoc: + lazy_initialize(:status_panel) do + @status_panel = Gtk::HBox.new + @status_panel.border_width = 10 + @status_panel.pack_start(status_entry, true, true, 0) + end + end + private :status_panel + + def fault_detail_label # :nodoc: + lazy_initialize(:fault_detail_label) do + @fault_detail_label = EnhancedLabel.new("") +# style = Gtk::Style.new +# font = Gdk::Font. +# font_load("-*-Courier 10 Pitch-medium-r-normal--*-120-*-*-*-*-*-*") +# style.set_font(font) +# @fault_detail_label.style = style + @fault_detail_label.justify = Gtk::JUSTIFY_LEFT + @fault_detail_label.wrap = false + end + end + private :fault_detail_label + + def inner_detail_sub_panel # :nodoc: + lazy_initialize(:inner_detail_sub_panel) do + @inner_detail_sub_panel = Gtk::HBox.new + @inner_detail_sub_panel.pack_start(fault_detail_label, false, false, 0) + end + end + private :inner_detail_sub_panel + + def outer_detail_sub_panel # :nodoc: + lazy_initialize(:outer_detail_sub_panel) do + @outer_detail_sub_panel = Gtk::VBox.new + @outer_detail_sub_panel.pack_start(inner_detail_sub_panel, false, false, 0) + end + end + private :outer_detail_sub_panel + + def detail_scrolled_window # :nodoc: + lazy_initialize(:detail_scrolled_window) do + @detail_scrolled_window = Gtk::ScrolledWindow.new + @detail_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) + @detail_scrolled_window. + set_size_request(400, @detail_scrolled_window.allocation.height) + @detail_scrolled_window.add_with_viewport(outer_detail_sub_panel) + end + end + private :detail_scrolled_window + + def detail_panel # :nodoc: + lazy_initialize(:detail_panel) do + @detail_panel = Gtk::HBox.new + @detail_panel.border_width = 10 + @detail_panel.pack_start(detail_scrolled_window, true, true, 0) + end + end + private :detail_panel + + def fault_list # :nodoc: + lazy_initialize(:fault_list) do + @fault_list = FaultList.new + end + end + private :fault_list + + def list_scrolled_window # :nodoc: + lazy_initialize(:list_scrolled_window) do + @list_scrolled_window = Gtk::ScrolledWindow.new + @list_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) + @list_scrolled_window. + set_size_request(@list_scrolled_window.allocation.width, 150) + @list_scrolled_window.add_with_viewport(fault_list) + end + end + private :list_scrolled_window + + def list_panel # :nodoc: + lazy_initialize(:list_panel) do + @list_panel = Gtk::HBox.new + @list_panel.border_width = 10 + @list_panel.pack_start(list_scrolled_window, true, true, 0) + end + end + private :list_panel + + def error_count_label # :nodoc: + lazy_initialize(:error_count_label) do + @error_count_label = Gtk::Label.new("0") + @error_count_label.justify = Gtk::JUSTIFY_LEFT + end + end + private :error_count_label + + def failure_count_label # :nodoc: + lazy_initialize(:failure_count_label) do + @failure_count_label = Gtk::Label.new("0") + @failure_count_label.justify = Gtk::JUSTIFY_LEFT + end + end + private :failure_count_label + + def assertion_count_label # :nodoc: + lazy_initialize(:assertion_count_label) do + @assertion_count_label = Gtk::Label.new("0") + @assertion_count_label.justify = Gtk::JUSTIFY_LEFT + end + end + private :assertion_count_label + + def run_count_label # :nodoc: + lazy_initialize(:run_count_label) do + @run_count_label = Gtk::Label.new("0") + @run_count_label.justify = Gtk::JUSTIFY_LEFT + end + end + private :run_count_label + + def info_panel # :nodoc: + lazy_initialize(:info_panel) do + @info_panel = Gtk::HBox.new(false, 0) + @info_panel.border_width = 10 + @info_panel.pack_start(Gtk::Label.new("Runs:"), false, false, 0) + @info_panel.pack_start(run_count_label, true, false, 0) + @info_panel.pack_start(Gtk::Label.new("Assertions:"), false, false, 0) + @info_panel.pack_start(assertion_count_label, true, false, 0) + @info_panel.pack_start(Gtk::Label.new("Failures:"), false, false, 0) + @info_panel.pack_start(failure_count_label, true, false, 0) + @info_panel.pack_start(Gtk::Label.new("Errors:"), false, false, 0) + @info_panel.pack_start(error_count_label, true, false, 0) + end + end # def info_panel + private :info_panel + + def green_style # :nodoc: + lazy_initialize(:green_style) do + @green_style = Gtk::Style.new + @green_style.set_bg(Gtk::STATE_PRELIGHT, 0x0000, 0xFFFF, 0x0000) + end + end # def green_style + private :green_style + + def red_style # :nodoc: + lazy_initialize(:red_style) do + @red_style = Gtk::Style.new + @red_style.set_bg(Gtk::STATE_PRELIGHT, 0xFFFF, 0x0000, 0x0000) + end + end # def red_style + private :red_style + + def test_progress_bar # :nodoc: + lazy_initialize(:test_progress_bar) { + @test_progress_bar = Gtk::ProgressBar.new + @test_progress_bar.fraction = 0.0 + @test_progress_bar. + set_size_request(@test_progress_bar.allocation.width, + info_panel.size_request[1]) + @test_progress_bar.style = green_style + } + end # def test_progress_bar + private :test_progress_bar + + def progress_panel # :nodoc: + lazy_initialize(:progress_panel) do + @progress_panel = Gtk::HBox.new(false, 10) + @progress_panel.border_width = 10 + @progress_panel.pack_start(test_progress_bar, true, true, 0) + end + end # def progress_panel + + def run_button # :nodoc: + lazy_initialize(:run_button) do + @run_button = Gtk::Button.new("Run") + end + end # def run_button + + def suite_name_entry # :nodoc: + lazy_initialize(:suite_name_entry) do + @suite_name_entry = Gtk::Entry.new + @suite_name_entry.editable = false + end + end # def suite_name_entry + private :suite_name_entry + + def suite_panel # :nodoc: + lazy_initialize(:suite_panel) do + @suite_panel = Gtk::HBox.new(false, 10) + @suite_panel.border_width = 10 + @suite_panel.pack_start(Gtk::Label.new("Suite:"), false, false, 0) + @suite_panel.pack_start(suite_name_entry, true, true, 0) + @suite_panel.pack_start(run_button, false, false, 0) + end + end # def suite_panel + private :suite_panel + + def main_panel # :nodoc: + lazy_initialize(:main_panel) do + @main_panel = Gtk::VBox.new(false, 0) + @main_panel.pack_start(suite_panel, false, false, 0) + @main_panel.pack_start(progress_panel, false, false, 0) + @main_panel.pack_start(info_panel, false, false, 0) + @main_panel.pack_start(list_panel, false, false, 0) + @main_panel.pack_start(detail_panel, true, true, 0) + @main_panel.pack_start(status_panel, false, false, 0) + end + end # def main_panel + private :main_panel + + def main_window # :nodoc: + lazy_initialize(:main_window) do + @main_window = Gtk::Window.new(Gtk::Window::TOPLEVEL) + @main_window.set_title("Test::Unit TestRunner") + @main_window.set_default_size(800, 600) + @main_window.set_resizable(true) + @main_window.add(main_panel) + end + end # def main_window + private :main_window + + def setup_ui # :nodoc: + main_window.signal_connect("destroy", nil) { stop } + main_window.show_all + fault_list.selection.signal_connect("changed", nil) do + |selection, data| + if selection.selected then + show_fault(fault_list.get_fault(selection.selected)) + else + clear_fault + end + end + end # def setup_ui + private :setup_ui + + def output_status(string) # :nodoc: + status_entry.set_text(string) + end # def output_status(string) + private :output_status + + def finished(elapsed_time) # :nodoc: + test_progress_bar.fraction = 1.0 + output_status("Finished in #{elapsed_time} seconds") + end # def finished(elapsed_time) + private :finished + + def test_started(test_name) # :nodoc: + output_status("Running #{test_name}...") + end # def test_started(test_name) + private :test_started + + def started(result) # :nodoc: + @result = result + output_status("Started...") + end # def started(result) + private :started + + def test_finished(result) # :nodoc: + test_progress_bar.fraction += 1.0 / @count + end # def test_finished(result) + + def result_changed(result) # :nodoc: + run_count_label.label = result.run_count.to_s + assertion_count_label.label = result.assertion_count.to_s + failure_count_label.label = result.failure_count.to_s + error_count_label.label = result.error_count.to_s + end # def result_changed(result) + private :result_changed + + def clear_fault # :nodoc: + raw_show_fault("") + end # def clear_fault + private :clear_fault + + def raw_show_fault(string) # :nodoc: + fault_detail_label.set_text(string) + outer_detail_sub_panel.queue_resize + end # def raw_show_fault(string) + private :raw_show_fault + + def show_fault(fault) # :nodoc: + raw_show_fault(fault.long_display) + end # def show_fault(fault) + private :show_fault + + def add_fault(fault) # :nodoc: + if not @red then + test_progress_bar.style = red_style + @red = true + end + fault_list.add_fault(fault) + end # def add_fault(fault) + private :add_fault + + def reset_ui(count) # :nodoc: + test_progress_bar.style = green_style + test_progress_bar.fraction = 0.0 + @count = count + 1 + @red = false + + run_count_label.set_text("0") + assertion_count_label.set_text("0") + failure_count_label.set_text("0") + error_count_label.set_text("0") + + fault_list.clear + end # def reset_ui(count) + private :reset_ui + + def stop # :nodoc: + Gtk.main_quit + end # def stop + private :stop + + def run_test + @runner.raise(@restart_signal) + end + private :run_test + + def start_ui # :nodoc + @viewer.run + running = false + begin + loop do + if (running ^= true) + run_button.child.text = "Stop" + @mediator.run_suite + else + run_button.child.text = "Run" + @viewer.join + break + end + end + rescue @restart_signal + retry + rescue + end + end # def start_ui + private :start_ui + + def attach_to_mediator + run_button.signal_connect("clicked", nil) { run_test } + @mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui)) + @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started)) + @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished)) + @mediator.add_listener(TestResult::FAULT, &method(:add_fault)) + @mediator.add_listener(TestResult::CHANGED, &method(:result_changed)) + @mediator.add_listener(TestCase::STARTED, &method(:test_started)) + @mediator.add_listener(TestCase::FINISHED, &method(:test_finished)) + end # def attach_to_mediator + private :attach_to_mediator + + def setup_mediator + @mediator = TestRunnerMediator.new(@suite) + suite_name = @suite.to_s + if @suite.kind_of?(Module) then + suite_name = @suite.name + end + suite_name_entry.set_text(suite_name) + end # def setup_mediator + private :setup_mediator + + def start + setup_mediator + setup_ui + attach_to_mediator + start_ui + @result + end # def start + + def initialize(suite, output_level = NORMAL) + if suite.respond_to?(:suite) then + @suite = suite.suite + else + @suite = suite + end + @result = nil + + @runner = Thread.current + @restart_signal = Class.new(Exception) + @viewer = Thread.start do + @runner.join rescue @runner.run + Gtk.main + end + @viewer.join rescue nil # wait deadlock to handshake + end # def initialize(suite) + + end # class TestRunner + + end # module GTK2 + end # module UI + end # module Unit +end # module Test diff --git a/trunk/lib/test/unit/ui/testrunnermediator.rb b/trunk/lib/test/unit/ui/testrunnermediator.rb new file mode 100644 index 0000000000..07bb462cc0 --- /dev/null +++ b/trunk/lib/test/unit/ui/testrunnermediator.rb @@ -0,0 +1,68 @@ +#-- +# +# Author:: Nathaniel Talbott. +# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. +# License:: Ruby license. + +require 'test/unit' +require 'test/unit/util/observable' +require 'test/unit/testresult' + +module Test + module Unit + module UI # :nodoc: + + # Provides an interface to write any given UI against, + # hopefully making it easy to write new UIs. + class TestRunnerMediator + RESET = name + "::RESET" + STARTED = name + "::STARTED" + FINISHED = name + "::FINISHED" + + include Util::Observable + + # Creates a new TestRunnerMediator initialized to run + # the passed suite. + def initialize(suite) + @suite = suite + end + + # Runs the suite the TestRunnerMediator was created + # with. + def run_suite + Unit.run = true + begin_time = Time.now + notify_listeners(RESET, @suite.size) + result = create_result + notify_listeners(STARTED, result) + result_listener = result.add_listener(TestResult::CHANGED) do |updated_result| + notify_listeners(TestResult::CHANGED, updated_result) + end + + fault_listener = result.add_listener(TestResult::FAULT) do |fault| + notify_listeners(TestResult::FAULT, fault) + end + + @suite.run(result) do |channel, value| + notify_listeners(channel, value) + end + + result.remove_listener(TestResult::FAULT, fault_listener) + result.remove_listener(TestResult::CHANGED, result_listener) + end_time = Time.now + elapsed_time = end_time - begin_time + notify_listeners(FINISHED, elapsed_time) #"Finished in #{elapsed_time} seconds.") + return result + end + + private + # A factory method to create the result the mediator + # should run with. Can be overridden by subclasses if + # one wants to use a different result. + def create_result + return TestResult.new + end + end + end + end +end diff --git a/trunk/lib/test/unit/ui/testrunnerutilities.rb b/trunk/lib/test/unit/ui/testrunnerutilities.rb new file mode 100644 index 0000000000..70b885bd6c --- /dev/null +++ b/trunk/lib/test/unit/ui/testrunnerutilities.rb @@ -0,0 +1,46 @@ +#-- +# +# Author:: Nathaniel Talbott. +# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. +# License:: Ruby license. + +module Test + module Unit + module UI + + SILENT = 0 + PROGRESS_ONLY = 1 + NORMAL = 2 + VERBOSE = 3 + + # Provides some utilities common to most, if not all, + # TestRunners. + # + #-- + # + # Perhaps there ought to be a TestRunner superclass? There + # seems to be a decent amount of shared code between test + # runners. + + module TestRunnerUtilities + + # Creates a new TestRunner and runs the suite. + def run(suite, output_level=NORMAL) + return new(suite, output_level).start + end + + # Takes care of the ARGV parsing and suite + # determination necessary for running one of the + # TestRunners from the command line. + def start_command_line_test + if ARGV.empty? + puts "You should supply the name of a test suite file to the runner" + exit + end + require ARGV[0].gsub(/.+::/, '') + new(eval(ARGV[0])).start + end + end + end + end +end diff --git a/trunk/lib/test/unit/ui/tk/testrunner.rb b/trunk/lib/test/unit/ui/tk/testrunner.rb new file mode 100644 index 0000000000..4521b8e258 --- /dev/null +++ b/trunk/lib/test/unit/ui/tk/testrunner.rb @@ -0,0 +1,260 @@ +#-- +# +# Original Author:: Nathaniel Talbott. +# Author:: Kazuhiro NISHIYAMA. +# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. +# Copyright:: Copyright (c) 2003 Kazuhiro NISHIYAMA. All rights reserved. +# License:: Ruby license. + +require 'tk' +require 'test/unit/ui/testrunnermediator' +require 'test/unit/ui/testrunnerutilities' + +module Test + module Unit + module UI + module Tk # :nodoc: + + # Runs a Test::Unit::TestSuite in a Tk UI. Obviously, + # this one requires you to have Tk + # and the Ruby Tk extension installed. + class TestRunner + extend TestRunnerUtilities + + # Creates a new TestRunner for running the passed + # suite. + def initialize(suite, output_level = NORMAL) + if (suite.respond_to?(:suite)) + @suite = suite.suite + else + @suite = suite + end + @result = nil + + @red = false + @fault_detail_list = [] + @runner = Thread.current + @restart_signal = Class.new(Exception) + @viewer = Thread.start do + @runner.join rescue @runner.run + ::Tk.mainloop + end + @viewer.join rescue nil # wait deadlock to handshake + end + + # Begins the test run. + def start + setup_ui + setup_mediator + attach_to_mediator + start_ui + @result + end + + private + def setup_mediator # :nodoc: + @mediator = TestRunnerMediator.new(@suite) + suite_name = @suite.to_s + if ( @suite.kind_of?(Module) ) + suite_name = @suite.name + end + @suite_name_entry.value = suite_name + end + + def attach_to_mediator # :nodoc: + @run_button.command(method(:run_test)) + @fault_list.bind('ButtonPress-1', proc{|y| + fault = @fault_detail_list[@fault_list.nearest(y)] + if fault + show_fault(fault) + end + }, '%y') + @mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui)) + @mediator.add_listener(TestResult::FAULT, &method(:add_fault)) + @mediator.add_listener(TestResult::CHANGED, &method(:result_changed)) + @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started)) + @mediator.add_listener(TestCase::STARTED, &method(:test_started)) + @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished)) + end + + def run_test + @runner.raise(@restart_signal) + end + + def start_ui # :nodoc: + @viewer.run + running = false + begin + loop do + if (running ^= true) + @run_button.configure('text'=>'Stop') + @mediator.run_suite + else + @run_button.configure('text'=>'Run') + @viewer.join + break + end + end + rescue @restart_signal + retry + rescue + end + end + + def stop # :nodoc: + ::Tk.exit + end + + def reset_ui(count) # :nodoc: + @test_total_count = count.to_f + @test_progress_bar.configure('background'=>'green') + @test_progress_bar.place('relwidth'=>(count.zero? ? 0 : 0/count)) + @red = false + + @test_count_label.value = 0 + @assertion_count_label.value = 0 + @failure_count_label.value = 0 + @error_count_label.value = 0 + + @fault_list.delete(0, 'end') + @fault_detail_list = [] + clear_fault + end + + def add_fault(fault) # :nodoc: + if ( ! @red ) + @test_progress_bar.configure('background'=>'red') + @red = true + end + @fault_detail_list.push fault + @fault_list.insert('end', fault.short_display) + end + + def show_fault(fault) # :nodoc: + raw_show_fault(fault.long_display) + end + + def raw_show_fault(string) # :nodoc: + @detail_text.value = string + end + + def clear_fault # :nodoc: + raw_show_fault("") + end + + def result_changed(result) # :nodoc: + @test_count_label.value = result.run_count + @test_progress_bar.place('relwidth'=>result.run_count/@test_total_count) + @assertion_count_label.value = result.assertion_count + @failure_count_label.value = result.failure_count + @error_count_label.value = result.error_count + end + + def started(result) # :nodoc: + @result = result + output_status("Started...") + end + + def test_started(test_name) + output_status("Running #{test_name}...") + end + + def finished(elapsed_time) + output_status("Finished in #{elapsed_time} seconds") + end + + def output_status(string) # :nodoc: + @status_entry.value = string + end + + def setup_ui # :nodoc: + @status_entry = TkVariable.new + l = TkLabel.new(nil, 'textvariable'=>@status_entry, 'relief'=>'sunken') + l.pack('side'=>'bottom', 'fill'=>'x') + + suite_frame = TkFrame.new.pack('fill'=>'x') + + @run_button = TkButton.new(suite_frame, 'text'=>'Run') + @run_button.pack('side'=>'right') + + TkLabel.new(suite_frame, 'text'=>'Suite:').pack('side'=>'left') + @suite_name_entry = TkVariable.new + l = TkLabel.new(suite_frame, 'textvariable'=>@suite_name_entry, 'relief'=>'sunken') + l.pack('side'=>'left', 'fill'=>'x', 'expand'=>true) + + f = TkFrame.new(nil, 'relief'=>'sunken', 'borderwidth'=>3, 'height'=>20).pack('fill'=>'x', 'padx'=>1) + @test_progress_bar = TkFrame.new(f, 'background'=>'green').place('anchor'=>'nw', 'relwidth'=>0.0, 'relheight'=>1.0) + + info_frame = TkFrame.new.pack('fill'=>'x') + @test_count_label = create_count_label(info_frame, 'Tests:') + @assertion_count_label = create_count_label(info_frame, 'Assertions:') + @failure_count_label = create_count_label(info_frame, 'Failures:') + @error_count_label = create_count_label(info_frame, 'Errors:') + + if (::Tk.info('command', TkPanedWindow::TkCommandNames[0]) != "") + # use panedwindow + paned_frame = TkPanedWindow.new("orient"=>"vertical").pack('fill'=>'both', 'expand'=>true) + + fault_list_frame = TkFrame.new(paned_frame) + detail_frame = TkFrame.new(paned_frame) + + paned_frame.add(fault_list_frame, detail_frame) + else + # no panedwindow + paned_frame = nil + fault_list_frame = TkFrame.new.pack('fill'=>'both', 'expand'=>true) + detail_frame = TkFrame.new.pack('fill'=>'both', 'expand'=>true) + end + + TkGrid.rowconfigure(fault_list_frame, 0, 'weight'=>1, 'minsize'=>0) + TkGrid.columnconfigure(fault_list_frame, 0, 'weight'=>1, 'minsize'=>0) + + fault_scrollbar_y = TkScrollbar.new(fault_list_frame) + fault_scrollbar_x = TkScrollbar.new(fault_list_frame) + @fault_list = TkListbox.new(fault_list_frame) + @fault_list.yscrollbar(fault_scrollbar_y) + @fault_list.xscrollbar(fault_scrollbar_x) + + TkGrid.rowconfigure(detail_frame, 0, 'weight'=>1, 'minsize'=>0) + TkGrid.columnconfigure(detail_frame, 0, 'weight'=>1, 'minsize'=>0) + + ::Tk.grid(@fault_list, fault_scrollbar_y, 'sticky'=>'news') + ::Tk.grid(fault_scrollbar_x, 'sticky'=>'news') + + detail_scrollbar_y = TkScrollbar.new(detail_frame) + detail_scrollbar_x = TkScrollbar.new(detail_frame) + @detail_text = TkText.new(detail_frame, 'height'=>10, 'wrap'=>'none') { + bindtags(bindtags - [TkText]) + } + @detail_text.yscrollbar(detail_scrollbar_y) + @detail_text.xscrollbar(detail_scrollbar_x) + + ::Tk.grid(@detail_text, detail_scrollbar_y, 'sticky'=>'news') + ::Tk.grid(detail_scrollbar_x, 'sticky'=>'news') + + # rubber-style pane + if paned_frame + ::Tk.update + @height = paned_frame.winfo_height + paned_frame.bind('Configure', proc{|h| + paned_frame.sash_place(0, 0, paned_frame.sash_coord(0)[1] * h / @height) + @height = h + }, '%h') + end + end + + def create_count_label(parent, label) # :nodoc: + TkLabel.new(parent, 'text'=>label).pack('side'=>'left', 'expand'=>true) + v = TkVariable.new(0) + TkLabel.new(parent, 'textvariable'=>v).pack('side'=>'left', 'expand'=>true) + v + end + end + end + end + end +end + +if __FILE__ == $0 + Test::Unit::UI::Tk::TestRunner.start_command_line_test +end |