diff options
Diffstat (limited to 't/60-bin-efa.t')
-rw-r--r-- | t/60-bin-efa.t | 177 |
1 files changed, 97 insertions, 80 deletions
diff --git a/t/60-bin-efa.t b/t/60-bin-efa.t index d14c399..6bb9f5d 100644 --- a/t/60-bin-efa.t +++ b/t/60-bin-efa.t @@ -3,7 +3,7 @@ use strict; use warnings; use 5.010; -use Test::Command tests => (27); +use Test::Command tests => 85; my $efa = 'bin/efa'; my $testarg = "E HBf MH HBf"; @@ -11,91 +11,108 @@ my $test_parse = "--test-parse $testarg"; my $EMPTY = ''; -my $re_usage = qr{Insufficient to/from arguments, see \S*efa --help for usage}; my $re_version = qr{\S*efa version \S+}; -my $err_exclude = "exclude: Invalid argument: invalid\n"; -my $err_prefer = "prefer: Invalid argument. Use speed|nowait|nowalk\n"; -my $err_include = "include: Invalid argument. Use local|ic|ice\n"; -my $err_time = "time: Invalid argument. Use HH:MM\n"; -my $err_date = "date: Invalid argument: Use DD.MM.[YYYY]\n"; -my $err_walk_speed = "walk-speed: Invalid argument. Use normal|fast|slow\n"; -my $err_common = "Please see bin/efa --help\n"; +sub mk_err { + my ($arg, $value, $message) = @_; + return sprintf( + "WWW::Efa config error: Wrong arg for option %s: %s\n%s\n", + $arg, $value, $message + ); +} # Usage on invalid invocation my $cmd = Test::Command->new(cmd => "$efa"); -#$cmd->exit_isnt_num(0); -#$cmd->stdout_is_eq($EMPTY); -#$cmd->stderr_like($re_usage); -# -#$cmd = Test::Command->new(cmd => "$efa E HBf MH"); -# -#$cmd->exit_isnt_num(0); -#$cmd->stdout_is_eq($EMPTY); -#$cmd->stderr_like($re_usage); -# -#$cmd = Test::Command->new(cmd => "$efa E HBf Du HBf MH"); -# -#$cmd->exit_isnt_num(0); -#$cmd->stdout_is_eq($EMPTY); -#$cmd->stderr_like($re_usage); - -#for my $opt (qw/-e --exclude/) { -# $cmd = Test::Command->new(cmd => "$efa $opt invalid $testarg"); -# -# $cmd->exit_isnt_num(0); -# $cmd->stdout_is_eq($EMPTY); -# $cmd->stderr_is_eq($err_exclude . $err_common); -#} -# -#for my $opt (qw/-m --max-change/) { -# $cmd = Test::Command->new(cmd => "$efa $opt nan $testarg"); -# -# $cmd->exit_isnt_num(0); -# $cmd->stdout_is_eq($EMPTY); -# # no stderr test - depends on Getopt::Long -#} -# -#for my $opt (qw/-P --prefer/) { -# $cmd = Test::Command->new(cmd => "$efa $opt invalid $testarg"); -# -# $cmd->exit_isnt_num(0); -# $cmd->stdout_is_eq($EMPTY); -# $cmd->stderr_is_eq($err_prefer . $err_common); -#} -# -#for my $opt (qw/-i --include/) { -# $cmd = Test::Command->new(cmd => "$efa $opt invalid $testarg"); -# -# $cmd->exit_isnt_num(0); -# $cmd->stdout_is_eq($EMPTY); -# $cmd->stderr_is_eq($err_include . $err_common); -#} -# -#for my $opt (qw/-w --walk-speed/) { -# $cmd = Test::Command->new(cmd => "$efa $opt invalid $testarg"); -# -# $cmd->exit_isnt_num(0); -# $cmd->stdout_is_eq($EMPTY); -# $cmd->stderr_is_eq($err_walk_speed . $err_common); -#} -# -#for my $opt (qw/-t --time/) { -# $cmd = Test::Command->new(cmd => "$efa $opt 35:12 $testarg"); -# -# $cmd->exit_isnt_num(0); -# $cmd->stdout_is_eq($EMPTY); -# $cmd->stderr_is_eq($err_time . $err_common); -#} -# -#for my $opt (qw/-d --date/) { -# $cmd = Test::Command->new(cmd => "$efa $opt 11.23.2010 $testarg"); -# -# $cmd->exit_isnt_num(0); -# $cmd->stdout_is_eq($EMPTY); -# $cmd->stderr_is_eq($err_date . $err_common); -#} +$cmd->exit_isnt_num(0); +$cmd->stdout_is_eq($EMPTY); +$cmd->stderr_is_eq( + mk_err('place', 'origin', 'Need at least two elements') +); + +$cmd = Test::Command->new(cmd => "$efa E HBf MH"); + +$cmd->exit_isnt_num(0); +$cmd->stdout_is_eq($EMPTY); +$cmd->stderr_is_eq( + mk_err('place', 'origin', 'Need at least two elements') +); + +$cmd = Test::Command->new(cmd => "$efa E HBf Du HBf MH"); + +$cmd->exit_isnt_num(0); +$cmd->stdout_is_eq($EMPTY); +$cmd->stderr_is_eq( + mk_err('place', 'origin', 'Need at least two elements') +); + +for my $opt (qw/-e --exclude/) { + $cmd = Test::Command->new(cmd => "$efa $opt invalid $testarg"); + + $cmd->exit_isnt_num(0); + $cmd->stdout_is_eq($EMPTY); + $cmd->stderr_is_eq( + mk_err('exclude', 'invalid', 'Must consist of zug s-bahn u-bahn stadtbahn tram stadtbus regionalbus schnellbus seilbahn schiff ast sonstige') + ); +} + +for my $opt (qw/-m --max-change/) { + $cmd = Test::Command->new(cmd => "$efa $opt nan $testarg"); + + $cmd->exit_isnt_num(0); + $cmd->stdout_is_eq($EMPTY); + # no stderr test - depends on Getopt::Long +} + +for my $opt (qw/-P --prefer/) { + $cmd = Test::Command->new(cmd => "$efa $opt invalid $testarg"); + + $cmd->exit_isnt_num(0); + $cmd->stdout_is_eq($EMPTY); + $cmd->stderr_is_eq( + mk_err('prefer', 'invalid', 'Must be either speed, nowait or nowalk') + ); +} + +for my $opt (qw/-i --include/) { + $cmd = Test::Command->new(cmd => "$efa $opt invalid $testarg"); + + $cmd->exit_isnt_num(0); + $cmd->stdout_is_eq($EMPTY); + $cmd->stderr_is_eq( + mk_err('include', 'invalid', 'Must be one of local/ic/ice') + ); +} + +for my $opt (qw/-w --walk-speed/) { + $cmd = Test::Command->new(cmd => "$efa $opt invalid $testarg"); + + $cmd->exit_isnt_num(0); + $cmd->stdout_is_eq($EMPTY); + $cmd->stderr_is_eq( + mk_err('walk_speed', 'invalid', 'Must be normal, fast or slow') + ); +} + +for my $opt (qw/-t --time --depart -a --arrive/) { + $cmd = Test::Command->new(cmd => "$efa $opt 35:12 $testarg"); + + $cmd->exit_isnt_num(0); + $cmd->stdout_is_eq($EMPTY); + $cmd->stderr_is_eq( + mk_err('time', '35:12', 'Must match HH:MM') + ); +} + +for my $opt (qw/-d --date/) { + $cmd = Test::Command->new(cmd => "$efa $opt 11.23.2010 $testarg"); + + $cmd->exit_isnt_num(0); + $cmd->stdout_is_eq($EMPTY); + $cmd->stderr_is_eq( + mk_err('date', '11.23.2010', 'Must match DD.MM.[YYYY]') + ); +} for my $opt (qw/-v --version/) { $cmd = Test::Command->new(cmd => "$efa $opt"); |