Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out the test file code into a module
- Loading branch information
Anthony Parsons
committed
Feb 25, 2011
1 parent
05f2a2c
commit b674b5a
Showing
13 changed files
with
176 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
module TestFiles; | |||
use Test; | |||
|
|||
our sub run( | |||
Callable $test-block, | |||
Str $input-dir = "$*PROGRAM_NAME.input", | |||
Str $output-dir = "$*PROGRAM_NAME.output", | |||
Int $tests-per-block = 1, | |||
Int $add-to-plan = 0 | |||
) { | |||
my @files = dir($output-dir); | |||
plan $tests-per-block * @files + $add-to-plan; | |||
|
|||
for @files -> $filename { | |||
my $in = open("$input-dir/$filename"); | |||
my $out = open("$output-dir/$filename"); | |||
|
|||
$test-block(:$in, :$out, :$filename); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,25 +1,13 @@ | |||
#!/usr/bin/env perl6 | #!/usr/bin/env perl6 | ||
use v6; | use v6; | ||
use TestFiles; | |||
use Test; | use Test; | ||
use Text::Tabs; | use Text::Tabs; | ||
|
|
||
BEGIN { | BEGIN { | ||
@*INC.push('lib'); | @*INC.push('lib'); | ||
} | } | ||
|
|
||
my @tests = dir("$*PROGRAM_NAME.output"); | TestFiles::run(sub ($in, $out, $filename) { | ||
|
is expand($in.slurp), $out.slurp, $filename; | ||
plan 1 + @tests; | }); | ||
|
|||
is +dir("$*PROGRAM_NAME.input"), | |||
+@tests, | |||
'Sanity check: number of input files = output files'; | |||
|
|||
for @tests -> $filename { | |||
my $in = open("$*PROGRAM_NAME.input/$filename").slurp; | |||
my $out = open("$*PROGRAM_NAME.output/$filename").slurp; | |||
|
|||
is expand($in), | |||
$out, | |||
$filename; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,25 +1,13 @@ | |||
#!/usr/bin/env perl6 | #!/usr/bin/env perl6 | ||
use v6; | use v6; | ||
use TestFiles; | |||
use Test; | use Test; | ||
use Text::Wrap; | use Text::Wrap; | ||
|
|
||
BEGIN { | BEGIN { | ||
@*INC.push('lib'); | @*INC.push('lib'); | ||
} | } | ||
|
|
||
my @tests = dir("$*PROGRAM_NAME.output"); | TestFiles::run(sub ($in, $out, $filename) { | ||
|
is fill(' ' x 4, ' ', $in.slurp), $out.slurp, $filename; | ||
plan 1 + @tests; | }); | ||
|
|||
is +dir("$*PROGRAM_NAME.input"), | |||
+@tests, | |||
'Sanity check: number of input files = output files'; | |||
|
|||
for @tests -> $filename { | |||
my $in = open("$*PROGRAM_NAME.input/$filename").slurp; | |||
my $out = open("$*PROGRAM_NAME.output/$filename").slurp; | |||
|
|||
is fill(' ', ' ', $in), | |||
$out, | |||
$filename; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,37 @@ | |||
#!/usr/bin/env perl6 | |||
use v6; | |||
use Test; | |||
use Text::Wrap; | |||
|
|||
BEGIN { | |||
@*INC.push('lib'); | |||
} | |||
|
|||
plan 3; | |||
|
|||
$Text::Wrap::huge = 'overflow'; | |||
my %default = ( | |||
separator => $Text::Wrap::separator, | |||
separator2 => $Text::Wrap::separator2, | |||
); | |||
|
|||
my $input = < | |||
This is a word that is too long to wrap to make sure that the program does not crash and burn | |||
>.join('_'); | |||
my $output = "zzz$input"; | |||
|
|||
is wrap('zzz', 'yyy', $input), | |||
$output, | |||
'Overflow handling'; | |||
|
|||
$Text::Wrap::separator = '='; | |||
is wrap('zzz', 'yyy', $input), | |||
$output, | |||
'Overflow handling with $separator'; | |||
$Text::Wrap::separator = %default<separator>; | |||
|
|||
$Text::Wrap::separator2 = '='; | |||
is wrap('zzz', 'yyy', $input), | |||
$output, | |||
'Overflow handling with $separator2'; | |||
$Text::Wrap::separator2 = %default<separator2>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,44 +1,31 @@ | |||
#!/usr/bin/env perl6 | #!/usr/bin/env perl6 | ||
use v6; | use v6; | ||
use TestFiles; | |||
use Test; | use Test; | ||
use Text::Wrap; | use Text::Wrap; | ||
|
|
||
BEGIN { | BEGIN { | ||
@*INC.push('lib'); | @*INC.push('lib'); | ||
} | } | ||
|
|
||
my @tests = dir("$*PROGRAM_NAME.output"); | |||
|
|||
plan 2 + @tests * 2; | |||
|
|||
is +dir("$*PROGRAM_NAME.input"), | |||
+@tests, | |||
'Sanity check: number of input files = output files'; | |||
|
|||
$Text::Wrap::separator = '='; | $Text::Wrap::separator = '='; | ||
|
|
||
for @tests -> $filename { | TestFiles::run( | ||
my $in = open("$*PROGRAM_NAME.input/$filename").slurp; | tests-per-block => 2, | ||
my $out = open("$*PROGRAM_NAME.output/$filename").slurp; | test-block => sub ($in, $out, $filename) { | ||
|
my $in-str = $in.slurp; | ||
is wrap(' ', ' ', $in), | my $out-str = $out.slurp; | ||
$out, |
|
||
"$filename (as one string)"; | is wrap(' ', ' ', $in-str), | ||
|
$out-str, | ||
my @in = $in.split(/\n/); | "$filename - sep.t (as one string)"; | ||
|
|
||
# append "\n" to all entries but the last | # append "\n" to all lines but the last | ||
@in[0 ..^ @in-1] >>~=>> "\n"; | my @in = $in-str.split(/\n/); | ||
|
@in[0 ..^ @in-1] >>~=>> "\n"; | ||
is wrap(' ', ' ', @in), |
|
||
$out, | is wrap(' ', ' ', @in), | ||
"$filename (array of lines)"; | $out-str, | ||
} | "$filename - sep.t (array of lines)"; | ||
|
} | ||
$Text::Wrap::huge = 'overflow'; | ); | ||
my $tw = < | |||
This is a word that is too long to wrap to make sure that the program does not crash and burn | |||
>.join('_'); | |||
|
|||
is wrap('zzz', 'yyy', $tw), | |||
"zzz$tw"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,45 +1,31 @@ | |||
#!/usr/bin/env perl6 | #!/usr/bin/env perl6 | ||
use v6; | use v6; | ||
use TestFiles; | |||
use Test; | use Test; | ||
use Text::Wrap; | use Text::Wrap; | ||
|
|
||
BEGIN { | BEGIN { | ||
@*INC.push('lib'); | @*INC.push('lib'); | ||
} | } | ||
|
|
||
my @tests = dir("$*PROGRAM_NAME.output"); | |||
|
|||
plan 2 + @tests * 2; | |||
|
|||
is +dir("$*PROGRAM_NAME.input"), | |||
+@tests, | |||
'Sanity check: number of input files = output files'; | |||
|
|||
$Text::Wrap::separator2 = '='; | $Text::Wrap::separator2 = '='; | ||
|
|
||
for @tests -> $filename { | TestFiles::run( | ||
my $in = open("$*PROGRAM_NAME.input/$filename").slurp; | tests-per-block => 2, | ||
my $out = open("$*PROGRAM_NAME.output/$filename").slurp; | test-block => sub ($in, $out, $filename) { | ||
|
my $in-str = $in.slurp; | ||
is wrap(' ', ' ', $in), | my $out-str = $out.slurp; | ||
$out, |
|
||
"$filename (as one string)"; | is wrap(' ', ' ', $in-str), | ||
|
$out-str, | ||
# Test multiple string usage | "$filename - sep.t (as one string)"; | ||
my @in = $in.split(/\n/); |
|
||
|
# append "\n" to all lines but the last | ||
# append "\n" to all entries but the last | my @in = $in-str.split(/\n/); | ||
@in[0 ..^ @in-1] >>~=>> "\n"; | @in[0 ..^ @in-1] >>~=>> "\n"; | ||
|
|
||
is wrap(' ', ' ', @in), | is wrap(' ', ' ', @in), | ||
$out, | $out-str, | ||
"$filename (array of lines)"; | "$filename - sep.t (array of lines)"; | ||
} | } | ||
|
); | ||
$Text::Wrap::huge = 'overflow'; | |||
my $tw = < | |||
This is a word that is too long to wrap to make sure that the program does not crash and burn | |||
>.join('_'); | |||
|
|||
is wrap('zzz', 'yyy', $tw), | |||
"zzz$tw"; |
Oops, something went wrong.