Skip to content
Browse files

First shot at own-dogfooding prove

  • Loading branch information...
1 parent deb3354 commit e9d6331a646b2b29639daaf5011794fed4a93049 @tadzik committed Mar 16, 2013
View
2 bootstrap.pl
@@ -39,7 +39,7 @@
%*ENV<PERL6LIB> ~= "{$env_sep}{cwd}/ext/Test__Mock/lib";
%*ENV<PERL6LIB> ~= "{$env_sep}{cwd}/lib";
-shell "perl6 bin/panda install File::Tools JSON::Tiny Test::Mock {cwd}";
+shell "perl6 bin/panda install --notests Test::Harness File::Tools JSON::Tiny Test::Mock {cwd}";
rm_rf "$destdir/panda/src"; # XXX This shouldn't be necessary, I think
# that src should not be kept at all, but
# I figure out how to do that nicely, let's
View
7 ext/Test__Harness/META.info
@@ -0,0 +1,7 @@
+{
+ "name" : "Test::Harness",
+ "version" : "*",
+ "description" : "Read TAP output",
+ "depends" : [],
+ "source-url" : "git://github.com/tadzik/Test-Harness.git"
+}
View
53 ext/Test__Harness/bin/p6prove
@@ -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;
+ }
+}
View
69 ext/Test__Harness/lib/Test/Harness.pm
@@ -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
+ }
+}
View
88 ext/Test__Harness/t/file.t
@@ -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';
View
2 lib/Panda/Tester.pm
@@ -12,7 +12,7 @@ class Panda::Tester does Pies::Tester {
indir $!resources.workdir($p), {
if 't'.IO ~~ :d {
withp6lib {
- my $c = "prove -e $*EXECUTABLE_NAME -r t/";
+ my $c = "p6prove -e $*EXECUTABLE_NAME -r t/";
shell $c and die $p, "Tests failed";
}
}
View
8 projects.json.bootstrap
@@ -17,6 +17,14 @@
},
{
"source-type" : "local",
+ "source-url" : "_BASEDIR_/Test__Harness",
+ "version" : "*",
+ "name" : "Test::Harness",
+ "description" : "Read TAP output",
+ "depends" : []
+ },
+ {
+ "source-type" : "local",
"repo-url" : "_BASEDIR_/Test__Mock",
"version" : "*",
"name" : "Test::Mock",

0 comments on commit e9d6331

Please sign in to comment.
Something went wrong with that request. Please try again.