diff --git a/features/options/version.feature b/features/options/extract.feature similarity index 82% rename from features/options/version.feature rename to features/options/extract.feature index 9ad933924..1582888b7 100644 --- a/features/options/version.feature +++ b/features/options/extract.feature @@ -1,5 +1,5 @@ -@routing @options -Feature: Command line options: version +@extract @options +Feature: osrm-extract command line options: version # the regex will match these two formats: # v0.3.7.0 # this is the normal format when you build from a git clone # -128-NOTFOUND # if you build from a shallow clone (used on Travis) @@ -7,14 +7,14 @@ Feature: Command line options: version Background: Given the profile "testbot" - Scenario: Version, short + Scenario: osrm-extract - Version, short When I run "osrm-routed --v" Then stderr should be empty And stdout should contain 1 line And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ And it should exit with code 0 - Scenario: Version, long + Scenario: osrm-extract - Version, long When I run "osrm-routed --version" Then stderr should be empty And stdout should contain 1 line diff --git a/features/options/extract/files.feature b/features/options/extract/files.feature new file mode 100644 index 000000000..9b7a05408 --- /dev/null +++ b/features/options/extract/files.feature @@ -0,0 +1,31 @@ +@extract @options @files +Feature: osrm-extract command line options: files +# expansions: +# {base} => path to current input file +# {profile} => path to current profile script + + Background: + Given the profile "testbot" + And the node map + | a | b | + And the ways + | nodes | + | ab | + And the data has been saved to disk + + Scenario: osrm-extract - Passing base file + When I run "osrm-extract {base}.osm --profile {profile}" + Then stderr should be empty + And it should exit with code 0 + + Scenario: osrm-extract - Order of options should not matter + When I run "osrm-extract --profile {profile} {base}.osm" + Then stderr should be empty + And it should exit with code 0 + + @todo + Scenario: osrm-extract - Missing input file + When I run "osrm-extract over-the-rainbow.osrm --profile {profile}" + And stderr should contain "over-the-rainbow.osrm" + And stderr should contain "not found" + And it should exit with code 1 diff --git a/features/options/extract/help.feature b/features/options/extract/help.feature new file mode 100644 index 000000000..3a40c108d --- /dev/null +++ b/features/options/extract/help.feature @@ -0,0 +1,48 @@ +@extract @options @help +Feature: osrm-extract command line options: help + + Background: + Given the profile "testbot" + + @todo + Scenario: osrm-extract - Help should be shown when no options are passed + When I run "osrm-extract" + Then stderr should be empty + And stdout should contain "osrm-extract [options]:" + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "--config" + And stdout should contain "Configuration:" + And stdout should contain "--profile" + And stdout should contain "--threads" + And stdout should contain 12 lines + And it should exit with code 0 + + Scenario: osrm-extract - Help, short + When I run "osrm-extract -h" + Then stderr should be empty + And stdout should contain "osrm-extract [options]:" + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "--config" + And stdout should contain "Configuration:" + And stdout should contain "--profile" + And stdout should contain "--threads" + And stdout should contain 12 lines + And it should exit with code 0 + + Scenario: osrm-extract - Help, long + When I run "osrm-extract --help" + Then stderr should be empty + And stdout should contain "osrm-extract [options]:" + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "--config" + And stdout should contain "Configuration:" + And stdout should contain "--profile" + And stdout should contain "--threads" + And stdout should contain 12 lines + And it should exit with code 0 \ No newline at end of file diff --git a/features/options/extract/invalid.feature b/features/options/extract/invalid.feature new file mode 100644 index 000000000..2fd4b7509 --- /dev/null +++ b/features/options/extract/invalid.feature @@ -0,0 +1,13 @@ +@extract @options @invalid +Feature: osrm-extract command line options: invalid options + + Background: + Given the profile "testbot" + + @todo + Scenario: osrm-extract - Non-existing option + When I run "osrm-extract --fly-me-to-the-moon" + Then stdout should be empty + And stderr should contain "exception" + And stderr should contain "fly-me-to-the-moon" + And it should exit with code 1 diff --git a/features/options/extract/version.feature b/features/options/extract/version.feature new file mode 100644 index 000000000..0dd5f6588 --- /dev/null +++ b/features/options/extract/version.feature @@ -0,0 +1,22 @@ +@extract @options @version +Feature: osrm-extract command line options: version +# the regex will match these two formats: +# v0.3.7.0 # this is the normal format when you build from a git clone +# -128-NOTFOUND # if you build from a shallow clone (used on Travis) + + Background: + Given the profile "testbot" + + Scenario: osrm-extract - Version, short + When I run "osrm-extract --v" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit with code 0 + + Scenario: osrm-extract - Version, long + When I run "osrm-extract --version" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit with code 0 diff --git a/features/options/prepare/files.feature b/features/options/prepare/files.feature new file mode 100644 index 000000000..21fd390c7 --- /dev/null +++ b/features/options/prepare/files.feature @@ -0,0 +1,35 @@ +@prepare @options @files +Feature: osrm-prepare command line options: files +# expansions: +# {base} => path to current input file +# {profile} => path to current profile script + + Background: + Given the profile "testbot" + And the node map + | a | b | + And the ways + | nodes | + | ab | + And the data has been extracted + + Scenario: osrm-prepare - Passing base file + When I run "osrm-extract {base}.osm --profile {profile}" + Then stderr should be empty + And it should exit with code 0 + When I run "osrm-prepare {base}.osrm --profile {profile}" + Then stderr should be empty + And it should exit with code 0 + + @todo + Scenario: osrm-prepare - Order of options should not matter + When I run "osrm-prepare --profile {profile} {base}.osm" + Then stderr should be empty + And it should exit with code 0 + + @todo + Scenario: osrm-prepare - Missing input file + When I run "osrm-prepare over-the-rainbow.osrm --profile {profile}" + And stderr should contain "over-the-rainbow.osrm" + And stderr should contain "not found" + And it should exit with code 1 diff --git a/features/options/prepare/help.feature b/features/options/prepare/help.feature new file mode 100644 index 000000000..ea7ae1850 --- /dev/null +++ b/features/options/prepare/help.feature @@ -0,0 +1,51 @@ +@prepare @options @help +Feature: osrm-prepare command line options: help + + Background: + Given the profile "testbot" + + @todo + Scenario: osrm-prepare - Help should be shown when no options are passed + When I run "osrm-prepare" + Then stderr should be empty + And stdout should contain "osrm-prepare [options]:" + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "--config" + And stdout should contain "Configuration:" + And stdout should contain "--restrictions" + And stdout should contain "--profile" + And stdout should contain "--threads" + And stdout should contain 15 lines + And it should exit with code 0 + + Scenario: osrm-prepare - Help, short + When I run "osrm-prepare -h" + Then stderr should be empty + And stdout should contain "osrm-prepare [options]:" + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "--config" + And stdout should contain "Configuration:" + And stdout should contain "--restrictions" + And stdout should contain "--profile" + And stdout should contain "--threads" + And stdout should contain 15 lines + And it should exit with code 0 + + Scenario: osrm-prepare - Help, long + When I run "osrm-prepare --help" + Then stderr should be empty + And stdout should contain "osrm-prepare [options]:" + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "--config" + And stdout should contain "Configuration:" + And stdout should contain "--restrictions" + And stdout should contain "--profile" + And stdout should contain "--threads" + And stdout should contain 15 lines + And it should exit with code 0 \ No newline at end of file diff --git a/features/options/prepare/invalid.feature b/features/options/prepare/invalid.feature new file mode 100644 index 000000000..a17606613 --- /dev/null +++ b/features/options/prepare/invalid.feature @@ -0,0 +1,13 @@ +@prepare @options @invalid +Feature: osrm-prepare command line options: invalid options + + Background: + Given the profile "testbot" + + @todo + Scenario: osrm-prepare - Non-existing option + When I run "osrm-prepare --fly-me-to-the-moon" + Then stdout should be empty + And stderr should contain "exception" + And stderr should contain "fly-me-to-the-moon" + And it should exit with code 1 \ No newline at end of file diff --git a/features/options/prepare/version.feature b/features/options/prepare/version.feature new file mode 100644 index 000000000..7a821c626 --- /dev/null +++ b/features/options/prepare/version.feature @@ -0,0 +1,22 @@ +@prepare @options @version +Feature: osrm-prepare command line options: version +# the regex will match these two formats: +# v0.3.7.0 # this is the normal format when you build from a git clone +# -128-NOTFOUND # if you build from a shallow clone (used on Travis) + + Background: + Given the profile "testbot" + + Scenario: osrm-prepare - Version, short + When I run "osrm-prepare --v" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit with code 0 + + Scenario: osrm-prepare - Version, long + When I run "osrm-prepare --version" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit with code 0 diff --git a/features/options/files.feature b/features/options/routed/files.feature similarity index 83% rename from features/options/files.feature rename to features/options/routed/files.feature index 41252238e..716b2a4d8 100644 --- a/features/options/files.feature +++ b/features/options/routed/files.feature @@ -1,5 +1,5 @@ -@routing @options @files -Feature: Command line options: files +@routed @options @files +Feature: osrm-routed 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. @@ -14,9 +14,9 @@ Feature: Command line options: files And the ways | nodes | | ab | - And I preprocess data + And the data has been prepared - Scenario: Passing base file + Scenario: osrm-routed - 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}/ @@ -24,4 +24,4 @@ Feature: Command line options: files And stdout should contain /^\[info\] loaded plugin: viaroute/ And stdout should contain /^\[info\] trial run/ And stdout should contain /^\[info\] shutdown completed/ - And it should exit with code 0 + And it should exit with code 0 \ No newline at end of file diff --git a/features/options/help.feature b/features/options/routed/help.feature similarity index 89% rename from features/options/help.feature rename to features/options/routed/help.feature index 40ec0177e..3feb95746 100644 --- a/features/options/help.feature +++ b/features/options/routed/help.feature @@ -1,10 +1,10 @@ -@routing @options -Feature: Command line options: help +@routed @options @help +Feature: osrm-routed command line options: help Background: Given the profile "testbot" - Scenario: Help should be shown when no options are passed + Scenario: osrm-routed - Help should be shown when no options are passed When I run "osrm-routed" Then stderr should be empty And stdout should contain "osrm-routed []:" @@ -25,9 +25,10 @@ Feature: Command line options: help And stdout should contain "--port" And stdout should contain "--threads" And stdout should contain "--sharedmemory" + And stdout should contain 21 lines And it should exit with code 0 - Scenario: Help, short + Scenario: osrm-routed - Help, short When I run "osrm-routed -h" Then stderr should be empty And stdout should contain "osrm-routed []:" @@ -48,9 +49,10 @@ Feature: Command line options: help And stdout should contain "--port" And stdout should contain "--threads" And stdout should contain "--sharedmemory" + And stdout should contain 21 lines And it should exit with code 0 - Scenario: Help, long + Scenario: osrm-routed - Help, long When I run "osrm-routed --help" Then stderr should be empty And stdout should contain "osrm-routed []:" @@ -71,4 +73,5 @@ Feature: Command line options: help And stdout should contain "--port" And stdout should contain "--threads" And stdout should contain "--sharedmemory" + And stdout should contain 21 lines And it should exit with code 0 \ No newline at end of file diff --git a/features/options/invalid.feature b/features/options/routed/invalid.feature similarity index 75% rename from features/options/invalid.feature rename to features/options/routed/invalid.feature index b1ea4b420..a25a039c0 100644 --- a/features/options/invalid.feature +++ b/features/options/routed/invalid.feature @@ -1,17 +1,17 @@ -@routing @options -Feature: Command line options: invalid options +@routed @options @invalid +Feature: osrm-routed command line options: invalid options Background: Given the profile "testbot" - Scenario: Non-existing option + Scenario: osrm-routed - Non-existing option When I run "osrm-routed --fly-me-to-the-moon" Then stdout should be empty And stderr should contain "exception" And stderr should contain "fly-me-to-the-moon" And it should exit with code 1 - Scenario: Missing file + Scenario: osrm-routed - Missing file When I run "osrm-routed over-the-rainbow.osrm" Then stdout should contain "over-the-rainbow.osrm" And stderr should contain "exception" diff --git a/features/options/routed/version.feature b/features/options/routed/version.feature new file mode 100644 index 000000000..b544e36e6 --- /dev/null +++ b/features/options/routed/version.feature @@ -0,0 +1,22 @@ +@routed @options @version +Feature: osrm-routed command line options: version +# the regex will match these two formats: +# v0.3.7.0 # this is the normal format when you build from a git clone +# -128-NOTFOUND # if you build from a shallow clone (used on Travis) + + Background: + Given the profile "testbot" + + Scenario: osrm-routed - Version, short + When I run "osrm-routed --v" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit with code 0 + + Scenario: osrm-routed - Version, long + When I run "osrm-routed --version" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit with code 0 diff --git a/features/step_definitions/data.rb b/features/step_definitions/data.rb index d6cea41da..e0985a4b1 100644 --- a/features/step_definitions/data.rb +++ b/features/step_definitions/data.rb @@ -133,3 +133,28 @@ Given /^the input file ([^"]*)$/ do |file| raise "*** Input file must in .osm format" unless File.extname(file)=='.osm' @osm_str = File.read file end + +Given /^the data has been saved to disk$/ do + begin + write_input_data + rescue OSRMError => e + @process_error = e + end +end + +Given /^the data has been extracted$/ do + begin + write_input_data + extract_data unless extracted? + rescue OSRMError => e + @process_error = e + end +end + +Given /^the data has been prepared$/ do + begin + reprocess + rescue OSRMError => e + @process_error = e + end +end diff --git a/features/step_definitions/options.rb b/features/step_definitions/options.rb index 6b349f8b5..ac3bc9983 100644 --- a/features/step_definitions/options.rb +++ b/features/step_definitions/options.rb @@ -1,25 +1,19 @@ 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_expanded} 2>error.log` - @stderr = File.read 'error.log' - @exit_code = $?.exitstatus - end - rescue Timeout::Error - raise "*** osrm-routed didn't quit. Maybe the --trial option wasn't used?" - end + begin + Timeout.timeout(1) { run_bin 'osrm-routed', options } + rescue Timeout::Error + raise "*** osrm-routed didn't quit. Maybe the --trial option wasn't used?" end end +When(/^I run "osrm\-extract\s?(.*?)"$/) do |options| + run_bin 'osrm-extract', options +end + +When(/^I run "osrm\-prepare\s?(.*?)"$/) do |options| + run_bin 'osrm-prepare', options +end + Then /^it should exit with code (\d+)$/ do |code| @exit_code.should == code.to_i end diff --git a/features/step_definitions/requests.rb b/features/step_definitions/requests.rb index e6bdcae84..b40551f32 100644 --- a/features/step_definitions/requests.rb +++ b/features/step_definitions/requests.rb @@ -29,16 +29,8 @@ Then /^response should be a well-formed route$/ do @json['via_indices'].class.should == Array end -When /^I preprocess data$/ do - begin - reprocess - rescue OSRMError => e - @process_error = e - end -end - Then /^"([^"]*)" should return code (\d+)$/ do |binary, code| @process_error.is_a?(OSRMError).should == true @process_error.process.should == binary @process_error.code.to_i.should == code.to_i -end +end \ No newline at end of file diff --git a/features/support/data.rb b/features/support/data.rb index 1d9522994..58d5de759 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -2,20 +2,6 @@ require 'OSM/objects' #osmlib gem require 'OSM/Database' require 'builder' -OSM_USER = 'osrm' -OSM_GENERATOR = 'osrm-test' -OSM_UID = 1 -TEST_FOLDER = 'test' -DATA_FOLDER = 'cache' -OSM_TIMESTAMP = '2000-00-00T00:00:00Z' -DEFAULT_SPEEDPROFILE = 'bicycle' -WAY_SPACING = 100 -DEFAULT_GRID_SIZE = 100 #meters -PROFILES_PATH = '../profiles' -BIN_PATH = '../build' -DEFAULT_INPUT_FORMAT = 'osm' -DEFAULT_ORIGIN = [1,1] - class Location attr_accessor :lon,:lat @@ -252,30 +238,44 @@ def write_timestamp File.open( "#{@osm_file}.osrm.timestamp", 'w') {|f| f.write(OSM_TIMESTAMP) } end -def reprocess +def pbf? + input_format=='pbf' +end +def write_input_data Dir.chdir TEST_FOLDER do - use_pbf = (input_format=='pbf') write_osm write_timestamp - convert_osm_to_pbf if use_pbf - unless extracted? - log_preprocess_info - log "== Extracting #{@osm_file}.osm...", :preprocess - unless system "#{BIN_PATH}/osrm-extract #{@osm_file}.osm#{'.pbf' if use_pbf} --profile #{PROFILES_PATH}/#{@profile}.lua 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}" - log "*** Exited with code #{$?.exitstatus}.", :preprocess - raise ExtractError.new $?.exitstatus, "osrm-extract exited with code #{$?.exitstatus}." - end - log '', :preprocess - end - unless prepared? - log_preprocess_info - log "== Preparing #{@osm_file}.osm...", :preprocess - unless system "#{BIN_PATH}/osrm-prepare #{@osm_file}.osrm --profile #{PROFILES_PATH}/#{@profile}.lua 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}" - log "*** Exited with code #{$?.exitstatus}.", :preprocess - raise PrepareError.new $?.exitstatus, "osrm-prepare exited with code #{$?.exitstatus}." - end - log '', :preprocess - end - log_preprocess_done + convert_osm_to_pbf if pbf? end end + +def extract_data + Dir.chdir TEST_FOLDER do + log_preprocess_info + log "== Extracting #{@osm_file}.osm...", :preprocess + unless system "#{BIN_PATH}/osrm-extract #{@osm_file}.osm#{'.pbf' if pbf?} --profile #{PROFILES_PATH}/#{@profile}.lua 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}" + log "*** Exited with code #{$?.exitstatus}.", :preprocess + raise ExtractError.new $?.exitstatus, "osrm-extract exited with code #{$?.exitstatus}." + end + log '', :preprocess + end +end + +def prepare_data + Dir.chdir TEST_FOLDER do + log_preprocess_info + log "== Preparing #{@osm_file}.osm...", :preprocess + unless system "#{BIN_PATH}/osrm-prepare #{@osm_file}.osrm --profile #{PROFILES_PATH}/#{@profile}.lua 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}" + log "*** Exited with code #{$?.exitstatus}.", :preprocess + raise PrepareError.new $?.exitstatus, "osrm-prepare exited with code #{$?.exitstatus}." + end + log '', :preprocess + end +end + +def reprocess + write_input_data + extract_data unless extracted? + prepare_data unless prepared? + log_preprocess_done +end diff --git a/features/support/env.rb b/features/support/env.rb index 2cbc4e46d..b1eeb64b6 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -3,6 +3,22 @@ require 'rspec/expectations' DEFAULT_PORT = 5000 DEFAULT_TIMEOUT = 2 +ROOT_FOLDER = Dir.pwd +OSM_USER = 'osrm' +OSM_GENERATOR = 'osrm-test' +OSM_UID = 1 +TEST_FOLDER = File.join ROOT_FOLDER, 'test' +DATA_FOLDER = 'cache' +OSM_TIMESTAMP = '2000-00-00T00:00:00Z' +DEFAULT_SPEEDPROFILE = 'bicycle' +WAY_SPACING = 100 +DEFAULT_GRID_SIZE = 100 #meters +PROFILES_PATH = File.join ROOT_FOLDER, 'profiles' +BIN_PATH = File.join ROOT_FOLDER, 'build' +DEFAULT_INPUT_FORMAT = 'osm' +DEFAULT_ORIGIN = [1,1] + + puts "Ruby version #{RUBY_VERSION}" unless RUBY_VERSION.to_f >= 1.9 raise "*** Please upgrade to Ruby 1.9.x to run the OSRM cucumber tests" @@ -24,6 +40,10 @@ else puts "Using default timeout #{OSRM_TIMEOUT}" end +unless File.exists? TEST_FOLDER + raise "*** Test folder #{TEST_FOLDER} doesn't exist." +end + AfterConfiguration do |config| clear_log_files diff --git a/features/support/run.rb b/features/support/run.rb new file mode 100644 index 000000000..236c873d9 --- /dev/null +++ b/features/support/run.rb @@ -0,0 +1,18 @@ +def run_bin bin, options + Dir.chdir TEST_FOLDER do + opt = options.dup + + if opt.include? '{base}' + raise "*** {base} is missing" unless @osm_file + opt.gsub! "{base}", "#{@osm_file}" + end + + if opt.include? '{profile}' + opt.gsub! "{profile}", "#{PROFILES_PATH}/#{@profile}.lua" + end + + @stdout = `#{BIN_PATH}/#{bin} #{opt} 2>error.log` + @stderr = File.read 'error.log' + @exit_code = $?.exitstatus + end +end \ No newline at end of file diff --git a/features/testbot/bad.feature b/features/testbot/bad.feature index 98f5dbef2..f28b07295 100644 --- a/features/testbot/bad.feature +++ b/features/testbot/bad.feature @@ -11,7 +11,7 @@ Feature: Handle bad data in a graceful manner Given the ways | nodes | - When I preprocess data + When the data has been prepared Then "osrm-extract" should return code 255 Scenario: Only dead-end oneways diff --git a/features/testbot/protobuffer.feature b/features/testbot/protobuffer.feature index 016a233be..7d8329ad9 100644 --- a/features/testbot/protobuffer.feature +++ b/features/testbot/protobuffer.feature @@ -87,7 +87,7 @@ Feature: Importing protobuffer (.pbf) format Given the ways | nodes | - When I preprocess data + When the data has been prepared Then "osrm-extract" should return code 255