[svn:parrot] r41785 - in branches/detect_llvm: config/auto t/steps/auto

jkeenan at svn.parrot.org jkeenan at svn.parrot.org
Sat Oct 10 01:40:50 UTC 2009


Author: jkeenan
Date: Sat Oct 10 01:40:49 2009
New Revision: 41785
URL: https://trac.parrot.org/parrot/changeset/41785

Log:
Refactor code into _handle_native_assembly_output() and add tests.

Modified:
   branches/detect_llvm/config/auto/llvm.pm
   branches/detect_llvm/t/steps/auto/llvm-01.t

Modified: branches/detect_llvm/config/auto/llvm.pm
==============================================================================
--- branches/detect_llvm/config/auto/llvm.pm	Sat Oct 10 01:14:33 2009	(r41784)
+++ branches/detect_llvm/config/auto/llvm.pm	Sat Oct 10 01:40:49 2009	(r41785)
@@ -136,14 +136,9 @@
                         eval {
                             $output = capture_output(qq{./$nativefile});
                         };
-                        if ( $@ or ( $output !~ q/hello world/) ) {
-                            print "Unable to execute native assembly program successfuly\n"
-                                if $verbose;
-                            $self->_handle_result( $conf, 0 );
-                        }
-                        else {
-                            $self->_handle_result( $conf, 1 );
-                        }
+                        $self->_handle_native_assembly_output(
+                            $conf, $output, $verbose
+                        );
                     }
                 }
             }
@@ -184,6 +179,18 @@
     return 1;
 }
 
+sub _handle_native_assembly_output {
+    my ($self, $conf, $output, $verbose) = @_;
+    if ( $@ or ( $output !~ /hello world/ ) ) {
+        print "Unable to execute native assembly program successfully\n"
+            if $verbose;
+        $self->_handle_result( $conf, 0 );
+    }
+    else {
+        $self->_handle_result( $conf, 1 );
+    }
+}
+
 sub _cleanup_llvm_files {
    my @llvm_files = @_;
    my $count_unlinked = 0;

Modified: branches/detect_llvm/t/steps/auto/llvm-01.t
==============================================================================
--- branches/detect_llvm/t/steps/auto/llvm-01.t	Sat Oct 10 01:14:33 2009	(r41784)
+++ branches/detect_llvm/t/steps/auto/llvm-01.t	Sat Oct 10 01:40:49 2009	(r41785)
@@ -6,7 +6,7 @@
 use strict;
 use warnings;
 use File::Temp qw( tempdir );
-use Test::More tests =>  43;
+use Test::More qw(no_plan); # tests =>  43;
 use Carp;
 use lib qw( lib t/configure/testlib );
 use_ok('config::init::defaults');
@@ -173,6 +173,71 @@
     "Got expected verbose output: llvm lacking",
 );
 
+##### _handle_native_assembly_output() #####
+
+{
+    local $@ = '';
+    $output = 'hello world';
+    $verbose = 0;
+    ok( $step->_handle_native_assembly_output( $conf, $output, $verbose ),
+        "_handle_native_assembly_output() returned true value" );
+    is( $step->result(), 'yes', "Got expected 'yes' result" );
+}
+
+{
+    local $@ = 'error';
+    $output = 'hello world';
+    $verbose = 0;
+    ok( $step->_handle_native_assembly_output( $conf, $output, $verbose ),
+        "_handle_native_assembly_output() returned true value" );
+    is( $step->result(), 'no', "Got expected 'no' result" );
+}
+
+{
+    local $@ = '';
+    $output = 'goodbye, cruel world';
+    $verbose = 0;
+    ok( $step->_handle_native_assembly_output( $conf, $output, $verbose ),
+        "_handle_native_assembly_output() returned true value" );
+    is( $step->result(), 'no', "Got expected 'no' result" );
+}
+
+{
+    local $@ = 'error';
+    $output = 'hello world';
+    $verbose = 1;
+    capture(
+        sub { $step->_handle_native_assembly_output(
+                $conf, $output, $verbose); },
+        \$stdout,
+        \$stderr,
+    );
+    is( $step->result(), 'no', "Got expected 'no' result" );
+    like(
+        $stdout, 
+        qr/Unable to execute native assembly program successfully/,
+        "Got expected verbose output: native assembly program",
+    );
+}
+
+{
+    local $@ = '';
+    $output = 'goodbye, cruel world';
+    $verbose = 1;
+    capture(
+        sub { $step->_handle_native_assembly_output(
+                $conf, $output, $verbose); },
+        \$stdout,
+        \$stderr,
+    );
+    is( $step->result(), 'no', "Got expected 'no' result" );
+    like(
+        $stdout, 
+        qr/Unable to execute native assembly program successfully/,
+        "Got expected verbose output: native assembly program",
+    );
+}
+
 ##### _cleanup_llvm_files() #####
 
 my ( $bcfile, $sfile, $nativefile );
@@ -182,14 +247,14 @@
     auto::llvm::_cleanup_llvm_files( $bcfile, $sfile, $nativefile );
 is( $count_unlinked, 0, "no files existed, hence none unlinked" );
 
-my ( $bcfile, $sfile, $nativefile ) = ( '', '', '' );
+( $bcfile, $sfile, $nativefile ) = ( '', '', '' );
 $count_unlinked =
     auto::llvm::_cleanup_llvm_files( $bcfile, $sfile, $nativefile );
 is( $count_unlinked, 0, "no files existed, hence none unlinked" );
 
 {
     my $tdir = tempdir( CLEANUP => 1 );
-    my $bcfile = qq|$tdir/bcfile|;
+    $bcfile = qq|$tdir/bcfile|;
     open my $FH, '>', $bcfile
         or die "Unable to open handle for writing: $!";
     print $FH qq|bcfile hello world\n|;


More information about the parrot-commits mailing list