diff options
author | Jean Delvare <jdelvare@suse.de> | 2013-12-20 22:36:29 +0100 |
---|---|---|
committer | Jean Delvare <jdelvare@suse.de> | 2013-12-20 22:36:29 +0100 |
commit | 0b191eec5dd6cdb8b74d92a34bd5f0d0261b0009 (patch) | |
tree | 2f23aa71b07b9cfda5f38b95cf0996eddbc7d13d | |
parent | 64d8ac1c179ced1b00bc728d3abf6e7b4def4a64 (diff) | |
download | quilt-0b191eec5dd6cdb8b74d92a34bd5f0d0261b0009.tar.gz |
test/run: Rewrite the main parsing loop
Rewrite the main parsing loop of the tester scripts, in a way which
is easier to understand and avoids redundant tests.
No functional change here.
-rwxr-xr-x | test/run | 65 |
1 files changed, 33 insertions, 32 deletions
@@ -81,38 +81,41 @@ if (defined $ARGV[0]) { *SOURCE = *STDIN; } -for (;;) { - my $line = <SOURCE>; $lineno++; - if (defined $line) { - # Substitute %{VAR} with environment variables. - $line =~ s[%{(\w+)}][$ENV{$1}]eg; - } - if (defined $line) { - if ($line =~ s/^\s*< ?//) { - push @$in, $line; - } elsif ($line =~ s/^\s*> ?//) { - push @$out, $line; - } else { - $last_status = process_test($prog, $prog_line, $in, $out) if @$prog; - last if $prog_line >= $opt_l; +while (defined(my $line = <SOURCE>)) { + $lineno++; + # Substitute %{VAR} with environment variables + $line =~ s[%{(\w+)}][$ENV{$1}]eg; + + # Collect input and output for the previous command + if ($line =~ s/^\s*< ?//) { + push @$in, $line; + next; + } + if ($line =~ s/^\s*> ?//) { + push @$out, $line; + next; + } - $prog = []; - $prog_line = 0; - } - if ($line =~ s/^\s*\$ ?//) { - # Substitute %{?} with the last command's status. - $line =~ s[%{\?}][$last_status]eg; - - $prog = [ map { s/\\(.)/$1/g; $_ } split /(?<!\\)\s+/, $line ]; - $prog_line = $lineno; - $in = []; - $out = []; - } - } else { - process_test($prog, $prog_line, $in, $out); - last; - } + # We have all input and output, we can execute the command + if (@$prog) { + $last_status = process_test($prog, $prog_line, $in, $out); + $prog = []; + last if $prog_line >= $opt_l; + } + + # Parse the next command + if ($line =~ s/^\s*\$ ?//) { + # Substitute %{?} with the last command's status + $line =~ s[%{\?}][$last_status]eg; + + $prog = [ map { s/\\(.)/$1/g; $_ } split /(?<!\\)\s+/, $line ]; + $prog_line = $lineno; + $in = []; + $out = []; + } } +# Execute last command if needed +process_test($prog, $prog_line, $in, $out) if @$prog; close(SOURCE); @@ -137,8 +140,6 @@ exit $failed ? 1 : 0; sub process_test($$$$) { my ($prog, $prog_line, $in, $out) = @_; - return unless @$prog; - my $p = [ @$prog ]; print_body "[$prog_line] \$ ".join(' ', map { s/\s/\\$&/g; $_ } @$p)." -- "; |