Commit aa509864 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Detect non-itinerary efa.vrr.de output (i.e. upon invalid input data)

parent 05b9609c
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -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,12 +255,23 @@ 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());
		}
	}

	if (defined $con_no) {
		return $cons;
	}
	else {
		say "efa.vrr.de returned no connections, check your input data.";
		exit 3;
	}
}

GetOptions(
	'a|arrive=s'     => \&opt_time_arr,
@@ -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
+9 −1
Original line number Diff line number Diff line
@@ -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);
+793 −0

File added.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
efa.vrr.de returned no connections, check your input data.