From 8aae0bd078fb5867019b8c8a0e21506e9024e4d3 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Mon, 28 Dec 2015 16:18:40 -0700 Subject: [PATCH] Add ability to set status bar in TestRunner --- autohotkey/procedures/example_test.rb | 4 ++++ demo/procedures/example_test.rb | 5 +++++ lib/cosmos/script/scripting.rb | 9 ++++----- lib/cosmos/tools/test_runner/test_runner.rb | 11 +++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/autohotkey/procedures/example_test.rb b/autohotkey/procedures/example_test.rb index b9b4a525e..34405882c 100644 --- a/autohotkey/procedures/example_test.rb +++ b/autohotkey/procedures/example_test.rb @@ -6,10 +6,12 @@ # with 'test_' to be picked up by TestRunner. class ExampleTest < Cosmos::Test def setup + status_bar("setup") puts "Running ExampleTest setup" end def test_case_with_long_name_1 + status_bar("Running test_1") puts "Running test_1" Cosmos::Test.puts "This test verifies requirement 1" check_expression("false == true") @@ -17,6 +19,7 @@ def test_case_with_long_name_1 end def test_2 + status_bar("Running test_2") puts "Running test_2" Cosmos::Test.puts "This test verifies requirement 2" if $manual @@ -32,6 +35,7 @@ def test_3xx # Teardown the test case by doing other stuff def teardown + status_bar("teardown") puts "Running ExampleTest teardown" end diff --git a/demo/procedures/example_test.rb b/demo/procedures/example_test.rb index 29619012a..32bfea666 100644 --- a/demo/procedures/example_test.rb +++ b/demo/procedures/example_test.rb @@ -11,12 +11,14 @@ def initialize # Setup the test case by doing stuff def setup + status_bar("setup") puts "Running #{Cosmos::Test.current_test_suite}:#{Cosmos::Test.current_test}:#{Cosmos::Test.current_test_case}" wait(2) end # test_1 verifies requirement 1 def test_case_with_long_name_1 + status_bar("test_case_with_long_name_1") puts "Running #{Cosmos::Test.current_test_suite}:#{Cosmos::Test.current_test}:#{Cosmos::Test.current_test_case}" Cosmos::Test.puts "This test verifies requirement 1" wait(2) @@ -24,6 +26,7 @@ def test_case_with_long_name_1 # test_2 verifies requirement 2 def test_2 + status_bar("test_2") puts "Running #{Cosmos::Test.current_test_suite}:#{Cosmos::Test.current_test}:#{Cosmos::Test.current_test_case}" Cosmos::Test.puts "This test verifies requirement 2" if $manual @@ -35,12 +38,14 @@ def test_2 end def test_3xx + status_bar("test_3xx") puts "Running #{Cosmos::Test.current_test_suite}:#{Cosmos::Test.current_test}:#{Cosmos::Test.current_test_case}" wait 1 end # Teardown the test case by doing other stuff def teardown + status_bar("teardown") puts "Running #{Cosmos::Test.current_test_suite}:#{Cosmos::Test.current_test}:#{Cosmos::Test.current_test_case}" wait(2) end diff --git a/lib/cosmos/script/scripting.rb b/lib/cosmos/script/scripting.rb index 56d6d16ff..094350d23 100644 --- a/lib/cosmos/script/scripting.rb +++ b/lib/cosmos/script/scripting.rb @@ -23,11 +23,10 @@ def play_wav_file(wav_filename) end def status_bar(message) - if defined? ScriptRunner - script_runner = nil - ObjectSpace.each_object {|object| if ScriptRunner === object then script_runner = object; break; end} - script_runner.script_set_status(message) if script_runner - end + script_runner = ObjectSpace.find(ScriptRunner) if defined? ScriptRunner + script_runner.script_set_status(message) if script_runner + test_runner = ObjectSpace.find(TestRunner) if defined? TestRunner + test_runner.script_set_status(message) if test_runner end def ask_string(question, blank_or_default = false, password = false) diff --git a/lib/cosmos/tools/test_runner/test_runner.rb b/lib/cosmos/tools/test_runner/test_runner.rb index ac227a2ac..d335f5050 100644 --- a/lib/cosmos/tools/test_runner/test_runner.rb +++ b/lib/cosmos/tools/test_runner/test_runner.rb @@ -394,6 +394,17 @@ def self.start_teardown(test_suite_class, test_class = nil) end end + # Called by cosmos_script_module by the user calling the status_bar scripting method + def script_set_status(message) + Qt.execute_in_main_thread(true) do + # Check for self.disposed? to work around crash when using SimpleCov + unless self.disposed? + status_bar = statusBar() + status_bar.showMessage(message) + end + end + end + def continue_without_pausing_on_errors? if !@pause_on_error.isChecked() msg = ""