From 9e10b9433989908f787cd75cecf0239a2a6bb7c9 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sat, 22 Mar 2014 11:36:42 +0100 Subject: [PATCH] cuke: test file options --- features/options/files.feature | 27 ++++++++++++++ features/options/help.feature | 54 ++++------------------------ features/options/invalid.feature | 3 +- features/options/version.feature | 18 +++++----- features/step_definitions/options.rb | 35 +++++++++++++----- features/support/hooks.rb | 18 +++++++++- 6 files changed, 88 insertions(+), 67 deletions(-) create mode 100644 features/options/files.feature diff --git a/features/options/files.feature b/features/options/files.feature new file mode 100644 index 000000000..91c12eb31 --- /dev/null +++ b/features/options/files.feature @@ -0,0 +1,27 @@ +@routing @options @files +Feature: Command line options: files + Normally when launching osrm-routed, it will keep running as a server until it's shut down. + For testing program options, the --trial option is used, which causes osrm-routed to quit + immediately after initialization. This makes testing easier and faster. + + The {base} part of the options to osrm-routed will be expanded to the actual base path of + the preprocessed file. + + Background: + Given the profile "testbot" + And the node map + | a | b | + And the ways + | nodes | + | ab | + And I preprocess data + + Scenario: Passing base file + When I run "osrm-routed {base}.osrm --trial" + Then stdout should contain /^\[info\] starting up engines/ + And stdout should contain /\d{1,2}\.\d{1,2}\.\d{1,2}/ + And stdout should contain /compiled at/ + And stdout should contain /^\[info\] loaded plugin: viaroute/ + And stdout should contain /^\[server\] trial run/ + And stdout should contain /^\[server\] shutdown completed/ + And it should exit with code 0 \ No newline at end of file diff --git a/features/options/help.feature b/features/options/help.feature index 3be47e9b7..55dd91a30 100644 --- a/features/options/help.feature +++ b/features/options/help.feature @@ -4,8 +4,8 @@ Feature: Command line options: help Background: Given the profile "testbot" - Scenario: No options should show help - When I run "osrm-routed" + Scenario Outline: Help + When I run "osrm-routed " Then stderr should be empty And stdout should contain "osrm-routed []:" And stdout should contain "Options:" @@ -27,48 +27,8 @@ Feature: Command line options: help And stdout should contain "--sharedmemory" And it should exit with code 0 - Scenario: Help, short - When I run "osrm-routed -h" - Then stderr should be empty - And stdout should contain "osrm-routed []:" - And stdout should contain "Options:" - And stdout should contain "--version" - And stdout should contain "--help" - And stdout should contain "--config" - And stdout should contain "--trial" - And stdout should contain "Configuration:" - And stdout should contain "--hsgrdata arg" - And stdout should contain "--nodesdata arg" - And stdout should contain "--edgesdata arg" - And stdout should contain "--ramindex arg" - And stdout should contain "--fileindex arg" - And stdout should contain "--namesdata arg" - And stdout should contain "--timestamp arg" - And stdout should contain "--ip" - And stdout should contain "--port" - And stdout should contain "--threads" - And stdout should contain "--sharedmemory" - And it should exit with code 0 - - Scenario: Help, long - When I run "osrm-routed --help" - Then stderr should be empty - And stdout should contain "osrm-routed []:" - And stdout should contain "Options:" - And stdout should contain "--version" - And stdout should contain "--help" - And stdout should contain "--config" - And stdout should contain "--trial" - And stdout should contain "Configuration:" - And stdout should contain "--hsgrdata arg" - And stdout should contain "--nodesdata arg" - And stdout should contain "--edgesdata arg" - And stdout should contain "--ramindex arg" - And stdout should contain "--fileindex arg" - And stdout should contain "--namesdata arg" - And stdout should contain "--timestamp arg" - And stdout should contain "--ip" - And stdout should contain "--port" - And stdout should contain "--threads" - And stdout should contain "--sharedmemory" - And it should exit with code 0 + Examples: + | program_options | + | | + | -h | + | --help | \ No newline at end of file diff --git a/features/options/invalid.feature b/features/options/invalid.feature index 02bda69c0..7d7ef5cf4 100644 --- a/features/options/invalid.feature +++ b/features/options/invalid.feature @@ -16,5 +16,4 @@ Feature: Command line options: invalid options Then stdout should contain "over-the-rainbow.osrm" And stderr should contain "exception" And stderr should contain "does not exist" - And it should exit with code 255 - \ No newline at end of file + And it should exit with code 255 \ No newline at end of file diff --git a/features/options/version.feature b/features/options/version.feature index 085eb331e..6b2f27102 100644 --- a/features/options/version.feature +++ b/features/options/version.feature @@ -3,15 +3,15 @@ Feature: Command line options: version Background: Given the profile "testbot" - - Scenario: Version, short - When I run "osrm-routed -v" + + Scenario Outline: Version + When I run "osrm-routed " Then stderr should be empty - And stdout should contain " v0." + And stdout should contain 1 line + And stdout should contain /v\d{1,2}\.\d{1,2}\.\d{1,2}/ And it should exit with code 0 - Scenario: Version, long - When I run "osrm-routed --version" - Then stderr should be empty - And stdout should contain " v0." - And it should exit with code 0 \ No newline at end of file + Examples: + | program_options | + | -v | + | --version | diff --git a/features/step_definitions/options.rb b/features/step_definitions/options.rb index 3e72d65ff..f1b1694e5 100644 --- a/features/step_definitions/options.rb +++ b/features/step_definitions/options.rb @@ -1,16 +1,21 @@ When(/^I run "osrm\-routed\s?(.*?)"$/) do |options| Dir.chdir TEST_FOLDER do + if options.include? '{base}' + # expand {base} to base path of preprocessed data file + raise "*** Cannot expand {base} without a preprocessed file." unless @osm_file + options_expanded = options.gsub "{base}", "#{@osm_file}" + else + options_expanded = options + end + begin Timeout.timeout(1) do - @stdout = `#{BIN_PATH}/osrm-routed #{options} 2>error.log` + @stdout = `#{BIN_PATH}/osrm-routed #{options_expanded} 2>error.log` @stderr = File.read 'error.log' @exit_code = $?.exitstatus end - rescue - # TODO would be easy to handle there was an option to make osrm exit right after completing initialization - @stdout = nil - @stderr = nil - @exit_code = nil + rescue Timeout::Error + raise "*** osrm-routed didn't quit. Maybe the --trial option wasn't used?" end end end @@ -20,11 +25,21 @@ Then /^it should exit with code (\d+)$/ do |code| end Then /^stdout should contain "(.*?)"$/ do |str| - @stdout.include?(str).should == true + @stdout.should include(str) end Then /^stderr should contain "(.*?)"$/ do |str| - @stderr.include?(str).should == true + @stderr.should include(str) +end + +Then(/^stdout should contain \/(.*)\/$/) do |regex_str| + regex = Regexp.new regex_str + @stdout.should =~ regex +end + +Then(/^stderr should contain \/(.*)\/$/) do |regex_str| + regex = Regexp.new regex_str + @stderr.should =~ regex end Then /^stdout should be empty$/ do @@ -34,3 +49,7 @@ end Then /^stderr should be empty$/ do @stderr.should == "" end + +Then /^stdout should contain (\d+) lines?$/ do |lines| + @stdout.lines.count.should == lines.to_i +end diff --git a/features/support/hooks.rb b/features/support/hooks.rb index e3b6df0e5..4c58a1750 100644 --- a/features/support/hooks.rb +++ b/features/support/hooks.rb @@ -2,7 +2,23 @@ STRESS_TIMEOUT = 300 Before do |scenario| - @scenario_title = scenario.title + # feature name + case scenario + when Cucumber::Ast::Scenario + @feature_name = scenario.feature.name + when Cucumber::Ast::OutlineTable::ExampleRow + @feature_name = scenario.scenario_outline.feature.name + end + + # scenario name + case scenario + when Cucumber::Ast::Scenario + @scenario_title = scenario.name + when Cucumber::Ast::OutlineTable::ExampleRow + @scenario_title = scenario.scenario_outline.name + end + + @scenario_time = Time.now.strftime("%Y-%m-%dT%H:%m:%SZ") reset_data @has_logged_preprocess_info = false