quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [patch 5/8] test/run: Reorder functions


From: Jean Delvare
Subject: [Quilt-dev] [patch 5/8] test/run: Reorder functions
Date: Sun, 02 Feb 2014 15:20:10 +0100
User-agent: quilt/0.61-1

Move functions before they are called, so that we no longer need forward
declarations.
---
 test/run |  257 ++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 125 insertions(+), 132 deletions(-)

--- a/test/run
+++ b/test/run
@@ -60,13 +60,6 @@ if (isatty(fileno(STDOUT))) {
        $FAILED = "\033[31m\033[1m" . $FAILED . "\033[m";
 }
 
-sub exec_test($$);
-sub process_test($$$$);
-sub print_header($);
-sub print_body($);
-sub print_footer($);
-sub flush_output($);
-
 my $prog;
 my ($in, $out) = ([], []);
 my $prog_line = 0;
@@ -77,117 +70,49 @@ my $width = ($ENV{COLUMNS} || 80) >> 1;
 my $origdir = getcwd;
 my $workdir = "d.$$";
 
-# Create a dedicated working directory
-mkdir $workdir or die;
-chdir $workdir or die;
-$ENV{PWD} = getcwd;
-
-if (defined $ARGV[0]) {
-       open(SOURCE, "$origdir/$ARGV[0]");
-       print_header "[$ARGV[0]]\n";
-} else {
-       *SOURCE = *STDIN;
-}
-
-# Substitute %{VAR} with environment variables
-sub substitute_vars($)
+sub print_header($)
 {
-       my ($line) = @_;
-       $line =~ s[%{(\w+)}][defined $ENV{$1} ? $ENV{$1} : ""]eg;
-       return $line;
-}
-
-while (defined(my $line = <SOURCE>)) {
-       $lineno++;
-
-       # Collect input and output for the previous command
-       if ($line =~ s/^\s*< ?//) {
-               push @$in, substitute_vars($line);
-               next;
-       }
-       if ($line =~ s/^\s*> ?//) {
-               push @$out, substitute_vars($line);
-               next;
-       }
-
-       # We have all input and output, we can execute the command
-       if (defined $prog) {
-               $last_status = process_test($prog, $prog_line, $in, $out);
-               $prog = undef;
-               last if $prog_line >= $opt_l;
+       if ($opt_q) {
+               $output{header} = $_[0];
+       } else {
+               print $_[0];
        }
+}
 
-       # Parse the next command
-       if ($line =~ s/^\s*\$ ?//) {
-               # Substitute %{?} with the last command's status
-               $line =~ s[%{\?}][$last_status]eg;
-
-               chomp($prog = substitute_vars($line));
-               $prog_line = $lineno;
-               $in = [];
-               $out = [];
+sub print_body($)
+{
+       if ($opt_q) {
+               $output{body} .= $_[0];
+       } else {
+               print $_[0];
        }
 }
-# Execute last command if needed
-process_test($prog, $prog_line, $in, $out) if defined $prog;
-
-close(SOURCE);
 
-# Clean up the mess
-chdir $origdir or die;
-system "rm -rf $workdir";
-
-my $status = sprintf("%d commands (%d passed, %d failed)",
-       $tests, $tests-$failed, $failed);
-if (isatty(fileno(STDOUT))) {
-       if ($failed) {
-               $status = "\033[31m\033[1m" . $status . "\033[m";
+sub print_footer($)
+{
+       if ($opt_q) {
+               $output{footer} .= $_[0];
        } else {
-               $status = "\033[32m" . $status . "\033[m";
+               print $_[0];
        }
 }
-print_footer "$status\n";
-flush_output $failed;
-exit $failed ? 1 : 0;
-
-sub process_test($$$$) {
-       my ($prog, $prog_line, $in, $out) = @_;
 
-       print_body "[$prog_line] \$ $prog -- ";
-       my ($exec_status, $result) = exec_test($prog, $in);
-       my @good = ();
-       my $nmax = (@$out > @$result) ? @$out : @$result;
-       for (my $n = 0; $n < $nmax; $n++) {
-               my $use_re;
-               if (defined $out->[$n] && $out->[$n] =~ /^~ /) {
-                       $use_re = 1;
-                       $out->[$n] =~ s/^~ //g;
-               }
+sub flush_output($)
+{
+       my $failed = shift;
+       return unless $opt_q;
 
-               if (!defined($out->[$n]) || !defined($result->[$n]) ||
-                   (!$use_re && $result->[$n] ne $out->[$n]) ||
-                   ( $use_re && $result->[$n] !~ /^$out->[$n]/)) {
-                       push @good, ($use_re ? '!~' : '!=');
-               } else {
-                       push @good, ($use_re ? '=~' : '==');
-               }
-       }
-       my $good = !grep(/!/, @good);
-       $tests++;
-       $failed++ unless $good;
-       print_body(($good ? $OK : $FAILED)."\n");
-       if (!$good || $opt_v) {
-               for (my $n = 0; $n < $nmax; $n++) {
-                       my $l = defined($out->[$n]) ? $out->[$n] : "~";
-                       chomp $l;
-                       my $r = defined($result->[$n]) ? $result->[$n] : "~";
-                       chomp $r;
-                       print_body sprintf("%-" . ($width - 3) . "s %s %s\n",
-                                          $r, $good[$n], $l);
-               }
-       }
+       print $output{header} || "",
+             $failed ? $output{body} : "",
+             $output{footer} || "";
+}
 
-       return $exec_status;
+# Substitute %{VAR} with environment variables
+sub substitute_vars($)
+{
+       my ($line) = @_;
+       $line =~ s[%{(\w+)}][defined $ENV{$1} ? $ENV{$1} : ""]eg;
+       return $line;
 }
 
 sub exec_test($$) {
@@ -288,39 +213,107 @@ sub exec_test($$) {
        }
 }
 
-sub print_header($)
-{
-       if ($opt_q) {
-               $output{header} = $_[0];
-       } else {
-               print $_[0];
+sub process_test($$$$) {
+       my ($prog, $prog_line, $in, $out) = @_;
+
+       print_body "[$prog_line] \$ $prog -- ";
+       my ($exec_status, $result) = exec_test($prog, $in);
+       my @good = ();
+       my $nmax = (@$out > @$result) ? @$out : @$result;
+       for (my $n = 0; $n < $nmax; $n++) {
+               my $use_re;
+               if (defined $out->[$n] && $out->[$n] =~ /^~ /) {
+                       $use_re = 1;
+                       $out->[$n] =~ s/^~ //g;
+               }
+
+               if (!defined($out->[$n]) || !defined($result->[$n]) ||
+                   (!$use_re && $result->[$n] ne $out->[$n]) ||
+                   ( $use_re && $result->[$n] !~ /^$out->[$n]/)) {
+                       push @good, ($use_re ? '!~' : '!=');
+               } else {
+                       push @good, ($use_re ? '=~' : '==');
+               }
+       }
+       my $good = !grep(/!/, @good);
+       $tests++;
+       $failed++ unless $good;
+       print_body(($good ? $OK : $FAILED)."\n");
+       if (!$good || $opt_v) {
+               for (my $n = 0; $n < $nmax; $n++) {
+                       my $l = defined($out->[$n]) ? $out->[$n] : "~";
+                       chomp $l;
+                       my $r = defined($result->[$n]) ? $result->[$n] : "~";
+                       chomp $r;
+                       print_body sprintf("%-" . ($width - 3) . "s %s %s\n",
+                                          $r, $good[$n], $l);
+               }
        }
+
+       return $exec_status;
 }
 
-sub print_body($)
-{
-       if ($opt_q) {
-               $output{body} .= $_[0];
-       } else {
-               print $_[0];
-       }
+# Create a dedicated working directory
+mkdir $workdir or die;
+chdir $workdir or die;
+$ENV{PWD} = getcwd;
+
+if (defined $ARGV[0]) {
+       open(SOURCE, "$origdir/$ARGV[0]");
+       print_header "[$ARGV[0]]\n";
+} else {
+       *SOURCE = *STDIN;
 }
 
-sub print_footer($)
-{
-       if ($opt_q) {
-               $output{footer} .= $_[0];
-       } else {
-               print $_[0];
+while (defined(my $line = <SOURCE>)) {
+       $lineno++;
+
+       # Collect input and output for the previous command
+       if ($line =~ s/^\s*< ?//) {
+               push @$in, substitute_vars($line);
+               next;
+       }
+       if ($line =~ s/^\s*> ?//) {
+               push @$out, substitute_vars($line);
+               next;
+       }
+
+       # We have all input and output, we can execute the command
+       if (defined $prog) {
+               $last_status = process_test($prog, $prog_line, $in, $out);
+               $prog = undef;
+               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;
+
+               chomp($prog = substitute_vars($line));
+               $prog_line = $lineno;
+               $in = [];
+               $out = [];
        }
 }
+# Execute last command if needed
+process_test($prog, $prog_line, $in, $out) if defined $prog;
 
-sub flush_output($)
-{
-       my $failed = shift;
-       return unless $opt_q;
+close(SOURCE);
 
-       print $output{header} || "",
-             $failed ? $output{body} : "",
-             $output{footer} || "";
+# Clean up the mess
+chdir $origdir or die;
+system "rm -rf $workdir";
+
+my $status = sprintf("%d commands (%d passed, %d failed)",
+       $tests, $tests - $failed, $failed);
+if (isatty(fileno(STDOUT))) {
+       if ($failed) {
+               $status = "\033[31m\033[1m" . $status . "\033[m";
+       } else {
+               $status = "\033[32m" . $status . "\033[m";
+       }
 }
+print_footer "$status\n";
+flush_output $failed;
+exit $failed ? 1 : 0;





reply via email to

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