Revision: 103
Author: cosimo.streppone
Date: Wed Oct 21 10:01:20 2009
Log: invoke_javap(): also check status of close() on piped javap, since it
can help detecting failures
http://code.google.com/p/java2perl6/source/detail?r=103
Modified:
/trunk/lib/Java/Javap.pm
/trunk/t/02_invoke_javap.t
=======================================
--- /trunk/lib/Java/Javap.pm Mon Oct 5 07:39:49 2009
+++ /trunk/lib/Java/Javap.pm Wed Oct 21 10:01:20 2009
@@ -4,7 +4,7 @@
use warnings;
use Carp;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
our $JAVAP_EXECUTABLE = 'javap';
use Java::Javap::TypeCast;
@@ -57,14 +57,19 @@
$options ||= {};
+ # Open the real javap executable and read output from it
open(my $javap_fh, '-|', $JAVAP_EXECUTABLE, %$options, @$classes)
or croak "'$JAVAP_EXECUTABLE @{[ %$options ]} @$classes' failed:
$!";
my $javap_output = q{};
+
while (<$javap_fh>) {
$javap_output .= $_;
}
- close $javap_fh;
+
+ # When dealing with a pipe, we also want to get errors from close
+ close $javap_fh
+ or croak "'$JAVAP_EXECUTABLE @{[ %$options ]} @$classes' failed:
$!";
return $javap_output;
}
=======================================
--- /trunk/t/02_invoke_javap.t Sun Oct 4 06:34:16 2009
+++ /trunk/t/02_invoke_javap.t Wed Oct 21 10:01:20 2009
@@ -9,15 +9,19 @@
plan skip_all => "javap from Java SDK required: $@"
unless Java::Javap->javap_test;
-plan tests => 2;
+plan tests => 4;
+
+my $java_class = 'com.example.NestedIntTest';
my $decomp = Java::Javap->javap(
- ['com.example.NestedIntTest'],
+ [$java_class],
{-classpath=>'testjavas'}
);
diag($decomp);
ok($decomp, 'received some output from javap');
-like($decomp, qr{Compiled from}m, 'javap output seems sane');
-
+like($decomp, qr{Compiled from}m, 'javap output contains a "Compiled from"
statement');
+like($decomp, qr{$java_class}m, 'javap output contains the original class
name');
+ok(length($decomp) > length($java_class), 'javap output is longer than the
class name');
+