I encourage wisdom seekers to present sample data and use Test::More in the example code of their question. Let's look at some examples.
#!/usr/bin/perl use strict; use warnings; use Test::More; my $data = "Some string here"; my $regex = qr/ fancy regex here /mxis; like( $data, $regex, "Matching my regex" ); done_testing;
Your code fails, but readers can read this code and run it and make changes that will make it pass.
#!/usr/bin/perl use strict; use warnings; use Test::More; sub mysub { return; } ok( mysub(), "Should return true" ); done_testing;
Use __DATA__.
#!/usr/bin/perl use strict; use warnings; use Test::More; my $wanted_matches = 2; my $actual_matches = 0; my $regex = qr/ fancy regex here /mxis; while ( my $line = <DATA> ) { chomp $line; if ( $line =~ $regex ){ $actual_matches++; } } ok( $wanted_matches == $actual_matches, "Correct number of matches" ); done_testing; __DATA__ line one..... line two..... .... line ten.....
Neil Watson
watson-wilson.ca
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to ask better questions using Test::More and sample data
by haukex (Bishop) on Oct 12, 2017 at 10:31 UTC | |
Re: How to ask better questions using Test::More and sample data
by stevieb (Canon) on Feb 09, 2016 at 02:21 UTC | |
by Anonymous Monk on Feb 09, 2016 at 02:39 UTC |