Perl Testing: A Developer's Notebook by Ian Langworth, chromatic The unconfirmed error reports are from readers. They have not yet been approved or disproved by the author or editor and represent solely the opinion of the reader. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification This page was updated March 4, 2008. UNCONFIRMED errors and comments from readers: (3) 3rd line; On page 1, 3rd last line, you say 'if you have a C compiler', and then on page 3, 3rd line you say 'that has an appropriate compiler'. I think the text on page 3 was meant to read 'that does not have.' [14] 2nd "What About" Answer; "and add the following lines to the end of analyze_sentence.t:". Calculating the number of words in $sentence here, at the end of the script, will result in a failure because we are testing for 18 words. However, a few lines above, we changed $sentence to "Rampaging ideas flutter greedily.", which is four words. {14} second A: on page; as written test 6 in analyze_sentence.t will fail because @word will have 4 elements, not 18. To fix the example I made an amateurish change to this: #!perl use strict; use warnings; use Test::More tests =>6 ; my @subs = qw( words count_words ); #use_ok( 'AnalyzeSentence', @subs ); #BEGIN { use_ok( 'AnalyzeSentence', @subs, '$WORD_SEPARATOR' ) or exit;} #as example for testing variable $WORD_SEPARATOR BEGIN { my @subs = qw( words count_words ); use_ok( 'AnalyzeSentence', @subs, '$WORD_SEPARATOR' ) or exit; } can_ok( __PACKAGE__, 'words' ); can_ok( __PACKAGE__, 'count_words' ); my $sentence1 = 'Queen Esther, ruler of the Frog-Human Alliance, briskly devours a monumental ice cream sundae in her honor.'; my @words = words( $sentence1 ); ok( @words == 17, 'words( ) should return all words in sentence' ); my $sentence = 'Rampaging ideas flutter greedily.'; my $count = count_words( $sentence ); ok( $count == 4, 'count_words( ) should handle simple sentences' ); $WORD_SEPARATOR = qr/(?:\s|-)+/; @words = words( $sentence1 ); ok( @words == 18, '...respecting $WORD_SEPARATOR, if set' ); {15} Around the 3th line; The BEGIN statement errata is already posted, but it will still fail because the last defining of $sentence only has 4 words. In order to get the test right, the last three lines of analyze_sentence.t should be as shown below. Note that you need to type in once again the "Queen Esther" sentence because we want the word count to be 18 due to "Frog-Human" now being counted as two words. $sentence = 'Queen Esther, ruler of the Frog-Human Alliance, briskly devours a monumental ice cream sundae in her honor.'; $WORD_SEPARATOR = qr/(?:\s|-)+/; @words = words( $sentence ); ok( @words == 18, '... respecting $WORD_SEPARATOR, if set' ); [51] example - between.t; There is still an error using test_out() instead of test_pass(): > perl between.t 1..3 not ok 1 - simple alphabetical comparison # Failed test 'simple alphabetical comparison' # in between.t at line 14. # STDOUT is: # ok 1 - simple alphabetical comparison # # not: # simple alphabetical comparison # # as expected not ok 2 - simple numeric comparison # Failed test 'simple numeric comparison' # in between.t at line 19. # STDOUT is: # ok 1 - simple numeric comparison # # not: # simple numeric comparison # # as expected ok 3 - failed comparison with diagnostics (51) example - between.t; Further to my previous report regarding test_out(), the solution is to change the first two instances of test_out() to: test_out("ok 1 - $desc"); (54) 1st code example new_harness.pl; The following line in new_harness.pl reads... my %results = $strap->analyze_file( $file ); It should be... my $results = $strap->analyze_file( $file ); ---------------------------------------------------------------- The following line in new_harness.pl reads... printf <