Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

[RFC] Discipulus's step by step tutorial on module creation with tests and git -- second part

by Discipulus (Canon)
on Dec 19, 2018 at 11:16 UTC ( [id://1227455]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    =head1 EXPORT
    
    ...
    
    =cut
    
  2. or download this
    =head1 SUBROUTINES
    
    ...
    This function accepts a string or a list (range) and returns an array.
    In the string form the accepted characters are: positive integers, dot
    +s, commas and spaces. Every space will be removed.
    
  3. or download this
    git-client> git status
    
    ...
    [master a6dc557] initial POD to document validate function
     1 file changed, 5 insertions(+), 6 deletions(-)
    
  4. or download this
    # not allowed a lone .
        croak "invalid range [$range] (single .)!" if $range =~ /[^.]+\.{1
    +}[^.]+/;
    # not allowed more than 2 .
        croak "invalid range [$range] (more than 2 .)!" if $range =~ /[^.]
    ++\.{3}/;
    
  5. or download this
    sub validate{
        my $range;
    ...
        return @range;
    }
    
  6. or download this
    note ("start checks about incorrect dots in string");
    
    ...
                "expected to die with a lone dot";
    
  7. or download this
    shell> prove -l -v ./t/01-validate.t
    
    ...
    Files=1, Tests=5,  0 wallclock secs ( 0.06 usr +  0.03 sys =  0.09 CPU
    +)
    Result: PASS
    
  8. or download this
    foreach my $string ( '1.2', '0..2,5.6,8', '1,2,.,3', '.' ){
        dies_ok { Range::Validator::validate( $string ) }
                "expected to die with a lone dot in range [$string]";
    }
    
  9. or download this
    shell> prove -l -v ./t/01-validate.t
    
    ...
    Files=1, Tests=7,  0 wallclock secs ( 0.02 usr +  0.03 sys =  0.05 CPU
    +)
    Result: FAIL
    
  10. or download this
    # not allowed a lone .
        croak "invalid range [$range] (single .)!" if $range =~ /(?<!\.)\.
    +(?!\.)/;
    
  11. or download this
    foreach my $string ( '1.2', '0..2,5.6,8', '1,2,.,3', '.', '1.', '.1' )
    +{
        dies_ok { Range::Validator::validate( $string ) }
                "expected to die with a lone dot in range [$string]";
    }
    
  12. or download this
    foreach my $newstring ( '1...3', '1,3...5','...', '1...', '...2' ){
        dies_ok { Range::Validator::validate( $newstring ) }
                "expected to die with three dots in range [$newstring]";
    }
    
  13. or download this
    shell> prove -l -v ./t/01-validate.t
    
    ...
    Files=1, Tests=14,  1 wallclock secs ( 0.03 usr +  0.03 sys =  0.06 CP
    +U)
    Result: PASS
    
  14. or download this
    sub validate{
        my $range;
    ...
        return @range;
    }
    
  15. or download this
    #!perl
    use 5.006;
    ...
                "expected to die with three dots in range [$newstring]";
    }
    
  16. or download this
    git-client> git status
    
    ...
       5083ec3..169809c  master -> master
    
  17. or download this
         # spot reverse ranges like 27..5
         if ($range =~ /[^.]\.\.[^.]/){
    ...
            }
        }
    
  18. or download this
        # eval the range
        @range = eval ($range);
    ...
        @range = sort{ $a &lt;=&gt; $b } keys %single;    # -- new line
        return @range;
    
  19. or download this
    sub validate{
        my $range;
    ...
        return @range;
    }
    
  20. or download this
    git-client> git log HEAD --oneline
    
    ...
    49a0690 moved POD, removed -T
    1788c12 module-starter created content
    
  21. or download this
    foreach my $reversed ('3..1,7..9','1..4,7..5','3..4, 7..5','0..2,27..5
    +'){
        dies_ok { Range::Validator::validate( $reversed ) } "expected to d
    +ie with reverse range [$reversed]";
    }
    
  22. or download this
    my %test = (
        '1,1..3'    => [(1,2,3)],
    ...
        );
    }
    
  23. or download this
    ok 15 - expected to die with reverse range [3..1,7..9]
    ok 16 - expected to die with reverse range [1..4,7..5]
    ...
    ok 24 - correct result for range [8,9,1..2]
    ok 25 - correct result for range [1..5,3]
    
  24. or download this
    git-client> git log HEAD --oneline
    
    ...
    --
    *+ [master] test for overlappped or unordered ranges
    
  25. or download this
    # otherwise we received a list
        else{
            ...
        }
    
  26. or download this
    sub validate{
        my $range;
    ...
        return @range;
    }
    
  27. or download this
    Every string with occurences of a lone dot or more than two dots will 
    +be rejected causing an exception in the calling program.
    
    Reverse ranges like in <code>'3..1'
    
  28. or download this
    note ("starting test of list form");
    
    ...
        );
    }
    
  29. or download this
    # all actions performed, no need to call our validate sub
    actions_to_activate_account();
    ...
    my @valid_range = Range::Validator::validate( @actions );
    actions_to_activate_account( @valid_range );
    
  30. or download this
        # assume we have a string if we receive only one argument
        if ( @_ == 1){
    ...
        }
    
  31. or download this
    BUILD_REQUIRES => {
            'Test::More'         => '0',
    ...
            'Capture::Tiny'       => '0',        # -- new line
        },
    
  32. or download this
    note ("test of warnings emitted");
    {    
    ...
        like( $stderr, qr/^Empty list passed in/, "right warning for empty
    + list if \$Range::Validator::WARNINGS");    
        
    }
    
  33. or download this
    =head1 ENABLE WARNINGS
    
    If the <code>$Range::Validator::WARNINGS
    
  34. or download this
    shell> prove ./t/manifest.t
    
    ...
    Files=1, Tests=0,  0 wallclock secs ( 0.03 usr +  0.01 sys =  0.05 CPU
    +)
    Result: NOTESTS
    
  35. or download this
    shell> prove ./t/manifest.t
    
    ...
    #     expected: 1
    # The following files are not named in the MANIFEST file:  .... # MANY
    + LINES MORE..
    
  36. or download this
    shell> prove ./t/manifest.t
    
    ...
    /path/to/your/module/xt/boilerplate.t
    
    ...
    
  37. or download this
    shell> prove ./xt/boilerplate.t
    
    ...
    Files=1, Tests=3,  1 wallclock secs ( 0.03 usr +  0.03 sys =  0.06 CPU
    +)
    Result: PASS
    
  38. or download this
    shell> prove ./t/manifest.t
    
    ...
    Files=1, Tests=1,  1 wallclock secs ( 0.02 usr +  0.03 sys =  0.05 CPU
    +)
    Result: PASS
    
  39. or download this
    shell> prove -l -v ./t/pod.t
    
    ...
    Files=1, Tests=1,  0 wallclock secs ( 0.03 usr +  0.02 sys =  0.05 CPU
    +)
    Result: PASS
    
  40. or download this
    git-client> git log HEAD --oneline --reverse
    
    ...
    e3feb61 removed xt/boilerplate.t
    3c0da4f (HEAD -> master, YourGithubLogin/master) modified README
    
  41. or download this
    package        # hide from CPAN indexer
        testhelper;
    
  42. or download this
    use lib '.';
    use t::testhelper;
    

Log In?
Username:
Password:

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

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

    No recent polls found