From 84ce4b0a74e6ece2ecf7294149e4492bcc512f9d Mon Sep 17 00:00:00 2001 From: "James E. Keenan" Date: Sun, 6 Feb 2011 15:39:06 +0100 Subject: [PATCH] More and better tests Provide messages for some tests in 001-basic.t. Add file t/004-nolinenumbers.t to test case where line numbers are not requested. --- MANIFEST | 1 + dist/ExtUtils-ParseXS/t/001-basic.t | 25 ++++--- dist/ExtUtils-ParseXS/t/004-nolinenumbers.t | 100 ++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 dist/ExtUtils-ParseXS/t/004-nolinenumbers.t diff --git a/MANIFEST b/MANIFEST index f984a13..90796b0 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2981,6 +2981,7 @@ dist/ExtUtils-ParseXS/lib/ExtUtils/xsubpp External subroutine preprocessor dist/ExtUtils-ParseXS/t/001-basic.t See if ExtUtils::ParseXS works dist/ExtUtils-ParseXS/t/002-more.t Extended ExtUtils::ParseXS testing dist/ExtUtils-ParseXS/t/003-usage.t ExtUtils::ParseXS tests +dist/ExtUtils-ParseXS/t/004-nolinenumbers.t ExtUtils::ParseXS tests dist/ExtUtils-ParseXS/t/101-standard_typemap_locations.t ExtUtils::ParseXS tests dist/ExtUtils-ParseXS/t/102-trim_whitespace.t ExtUtils::ParseXS tests dist/ExtUtils-ParseXS/t/103-tidy_type.t ExtUtils::ParseXS tests diff --git a/dist/ExtUtils-ParseXS/t/001-basic.t b/dist/ExtUtils-ParseXS/t/001-basic.t index 39e1ca9..f948768 100644 --- a/dist/ExtUtils-ParseXS/t/001-basic.t +++ b/dist/ExtUtils-ParseXS/t/001-basic.t @@ -1,13 +1,11 @@ #!/usr/bin/perl use strict; -use Test::More; +use Test::More tests => 11; use Config; use DynaLoader; use ExtUtils::CBuilder; -plan tests => 10; - my ($source_file, $obj_file, $lib_file); require_ok( 'ExtUtils::ParseXS' ); @@ -37,7 +35,7 @@ SKIP: { skip "no compiler available", 2 if ! $b->have_compiler; $obj_file = $b->compile( source => $source_file ); - ok $obj_file; + ok $obj_file, "ExtUtils::CBuilder::compile() returned true value"; ok -e $obj_file, "Make sure $obj_file exists"; } @@ -46,13 +44,15 @@ SKIP: { if !$b->have_compiler || !$Config{usedl}; my $module = 'XSTest'; $lib_file = $b->link( objects => $obj_file, module_name => $module ); - ok $lib_file; + ok $lib_file, "ExtUtils::CBuilder::link() returned true value"; ok -e $lib_file, "Make sure $lib_file exists"; eval {require XSTest}; - is $@, ''; - ok XSTest::is_even(8); - ok !XSTest::is_even(9); + is $@, '', "No error message recorded, as expected"; + ok XSTest::is_even(8), + "Function created thru XS returned expected true value"; + ok !XSTest::is_even(9), + "Function created thru XS returned expected false value"; # Win32 needs to close the DLL before it can unlink it, but unfortunately # dl_unload_file was missing on Win32 prior to perl change #24679! @@ -66,6 +66,15 @@ SKIP: { } } +my $seen = 0; +open my $IN, '<', $source_file + or die "Unable to open $source_file: $!"; +while (my $l = <$IN>) { + $seen++ if $l =~ m/#line\s1\s/; +} +close $IN or die "Unable to close $source_file: $!"; +is( $seen, 1, "Linenumbers created in output file, as intended" ); + unless ($ENV{PERL_NO_CLEANUP}) { for ( $obj_file, $lib_file, $source_file) { next unless defined $_; diff --git a/dist/ExtUtils-ParseXS/t/004-nolinenumbers.t b/dist/ExtUtils-ParseXS/t/004-nolinenumbers.t new file mode 100644 index 0000000..4a1565a --- /dev/null +++ b/dist/ExtUtils-ParseXS/t/004-nolinenumbers.t @@ -0,0 +1,100 @@ +#!/usr/bin/perl + +use strict; +use Test::More tests => 11; +use Config; +use DynaLoader; +use ExtUtils::CBuilder; + +my ($source_file, $obj_file, $lib_file); + +require_ok( 'ExtUtils::ParseXS' ); +ExtUtils::ParseXS->import('process_file'); + +chdir 't' or die "Can't chdir to t/, $!"; + +use Carp; $SIG{__WARN__} = \&Carp::cluck; + +######################### + +# Try sending to filehandle +tie *FH, 'Foo'; +process_file( + filename => 'XSTest.xs', + output => \*FH, + prototypes => 1, + linenumbers => 0, +); +like tied(*FH)->content, '/is_even/', "Test that output contains some text"; + +$source_file = 'XSTest.c'; + +# Try sending to file +process_file( + filename => 'XSTest.xs', + output => $source_file, + prototypes => 0, + linenumbers => 0, +); +ok -e $source_file, "Create an output file"; + +my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE}; +my $b = ExtUtils::CBuilder->new(quiet => $quiet); + +SKIP: { + skip "no compiler available", 2 + if ! $b->have_compiler; + $obj_file = $b->compile( source => $source_file ); + ok $obj_file, "ExtUtils::CBuilder::compile() returned true value"; + ok -e $obj_file, "Make sure $obj_file exists"; +} + +SKIP: { + skip "no dynamic loading", 5 + if !$b->have_compiler || !$Config{usedl}; + my $module = 'XSTest'; + $lib_file = $b->link( objects => $obj_file, module_name => $module ); + ok $lib_file, "ExtUtils::CBuilder::link() returned true value"; + ok -e $lib_file, "Make sure $lib_file exists"; + + eval {require XSTest}; + is $@, '', "No error message recorded, as expected"; + ok XSTest::is_even(8), + "Function created thru XS returned expected true value"; + ok !XSTest::is_even(9), + "Function created thru XS returned expected false value"; + + # Win32 needs to close the DLL before it can unlink it, but unfortunately + # dl_unload_file was missing on Win32 prior to perl change #24679! + if ($^O eq 'MSWin32' and defined &DynaLoader::dl_unload_file) { + for (my $i = 0; $i < @DynaLoader::dl_modules; $i++) { + if ($DynaLoader::dl_modules[$i] eq $module) { + DynaLoader::dl_unload_file($DynaLoader::dl_librefs[$i]); + last; + } + } + } +} + +my $seen = 0; +open my $IN, '<', $source_file + or die "Unable to open $source_file: $!"; +while (my $l = <$IN>) { + $seen++ if $l =~ m/#line\s1\s/; +} +close $IN or die "Unable to close $source_file: $!"; +is( $seen, 0, "No linenumbers created in output file, as intended" ); + + +unless ($ENV{PERL_NO_CLEANUP}) { + for ( $obj_file, $lib_file, $source_file) { + next unless defined $_; + 1 while unlink $_; + } +} + +##################################################################### + +sub Foo::TIEHANDLE { bless {}, 'Foo' } +sub Foo::PRINT { shift->{buf} .= join '', @_ } +sub Foo::content { shift->{buf} } -- 2.7.4