Skip to content

Commit

Permalink
Add ability to set status bar in TestRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Feb 10, 2017
1 parent fe8469e commit 8aae0bd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions autohotkey/procedures/example_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
# 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")
puts "continue after error"
end

def test_2
status_bar("Running test_2")
puts "Running test_2"
Cosmos::Test.puts "This test verifies requirement 2"
if $manual
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions demo/procedures/example_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ 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)
end

# 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
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions lib/cosmos/script/scripting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions lib/cosmos/tools/test_runner/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down

0 comments on commit 8aae0bd

Please sign in to comment.