On Sat, 7 May 2005, Leopold Toetsch wrote:

>Dino Morelli <[EMAIL PROTECTED]> wrote:
>> On Fri, 6 May 2005, Leopold Toetsch wrote:
>
>>>"make testr" is broken. We need some replacement for it. It does:
>
>[ and should do ]
>
>>>$ ./parrot -o foo.pbc foo.imc
>>>$ ./parrot foo.pbc
>
>> I think this might do it: [snip]
>

Ok, I have more code. But I'm unsure about something still. First, the
code:

---------------------------------------------------------------------------
Index: /home/dmorelli/dev/parrot/lib/Parrot/Test.pm
===================================================================
--- /home/dmorelli/dev/parrot/lib/Parrot/Test.pm        (revision 7999)
+++ /home/dmorelli/dev/parrot/lib/Parrot/Test.pm        (working copy)
@@ -211,17 +211,30 @@
     open  STDOUT, ">$out"    or die "Can't redirect stdout to $out" if $out;
     open  STDERR, ">$err"    or die "Can't redirect stderr to $err" if $err;

-    $command = "$ENV{VALGRIND} $command" if defined $ENV{VALGRIND};
+    # If $command isn't already an arrayref (because of a multi-command
+    # test), make it so now so the code below can treat everybody the
+    # same.
+    $command = [$command] unless (ref $command);

+    if (defined $ENV{VALGRIND}) {
+        $_ = "$ENV{VALGRIND} $_" for (@$command);
+    }
+
     my $orig_dir;
     if( $chdir ) {
-       $orig_dir = cwd;
-       chdir $chdir;
+        $orig_dir = cwd;
+        chdir $chdir;
     }
-    system( $command );

+    # Execute all commands
+    for (@$command) {
+        system $_;
+
+        # Check the exit code in $? here, bail out as soon as it's bad?
+    }
+
     if( $chdir ) {
-       chdir $orig_dir;
+        chdir $orig_dir;
     }

     my $exit_code = $? >> 8;
@@ -380,11 +393,20 @@
                 if ( $func !~ /^pir_2_pasm_/ &&
                      ( $args =~ s/--run-pbc// || $args =~ s/-r //) ) {
                     my $pbc_f = per_test('.pbc', $test_no);
-                    $args = qq{$args -o "$pbc_f" -r -r};
+                    $args = qq{$args -o "$pbc_f"};
+
+                    # In this case, we need to execute more than one
+                    # command. Instead of a single scalar, build an
+                    # array of commands.
+                    $cmd = [
+                        qq{$parrot $args "$code_f"},
+                        qq{$parrot "$pbc_f"},
+                    ];
+                } else {
+                    $cmd = qq{$parrot $args "$code_f"};
                 }
-                $cmd = qq{$parrot $args "$code_f"};
                 $exit_code = run_command($cmd, CD => $path_to_parrot,
-                                        STDOUT => $out_f, STDERR => $out_f);
+                    STDOUT => $out_f, STDERR => $out_f);
             }

             my $meth = $parrot_test_map{$func};
---------------------------------------------------------------------------

What I'm doing:

In the -r case, packing the commands into an anon array and assigning
that ref to $cmd. Passing that ref to run_command()

run_command() then figures out if it's a ref or not and does the right
thing.  This seemed more sane than modifying the many places that a $cmd
gets built in this code.

The part I'm unsure of is the exit codes. As it's written above, the
exit code returned from run_command() is from the last command in the
array. If there's a failure somewhere, it keeps chugging along trying to
perform them all.

I could change it to watch for a bad code during the for loop with the
system(), bail out right there and send that code back. What do you guys
think?


>Unfortunately this might be not enough.
>
>- is the semicolon portable?
>

The above code eliminates the whole semicolon thing, which is a relief.
:-)


>- a few tests create output during compilation:
>
>$ parrot -o s49.pbc t/pmc/sub_49.pir
>initial
>
>$ parrot s49.pbc
>main
>
>$ parrot t/pmc/sub_49.pir
>initial
>main
>
>We probably need to capture output twice and concat it. I should have
>mentioned that in the first place.
>

As far as capturing output goes: I may be missing something, but it
seems like this is functioning correctly even with stuff like sub_49
above simply by system()ing the commands in the array sequentially and
not explicitly grabbing the output.

Probably because everything's still getting sent to STDOUT even though
it's separate system() calls.


>leo
>

-Dino

-- 
 .~.    Dino Morelli
 /V\    email: [EMAIL PROTECTED]
/( )\   weblog: http://categorically.net/d/blog/
^^-^^   preferred distro: Debian GNU/Linux  http://www.debian.org

Reply via email to