diff --git a/bin/efa b/bin/efa index 3056c8142c4fb3efe17b18b59d91ac5d15e656a9..aa8286418bcf108ea0ffdcc0aaf0db3b4c0c37dd 100755 --- a/bin/efa +++ b/bin/efa @@ -223,7 +223,7 @@ sub opt_timeout { sub parse_tree { my ($full_tree) = @_; my $con_part = 0; - my $con_no = 0; + my $con_no; my $cons; my $xp_td = XML::LibXML::XPathExpression->new('//table//table/tr/td'); @@ -255,11 +255,22 @@ sub parse_tree { } } - if (not $td->exists($xp_img) and $td->textContent() !~ /^\s*$/) { + if ( + defined $con_no and not $td->exists($xp_img) + and $td->textContent() !~ /^\s*$/ + ) + { push(@{$cons->[$con_no]->[$con_part]}, $td->textContent()); } } - return $cons; + + if (defined $con_no) { + return $cons; + } + else { + say "efa.vrr.de returned no connections, check your input data."; + exit 3; + } } GetOptions( @@ -362,10 +373,6 @@ check_no_connections($tree); $connections = parse_tree($tree); -if (@{$connections} == 0) { - die("Got no connections, parse error?\n"); -} - for my $i (0 .. $#{$connections}) { display_connection($connections->[$i]); if ($i != $#{$connections}) { @@ -523,7 +530,8 @@ Print version information 0 Everything went well 1 Ambiguous input, re-run efa with different arguments - 2 efa.vrr.de error + 2 efa.vrr.de error (i.e. unable to find matching connections) + 3 efa.vrr.de error (usually invalid input data) 255 Any other kind of error =head1 CONFIGURATION diff --git a/test/50-efa.t b/test/50-efa.t index 067b70b739f126819a5809fada4763f153cd46d7..ef97fb9974d215c1658ac94c7cecafaf9dfb44da 100644 --- a/test/50-efa.t +++ b/test/50-efa.t @@ -3,7 +3,7 @@ use strict; use warnings; use 5.010; -use Test::Command tests => 82; +use Test::Command tests => 85; my $efa = 'bin/efa'; my $testarg = "E HBf MH HBf"; @@ -152,3 +152,11 @@ $cmd = Test::Command->new( $cmd->exit_is_num(2); $cmd->stdout_is_file('test/parse_no_connections'); $cmd->stderr_is_eq($EMPTY); + +$cmd = Test::Command->new( + cmd => "$efa $test_parse < test/dump_invalid_input" +); + +$cmd->exit_is_num(3); +$cmd->stdout_is_file('test/parse_invalid_input'); +$cmd->stderr_is_eq($EMPTY); diff --git a/test/dump_invalid_input b/test/dump_invalid_input new file mode 100644 index 0000000000000000000000000000000000000000..fbdd3a1b231ff36f277fcfe5c9cbdd2b0e668675 --- /dev/null +++ b/test/dump_invalid_input @@ -0,0 +1,793 @@ + +
+ +