Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
First shot at own-dogfooding prove
- Loading branch information
Tadeusz Sośnierz
committed
Mar 16, 2013
1 parent
deb3354
commit e9d6331
Showing
7 changed files
with
227 additions
and
2 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
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 | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name" : "Test::Harness", | ||
| "version" : "*", | ||
| "description" : "Read TAP output", | ||
| "depends" : [], | ||
| "source-url" : "git://github.com/tadzik/Test-Harness.git" | ||
| } |
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 | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/usr/bin/env perl6 | ||
| use lib 'blib/lib'; | ||
| use Test::Harness; | ||
|
|
||
| sub MAIN(*@files is copy, :$e = 'perl6', Bool :$Q) { | ||
| my %results; | ||
| my $start = time; | ||
| +@files or @files = 't'; | ||
|
|
||
| sub summary { | ||
| my $files = +%results.keys; | ||
| my $tests = [+] %results.values.map({ .tests-ran }); | ||
| my $passes = [+] %results.values.map({ .tests-passed }); | ||
| my $result = $tests == $passes ?? 'PASS' !! 'FAIL'; | ||
| my $secs = time - $start; | ||
| say "Files=$files, Tests=$tests, $secs wallclock secs"; | ||
| say "Result: $result"; | ||
| } | ||
|
|
||
| while +@files { | ||
| my $f = @files.shift; | ||
| if $f.IO.d { | ||
| @files.push(dir($f).grep({ ~$_ !~~ /^ '.'/})\ | ||
| .map({ $_.path })); | ||
| next; | ||
| } | ||
| next unless $f ~~ /'.t' $/; | ||
| my $th = Test::Harness::File.new; | ||
| print "$f ... " unless $Q; | ||
| my @lines = lines(qqx[$e $f]); | ||
| for @lines { | ||
| $th.line($_) | ||
| } | ||
| %results{$f} = $th; | ||
| say $th.short-summary unless $Q; | ||
| } | ||
|
|
||
| unless $Q { | ||
| if all(%results.values.map({ .successful })) { | ||
| say "All tests successful." | ||
| } else { | ||
| say "\nTest Summary Report"; | ||
| say '-------------------'; | ||
| } | ||
| summary(); | ||
| } | ||
|
|
||
| if all(%results.values.map({ .successful })) { | ||
| exit 0; | ||
| } else { | ||
| exit 1; | ||
| } | ||
| } |
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 | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| use v6; | ||
|
|
||
| class Test::Harness::File { | ||
| has Int $.todos = 0; | ||
| has Int $.todos-passed = 0; | ||
| has Int $.tests-ran = 0; | ||
| has Int $.tests-passed = 0; | ||
| has Int $.tests-skipped = 0; | ||
| has Int $.tests-planned = 0; | ||
| has &.callback; | ||
|
|
||
| method line (Str $line) { | ||
| if $line ~~ /^ '1..' $<plan>=[\d+] $/ { | ||
| if $!tests-planned { | ||
| die "Plan declared twice" | ||
| } | ||
| # TODO check for plan appearing in the middle of the output | ||
| $!tests-planned = +$<plan>; | ||
| } | ||
| unless $line ~~ /^ 'not '? 'ok'»/ { | ||
| return # doesn't concern us | ||
| } | ||
| $line ~~ /:r ^ $<fail>=['not ']? | ||
| 'ok' | ||
| \h* | ||
| $<num>=[\d*] | ||
| \h* | ||
| $<description>=[ <-[#]>* ]? | ||
| [ | ||
| '# ' | ||
| [ $<todo>=[:i 'TODO'] || $<skip>=[:i 'SKIP'] ] | ||
| [ ' ' $<reason>=[\N+] ]? | ||
| ]? | ||
| $/; | ||
| unless $/ { | ||
| die "Malformed TAP output" | ||
| } | ||
|
|
||
| $!tests-ran++; | ||
| if ~$<num> ne '' and +$<num> != $!tests-ran { | ||
| die "Wrong test number" | ||
| } | ||
| if ~$<todo> ne '' { | ||
| $!todos++; | ||
| $!tests-passed++; | ||
| if ~$<fail> eq '' { | ||
| $!todos-passed++; | ||
| } | ||
| } elsif ~$<skip> ne '' { | ||
| $!tests-skipped++; | ||
| $!tests-passed++; | ||
| } elsif ~$<fail> eq '' { | ||
| $!tests-passed++; | ||
| } | ||
| } | ||
|
|
||
| method short-summary { | ||
| if self.successful { | ||
| return 'ok'; | ||
| } else { | ||
| return "Failed {$!tests-ran - $!tests-passed}" | ||
| ~ "/{$!tests-ran} subtests"; | ||
| } | ||
| } | ||
|
|
||
| method successful { | ||
| $!tests-ran == $!tests-passed | ||
| } | ||
| } |
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 | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| use v6; | ||
| use Test; | ||
| use Test::Harness; | ||
| plan 39; | ||
|
|
||
| my $h = Test::Harness::File.new; | ||
| $h.line('1..15'); | ||
| is $h.tests-planned, 15, 'plan parsed correctly'; | ||
| dies_ok { $h.line('1..30') }, 'can only plan once'; | ||
|
|
||
| $h.line('ok'); | ||
| diag 'testing bare ok'; | ||
| is $h.tests-ran, 1; | ||
| is $h.tests-passed, 1; | ||
| is $h.tests-skipped, 0; | ||
| is $h.todos, 0; | ||
| is $h.successful, True, 'it went okay'; | ||
|
|
||
| $h.line('not ok'); | ||
| diag 'testing bare not ok'; | ||
| is $h.tests-ran, 2; | ||
| is $h.tests-passed, 1; | ||
| is $h.tests-skipped, 0; | ||
| is $h.todos, 0; | ||
| is $h.successful, False, 'it went okay... NOT'; | ||
|
|
||
| diag 'garbage input'; | ||
| lives_ok { | ||
| $h.line('# I am a comment'); | ||
| $h.line('foo baz'); | ||
| $h.line('notok'); | ||
| } | ||
| is $h.tests-ran, 2; | ||
| is $h.tests-passed, 1; | ||
| is $h.tests-skipped, 0; | ||
| is $h.todos, 0; | ||
|
|
||
| diag 'wrong test number'; | ||
| dies_ok { $h.line('ok 1') } | ||
|
|
||
| diag 'basic legitimate input'; | ||
| $h = Test::Harness::File.new; | ||
| lives_ok { | ||
| $h.line('ok 1'); | ||
| $h.line('not ok 2'); | ||
| $h.line('ok 3 - test description'); | ||
| $h.line('not ok 4 test description'); | ||
| } | ||
| is $h.tests-ran, 4; | ||
| is $h.tests-passed, 2; | ||
| is $h.tests-skipped, 0; | ||
| is $h.todos, 0; | ||
| is $h.successful, False, 'it went okay... NOT'; | ||
|
|
||
| diag 'todoed tests'; | ||
| $h = Test::Harness::File.new; | ||
| lives_ok { | ||
| $h.line('ok 1 # TODO'); | ||
| $h.line('ok 2 # TODO foo'); | ||
| $h.line('not ok 3 # ToDO'); | ||
| $h.line('not ok 4 # TODo foo'); | ||
| } | ||
| is $h.tests-ran, 4, '4 tests ran'; | ||
| is $h.tests-passed, 4, '4 tests passed'; | ||
| is $h.todos, 4, '4 todoed tests'; | ||
| is $h.todos-passed, 2, '2 todos passed'; | ||
| is $h.successful, True, 'it went okay'; | ||
|
|
||
| diag 'skipped tests'; | ||
| $h = Test::Harness::File.new; | ||
| lives_ok { | ||
| $h.line('ok 1 # SKIP'); | ||
| $h.line('ok 2 # SKIP foo'); | ||
| $h.line('not ok 3 # skip'); | ||
| $h.line('not ok 4 # skip foo'); | ||
| } | ||
| is $h.tests-ran, 4; | ||
| is $h.tests-passed, 4; | ||
| is $h.todos, 0; | ||
| is $h.todos-passed, 0; | ||
| is $h.tests-skipped, 4; | ||
| is $h.successful, True, 'it went okay'; | ||
|
|
||
| dies_ok { $h.line('ok foo bar #dupa') }, 'malformed TAP'; | ||
|
|
||
| $h = Test::Harness::File.new; | ||
| lives_ok { $h.line("ok 1 - JSON string «{}» parsed") }, | ||
| 'does not fail on funny 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