Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Simple CPAN distribution.

Report information

Subject: Test::More::use_ok() doesn't use Carp properly
When I call (see attached use_ok_carp.pl): use Test::More qw(no_plan); use_ok('Carp'); ... 'croak' does not appear to load properly. If I subsequently call: my $output = 'output'; open my $FH, $output or croak "Unable to open $output: $!"; ... I get this error message: use_ok_carp....String found where operator expected at use_ok_carp.pl line 13, near "croak "Unable to open $output for reading"" (Do you need to predeclare croak?) String found where operator expected at use_ok_carp.pl line 18, near "croak "Unable to close $output"" (Do you need to predeclare croak?) syntax error at use_ok_carp.pl line 13, near "croak "Unable to open $output for reading"" syntax error at use_ok_carp.pl line 18, near "croak "Unable to close $output"" Execution of use_ok_carp.pl aborted due to compilation errors. # Looks like your test died before it could output anything. dubious Test returned status 255 (wstat 65280, 0xff00) FAILED--1 test script could be run, alas--no output ever seen shell returned 255 When, however, I convert the 'use_ok' to a standard 'use' (see use_carp.pl attached): use_carp....$VAR1 = [ 'alpha', 'beta', 'gamma' ]; ok 1 - All tests run in use_carp.pl 1..1 ok All tests successful. Files=1, Tests=1, 0 wallclock secs ( 0.07 cusr + 0.03 csys = 0.10 CPU) ... everything DWIMs . With other modules bundled with the Perl core, 'use_ok' DWIMs: use Test::More qw(no_plan); use_ok( 'Cwd' ); use_ok( 'File::Temp', qw| tempdir | ); use_ok( 'Tie::File' ); ... i.e., the module (and specified functions) is loaded and that load is simultaneously verified. Why isn't this working for 'croak'? (Or am I missing something obvious?) Thank you very much. Jim Keenan
Subject: use_carp.pl
# -*- perl -*- #$Id: 02_list.t 1110 2006-12-14 03:56:31Z jimk $ # t/02_list.t - test what happens when source is a list use strict; use warnings; use Test::More qw(no_plan); use Carp; use Data::Dumper; my @lines; my $output = 'output'; open my $FH, $output or croak "Unable to open $output for reading"; while (<$FH>) { chomp; push @lines, $_; } close $FH or croak "Unable to close $output"; print Dumper \@lines; pass("All tests run in $0");
Subject: use_ok_carp.pl
# -*- perl -*- #$Id: 02_list.t 1110 2006-12-14 03:56:31Z jimk $ # t/02_list.t - test what happens when source is a list use strict; use warnings; use Test::More qw(no_plan); use_ok( 'Carp' ); use Data::Dumper; my @lines; my $output = 'output'; open my $FH, $output or croak "Unable to open $output for reading"; while (<$FH>) { chomp; push @lines, $_; } close $FH or croak "Unable to close $output"; print Dumper \@lines;
Subject: output
Download output
application/octet-stream 17b

Message body not shown because it is not plain text.

Subject: perlv
Download perlv
application/octet-stream 2.3k

Message body not shown because it is not plain text.

