quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [PATCH 1/3] test/run: Rewrite the main parsing loop


From: Jean Delvare
Subject: [Quilt-dev] [PATCH 1/3] test/run: Rewrite the main parsing loop
Date: Wed, 18 Dec 2013 14:15:30 +0100

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.
---
 test/run |   67 +++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 34 insertions(+), 33 deletions(-)

--- a/test/run
+++ b/test/run
@@ -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;
-
-      $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;
-  }
+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;
+       }
+
+       # 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)." -- ";

-- 
Jean Delvare
Suse L3 Support




reply via email to

[Prev in Thread] Current Thread [Next in Thread]