hey all,
Ive been doing hoplite type stuff on B::Concise, so I figured Id come here, shield & spear in hand, to seek some free help.
If you build bleadperl, please apply this patch, and maybe rebuild with -Uuseperlio.
(sh Configure -des -O -Uuseperlio) I think.
For me, the patch fixes this:
linux [stdio ]-DDEBUGGING -Uuseperlio../ext/B/t/concise.t....................FAILED 32-38 ../ext/B/t/optree_check.t...............FAILED 2-3 5 16 18-20 22-25 ../ext/B/t/optree_concise.t.............FAILED 2-3 6-11 20-24 ../ext/B/t/optree_samples.t.............FAILED 3-7 9-10 12 ../ext/B/t/optree_sort.t................FAILED 2 4 6 8 10-11 ../ext/B/t/optree_varinit.t.............FAILED 2-5 10-12 16-18
(see 'stdio still supported?' in p5p)
Patch is pretty trivial all in all, but a handful of success reports here will save our pumpking(s) a few precious test/integrate cycles.
Test Strategy etc..
In my recent B::Concise work, I added ext/B/t/OptreeCheck.pm It CREATES a test framework, and as such could stand a second round of scrutiny, b4 it becomes baggage in 5.10
does it plug into existing frameworks acceptably ? are there improvements/extensions to make ? does it go the right direction ? are there any best practices latent here (or bad ones) ?
Frankly, theres cruft there, esp wrt arg handling. arg handling in tests is not currently used anywhere else in core TMK, so this represents a precedent in some sense, and could stand judicial review by some appellate court. (dont take the analogy too literally, legislation might be closer)
Core Arg handling Strawman.
could stuff test args into MANIFEST, after filename of each test which should have specific defaults.
ex:
ext/B/t/OptreeCheck.pm optree comparison tool ext/B/t/optree_check.t test OptreeCheck apparatus ext/B/t/optree_concise.t more B::Concise tests
ext/B/t/run_offense_example.t ARGS: -quarterback=sneak -slotback=inmotion hut hut hike
Now, if this gets warnocked ... ;-)
tia, jimc
ps: my favorite 'prove' feature is how it tree-globs for tests. (ie find . ) ie its granularity
ottomh: (off the top of my head) (probly should be separate email :-O and researched for 5 min too <:-)
1. could prove check -x ./perl, and use that in preference to $PATH perl ? perhaps also automatically adding -Ilib
eval "exec ./perl -Ilib @ARGV" if -x './perl' and $ENV{BLEAD};
Only in ../bleadperl: config.sh~ diff -ru ../bleadperl/ext/B/B/Concise.pm bc.noperlio/ext/B/B/Concise.pm --- ../bleadperl/ext/B/B/Concise.pm Tue Apr 6 01:50:52 2004 +++ bc.noperlio/ext/B/B/Concise.pm Thu May 6 16:15:00 2004 @@ -107,8 +107,11 @@ sub walk_output { # updates $walkHandle my $handle = shift; if (ref $handle eq 'SCALAR') { + require Config; + die "no perlio in this build, can't call walk_output (\\\$scalar)\n" + unless $Config::Config{useperlio}; # in 5.8+, open(FILEHANDLE,MODE,REFERENCE) writes to string - open my $tmp, '>', $handle; # but cant re-set an existing filehandle + open my $tmp, '>', $handle; # but cant re-set existing STDOUT $walkHandle = $tmp; # so use my $tmp as intermediate var return; } @@ -1323,7 +1326,8 @@ in the new style. B<walk_output> lets you change the print destination from STDOUT to -another open filehandle, or into a string passed as a ref. +another open filehandle, or (unless you've built with -Uuseperlio) +into a string passed as a ref. walk_output(\my $buf); my $walker = B::Concise::compile('-concise','funcName', \&aSubRef); diff -ru ../bleadperl/ext/B/t/concise.t bc.noperlio/ext/B/t/concise.t --- ../bleadperl/ext/B/t/concise.t Tue Apr 6 01:50:52 2004 +++ bc.noperlio/ext/B/t/concise.t Thu May 6 16:15:00 2004 @@ -44,12 +44,6 @@ ## walk_output argument checking -# test that walk_output accepts a HANDLE arg -foreach my $foo (\*STDOUT, \*STDERR) { - eval { walk_output($foo) }; - is ($@, '', "walk_output() accepts STD* " . ref $foo); -} - # test that walk_output rejects non-HANDLE args foreach my $foo (undef, 0, "string",[], {}) { eval { walk_output($foo) }; @@ -66,13 +60,24 @@ eval { walk_output($foo) }; is ($@, '', "walk_output() accepts obj that can print"); -# now test a ref to scalar -eval { walk_output(\my $junk) }; -is ($@, '', "walk_output() accepts ref-to-sprintf target"); - -$junk = "non-empty"; -eval { walk_output(\$junk) }; -is ($@, '', "walk_output() accepts ref-to-non-empty-scalar"); +# test that walk_output accepts a HANDLE arg +SKIP: { + skip("no perlio in this build", 4) + unless $Config::Config{useperlio}; + + foreach my $foo (\*STDOUT, \*STDERR) { + eval { walk_output($foo) }; + is ($@, '', "walk_output() accepts STD* " . ref $foo); + } + + # now test a ref to scalar + eval { walk_output(\my $junk) }; + is ($@, '', "walk_output() accepts ref-to-sprintf target"); + + $junk = "non-empty"; + eval { walk_output(\$junk) }; + is ($@, '', "walk_output() accepts ref-to-non-empty-scalar"); +} ## add_style my @stylespec; @@ -104,64 +109,67 @@ #### for content with doc'd options +SKIP: +{ # test output to GLOB, using perlio feature directly + skip "no perlio on this build", 18 + unless $Config::Config{useperlio}; -set_style_standard('concise'); # MUST CALL b4 output needed -my $func = sub{ $a = $b+42 }; - [EMAIL PROTECTED] = qw( - -basic -exec -tree -compact -loose -vt -ascii -main - -base10 -bigendian -littleendian - ); -foreach $opt (@options) { - walk_output(\my $out); - my $treegen = B::Concise::compile($opt, $func); - $treegen->(); - #print "foo:$out\n"; - isnt($out, '', "got output with option $opt"); -} - -## test output control via walk_output - -my $treegen = B::Concise::compile('-basic', $func); # reused - -{ # test output into a package global string (sprintf-ish) - our $thing; - walk_output(\$thing); - $treegen->(); - ok($thing, "walk_output to our SCALAR, output seen"); -} + set_style_standard('concise'); # MUST CALL b4 output needed + my $func = sub{ $a = $b+42 }; -{ # test output to GLOB, using perlio feature directly - skip 1, "no perlio on this build" unless $Config{useperlio}; + @options = qw( + -basic -exec -tree -compact -loose -vt -ascii -main + -base10 -bigendian -littleendian + ); + foreach $opt (@options) { + walk_output(\my $out); + my $treegen = B::Concise::compile($opt, $func); + $treegen->(); + #print "foo:$out\n"; + isnt($out, '', "got output with option $opt"); + } + + ## test output control via walk_output + + my $treegen = B::Concise::compile('-basic', $func); # reused + + { # test output into a package global string (sprintf-ish) + our $thing; + walk_output(\$thing); + $treegen->(); + ok($thing, "walk_output to our SCALAR, output seen"); + } + open (my $fh, '>', \my $buf); walk_output($fh); $treegen->(); ok($buf, "walk_output to GLOB, output seen"); -} -## Test B::Concise::compile error checking - -# call compile on non-CODE ref items -foreach my $ref ([], {}) { - my $typ = ref $ref; - walk_output(\my $out); - eval { B::Concise::compile('-basic', $ref)->() }; - like ($@, qr/^err: not a coderef: $typ/, - "compile detects $typ-ref where expecting subref"); - # is($out,'', "no output when errd"); # announcement prints -} + ## Test B::Concise::compile error checking -# test against a bogus autovivified subref. -# in debugger, it should look like: -# 1 CODE(0x84840cc) -# -> &CODE(0x84840cc) in ??? -sub nosuchfunc; -eval { B::Concise::compile('-basic', \&nosuchfunc)->() }; -like ($@, qr/^err: coderef has no START/, - "compile detects CODE-ref w/o actual code"); - -foreach my $opt (qw( -concise -exec )) { - eval { B::Concise::compile($opt,'non_existent_function')->() }; - like ($@, qr/unknown function \(main::non_existent_function\)/, - "'$opt' reports non-existent-function properly"); + # call compile on non-CODE ref items + foreach my $ref ([], {}) { + my $typ = ref $ref; + walk_output(\my $out); + eval { B::Concise::compile('-basic', $ref)->() }; + like ($@, qr/^err: not a coderef: $typ/, + "compile detects $typ-ref where expecting subref"); + # is($out,'', "no output when errd"); # announcement prints + } + + + # test against a bogus autovivified subref. + # in debugger, it should look like: + # 1 CODE(0x84840cc) + # -> &CODE(0x84840cc) in ??? + sub nosuchfunc; + eval { B::Concise::compile('-basic', \&nosuchfunc)->() }; + like ($@, qr/^err: coderef has no START/, + "compile detects CODE-ref w/o actual code"); + + foreach my $opt (qw( -concise -exec )) { + eval { B::Concise::compile($opt,'non_existent_function')->() }; + like ($@, qr/unknown function \(main::non_existent_function\)/, + "'$opt' reports non-existent-function properly"); + } } diff -ru ../bleadperl/ext/B/t/optree_check.t bc.noperlio/ext/B/t/optree_check.t --- ../bleadperl/ext/B/t/optree_check.t Tue Apr 6 01:50:52 2004 +++ bc.noperlio/ext/B/t/optree_check.t Thu May 6 16:15:00 2004 @@ -19,11 +19,14 @@ =cut -################## - ; - +use Config; plan tests => 5 + 19 + 14 * $gOpts{selftest}; # fudged +SKIP: { + skip "no perlio in this build", 5 + 19 + 14 * $gOpts{selftest} + unless $Config::Config{useperlio}; + + pass("REGEX TEST HARNESS SELFTEST"); checkOptree ( name => "bare minimum opcode search", @@ -233,6 +236,7 @@ checkOptree ( name => 'tree reftext is messy cut-paste', skip => 1); +} # skip __END__ diff -ru ../bleadperl/ext/B/t/optree_concise.t bc.noperlio/ext/B/t/optree_concise.t --- ../bleadperl/ext/B/t/optree_concise.t Tue Apr 6 01:50:52 2004 +++ bc.noperlio/ext/B/t/optree_concise.t Thu May 6 16:15:00 2004 @@ -8,8 +8,11 @@ # import checkOptree(), and %gOpts (containing test state) use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!! +use Config; -plan tests => 24; # need to set based on testing state +plan tests => 24; +SKIP: { +skip "no perlio in this build", 24 unless $Config::Config{useperlio}; $SIG{__WARN__} = sub { my $err = shift; @@ -442,6 +445,7 @@ 1 <;> nextstate(main 76 optree_concise.t:407) v ->2 EONT_EONT +} #skip __END__ diff -ru ../bleadperl/ext/B/t/optree_samples.t bc.noperlio/ext/B/t/optree_samples.t --- ../bleadperl/ext/B/t/optree_samples.t Wed Apr 7 02:51:45 2004 +++ bc.noperlio/ext/B/t/optree_samples.t Thu May 6 16:15:00 2004 @@ -6,8 +6,10 @@ require './test.pl'; } use OptreeCheck; - +use Config; plan tests => 13; +SKIP: { + skip "no perlio in this build", 13 unless $Config::Config{useperlio}; pass("GENERAL OPTREE EXAMPLES"); @@ -454,6 +456,8 @@ # 6 <@> leave[1 ref] vKP/REFC EONT_EONT +} # skip + __END__ ####################################################################### diff -ru ../bleadperl/ext/B/t/optree_sort.t bc.noperlio/ext/B/t/optree_sort.t --- ../bleadperl/ext/B/t/optree_sort.t Tue Apr 6 01:50:52 2004 +++ bc.noperlio/ext/B/t/optree_sort.t Thu May 6 16:15:00 2004 @@ -6,9 +6,12 @@ require './test.pl'; } use OptreeCheck; - +use Config; plan tests => 11; +SKIP: { +skip "no perlio in this build", 11 unless $Config::Config{useperlio}; + pass("SORT OPTIMIZATION"); checkOptree ( name => 'sub {sort @a}', @@ -288,6 +291,7 @@ # a <1> leavesub[1 ref] K/REFC,1 EONT_EONT +} #skip __END__ diff -ru ../bleadperl/ext/B/t/optree_varinit.t bc.noperlio/ext/B/t/optree_varinit.t --- ../bleadperl/ext/B/t/optree_varinit.t Tue Apr 6 01:50:52 2004 +++ bc.noperlio/ext/B/t/optree_varinit.t Thu May 6 16:15:00 2004 @@ -6,8 +6,11 @@ require './test.pl'; } use OptreeCheck; - +use Config; plan tests => 22; +SKIP: { +skip "no perlio in this build", 22 unless $Config::Config{useperlio}; + pass("OPTIMIZER TESTS - VAR INITIALIZATION"); checkOptree ( name => 'sub {my $a}', @@ -378,5 +381,7 @@ # 8 <@> leave[1 ref] vKP/REFC EONT_EONT +} #skip + __END__ diff -ru ../bleadperl/pod/perlfunc.pod bc.noperlio/pod/perlfunc.pod --- ../bleadperl/pod/perlfunc.pod Tue May 4 09:08:15 2004 +++ bc.noperlio/pod/perlfunc.pod Thu May 6 16:20:12 2004 @@ -2908,7 +2908,9 @@ to the temporary file first. You will need to seek() to do the reading. -File handles can be opened to "in memory" files held in Perl scalars via: +Since v5.8.0, perl has built using PerlIO by default. Unless you've +changed this (ie Configure -Uuseperlio), you can open file handles to +"in memory" files held in Perl scalars via: open($fh, '>', \$variable) || .. @@ -2971,6 +2973,8 @@ } } +See L<perliol/> for detailed info on PerlIO. + You may also, in the Bourne shell tradition, specify an EXPR beginning with C<< '>&' >>, in which case the rest of the string is interpreted as the name of a filehandle (or file descriptor, if numeric) to be Only in bc.noperlio/pod: perlfunc.pod~ Only in ../bleadperl/t: TEST~ Only in ../bleadperl/t: TestInit.pm~