Subject: Test::More::use_ok('Data::Dumper') doesn't load Dumper properly
When I call: use Test::More qw(no_plan); use_ok( 'Data::Dumper' ); my @lines; my $output = 'output.txt'; open my $FH, $output or die "Unable to open $output for reading"; while (<$FH>) { chomp; push @lines, $_; } close $FH or die "Unable to close $output"; print STDERR Dumper \@lines; and then run 'prove -v' on the script (see attached use_ok_data_dumper.pl), I get the following failure message: use_ok_data_dumper....Backslash found where operator expected at use_ok_data_dumper.pl line 16, near "Dumper \" (Do you need to predeclare Dumper?) syntax error at use_ok_data_dumper.pl line 16, near "Dumper \" Execution of use_ok_data_dumper.pl aborted due to compilation errors. # Looks like your test died before it could output anything. dubious Test returned status 255 (wstat 65280, 0xff00) FAILED--1 test script could be run, alas--no output ever seen shell returned 255 If I convert 'use_ok('Data::Dumper');' to 'use Data::Dumper;', everything DWIMs (see attached use_data_dumper.pl): use_data_dumper....$VAR1 = [ 'alpha', 'beta', 'gamma' ]; ok 1 - All tests passed in use_data_dumper.pl 1..1 ok All tests successful. Files=1, Tests=1, 0 wallclock secs ( 0.07 cusr + 0.03 csys = 0.10 CPU) So Test::More::use_ok() doesn't seem to load Data::Dumper properly. In this, it differs from other modules bundled with the Perl core -- with the exception of Carp, which I just reported in http://rt.cpan.org/Public/Bug/Display.html?id=24173. Shouldn't Test::More::use_ok('Data::Dumper;) both load Data::Dumper and verify its loading? Thank you very much. Jim Keenan
From: jkeen [...] verizon.net
The attachments didn't seem to get attached the first time around.
alpha beta gamma
# -*- perl -*- use strict; use warnings; use Test::More qw(no_plan); use Data::Dumper; my @lines; my $output = 'output.txt'; open my $FH, $output or die "Unable to open $output for reading"; while (<$FH>) { chomp; push @lines, $_; } close $FH or die "Unable to close $output"; print STDERR Dumper \@lines; pass("All tests passed in $0");
Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=darwin, osvers=8.7.0, archname=darwin-2level uname='darwin macintosh.local 8.7.0 darwin kernel version 8.7.0: fri may 26 15:20:53 pdt 2006; root:xnu-792.6.76.obj~1release_ppc power macintosh powerpc ' config_args='-de' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include', optimize='-O3', cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include' ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build 1495)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /usr/lib libs=-ldbm -ldl -lm -lc perllibs=-ldl -lm -lc libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO Built under darwin Compiled at Sep 13 2006 20:15:49 @INC: /usr/local/lib/perl5/5.8.8/darwin-2level /usr/local/lib/perl5/5.8.8 /usr/local/lib/perl5/site_perl/5.8.8/darwin-2level /usr/local/lib/perl5/site_perl/5.8.8 /usr/local/lib/perl5/site_perl/5.8.7/darwin-2level /usr/local/lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl/5.8.4/darwin-2level /usr/local/lib/perl5/site_perl/5.8.4 /usr/local/lib/perl5/site_perl . Darwin Macintosh.local 8.8.0 Darwin Kernel Version 8.8.0: Fri Sep 8 17:18:57 PDT 2006; root:xnu-792.12.6.obj~1/RELEASE_PPC Power Macintosh powerpc
# -*- perl -*- use strict; use warnings; use Test::More qw(no_plan); use_ok( 'Data::Dumper' ); my @lines; my $output = 'output.txt'; open my $FH, $output or die "Unable to open $output for reading"; while (<$FH>) { chomp; push @lines, $_; } close $FH or die "Unable to close $output"; print STDERR Dumper \@lines;
This is a consequence of "use_ok('Carp')" loading Carp at run time rather than compile time as "use Carp" does. The result is that it doesn't know that croak() is a function name. You can see this with the following: eval "use Carp"; croak "foo"; If you instead do 'croak("foo")' it works as there's no ambiguity. There are several work arounds. First is to wrap your use_ok() calls in a BEGIN block. Another is to use the very clever ok.pm module, "use ok 'Carp'", which does load Carp at compile-time. Finally, you can put parens around your function calls. Sorry for the confusion, its pretty common. The use_ok() docs discuss this and show examples with a BEGIN wrapper. I might absorb ok.pm into the distribution and discourage use_ok().
This is a consequence of "use_ok('Carp')" loading Carp at run time rather than compile time as "use Carp" does. The result is that it doesn't know that croak() is a function name. You can see this with the following: eval "use Carp"; croak "foo"; If you instead do 'croak("foo")' it works as there's no ambiguity. There are several work arounds. First is to wrap your use_ok() calls in a BEGIN block. Another is to use the very clever ok.pm module, "use ok 'Carp'", which does load Carp at compile-time. Finally, you can put parens around your function calls. Sorry for the confusion, its pretty common. The use_ok() docs discuss this and show examples with a BEGIN wrapper. I might absorb ok.pm into the distribution and discourage use_ok().