Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Basic Testing Tutorial

by hippo (Bishop)
on Sep 11, 2019 at 10:32 UTC ( [id://11106010]=perltutorial: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    1..1
    ok 1 The expected file "foo" is present
    
  2. or download this
    use strict;
    use warnings;
    ...
    print "1..1\n";
    print localtime(time)->year > 1999 ? 'ok' : 'not ok';
    print " 1 Not in a previous century\n";
    
  3. or download this
    1..1
    ok 1 Not in a previous century
    
  4. or download this
    use strict;
    use warnings;
    ...
    use Test::Simple tests => 1;
    
    ok localtime(time)->year > 1999, 'Not in a previous century';
    
  5. or download this
    use strict;
    use warnings;
    ...
    use Test::More tests => 1;
    
    cmp_ok localtime(time)->_year, '>', 1999, 'Not in a previous century';
    
  6. or download this
    1..1
    not ok 1 - Not in a previous century
    ...
    #         >
    #     '1999'
    # Looks like you failed 1 test of 1.
    
  7. or download this
    use strict;
    use warnings;
    ...
    cmp_ok $now->_year, '>', 1999, 'Not in a previous century';
    is $now->time, $now->hms, 'The time() and hms() methods give the same 
    +result';
    like $now->fullday, qr/day$/, 'The dayname ends in "day"';
    
  8. or download this
    use strict;
    use warnings;
    ...
        skip 'Non-English locale', 1 unless substr ($ENV{LANG} // 'en', 0,
    + 2) eq 'en';
        like $now->fullday, qr/day$/, 'The dayname ends in "day"';
    }
    
  9. or download this
    plan tests => scalar @array;
    
  10. or download this
    done_testing ();
    exit;
    
  11. or download this
    $ prove /tmp/bar.t
    /tmp/bar.t .. 1/3 
    ...
      Non-zero exit status: 1
    Files=1, Tests=3,  0 wallclock secs ( 0.03 usr  0.00 sys +  0.06 cusr 
    + 0.01 csys =  0.10 CPU)
    Result: FAIL
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://11106010]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-19 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found