Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Test::More test names?

by zigdon (Deacon)
on Nov 08, 2005 at 17:57 UTC ( #506821=perlquestion: print w/replies, xml ) Need Help??

zigdon has asked for the wisdom of the Perl Monks concerning the following question:

Am I missing something here? I set up a bunch of tests using Test::More. But for some reason, when a test fails, I don't get the test name, just the test number and line number. Did I misunderstand the whole idea of $test_name? The test is something like this:
foreach (@items) { ... a lot of perl code ... unless (some condition) { $err = "Splunk is missing from Foobar"; } } if ($err) { # <------- line 60 fail($err); } else { pass("Fancy code passed"); }
$ ./t/test.pl t/DB/SearchPart.t + t/DB/SearchPart....NOK 3 + # Failed test (t/DB/SearchPart.t at line 60) # Looks like you failed 1 test of 3. t/DB/SearchPart....dubious + Test returned status 1 (wstat 256, 0x100) Scalar found where operator expected at (eval 158) line 1, near "'int' + $__val" (Missing operator before $__val?) DIED. FAILED test 3 Failed 1/3 tests, 66.67% okay Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t/DB/SearchPart.t 1 256 3 1 33.33% 3 Failed 1/1 test scripts, 0.00% okay. 1/3 subtests failed, 66.67% okay.

-- zigdon

Replies are listed 'Best First'.
Re: Test::More test names?
by xdg (Monsignor) on Nov 08, 2005 at 18:24 UTC

    The names only print out if you use "verbose" mode. See the "-v" flag for prove, the description of the HARNESS_VERBOSE environment flag in Test::Harness and ways to set that automatically with Module::Build and ExtUtils::MakeMaker.

    As a side note, you may want to write your test like this:

    foreach (@items) { ... a lot of perl code ... unless (some condition) { $err = "Splunk is missing from Foobar"; } } ok(! $err,"Fancy code") or diag $err;

    Using pass and fail is generally a more tedious way to work with Test::More.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      The names also print if you run one test at a time:
      make; perl -I blib/lib t/test_name.t
      Not only do you see the names of the tests, but you save time if your suite takes a long time and only one or two test files have failing tests.

      Phil

Re: Test::More test names?
by dragonchild (Archbishop) on Nov 08, 2005 at 18:16 UTC
    Try
    if ( $err ) { ok( 0, $err ); else { ok( 1, "Fancy code passed" ); } # or, for the golfers amongst you ... ok( $err ? ( 0, $err ) : ( 1, "Fancy code passed" ) );

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Test::More test names?
by Animator (Hermit) on Nov 08, 2005 at 18:22 UTC

    I don't know what exactly your problem is... My initial guess (read: when I started writing this) was something else then dragonchild wrote... So this post might be irrelevant.

    First question: are you sure the syntax of t/DB/SearchPart.t is correct? As in, did you run perl -c t/DB/SearchPart.t?

    Here are some questions: What is t/test.pl ? Did you create the script? Did you download it? What does it do?

    If you really can't figure it out then you should try to reproduce the same 'problem' and post that code here. If you can't do that then you can try posting all the code... (If it is too long then you can use the readmore-tags to hide the irrelevant parts)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://506821]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2019-05-24 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (147 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!