pax_global_header00006660000000000000000000000064141745703210014516gustar00rootroot0000000000000052 comment=2ed93290d4b58f4371ca252150a3dd458cd1ab3d tap-harness6-0.3.5/000077500000000000000000000000001417457032100140365ustar00rootroot00000000000000tap-harness6-0.3.5/.gitignore000066400000000000000000000000111417457032100160160ustar00rootroot00000000000000.precomp tap-harness6-0.3.5/.travis.yml000066400000000000000000000002351417457032100161470ustar00rootroot00000000000000language: minimal services: - docker install: - docker pull jjmerelo/test-perl6 script: docker run -t -v $TRAVIS_BUILD_DIR:/test jjmerelo/test-perl6 tap-harness6-0.3.5/Changes000066400000000000000000000025411417457032100153330ustar00rootroot00000000000000Revision history for TAP {{$NEXT}} 0.3.5 2022-01-27T20:21:45+01:00 - Restore SourceHandler::Exec's constructor - Parse pragmas - Process strict pragma - Correctly handle IO::Path object as SourceHandler::Raku @!incdirs - Correctly pass through bailout Promise 0.3.4 2022-01-21T23:29:46+01:00 - Allow SourceHandler::Raku's incdirs arguments to be Str or IO::Path 0.3.3 2022-01-21T23:00:00+01:00 - Add a cwd argument to TAP::Harness::run - Add out and err argument to TAP::Harness::run - Allow coloring with verbose outputting 0.3.1 2022-01-12T01:00:01+01:00 - Fix Supplier name in Output::Supplier 0.3.0 2022-01-11T22:18:45+01:00 - Allow Supplier as output handle 0.2.2 2021-12-31T01:04:26+01:00 - Make error handle a supplier instead of a supply 0.2.1 2021-08-09T15:30:06+02:00 - Fix warning in Result.exit-failed() 0.2.0 2021-08-08T22:31:06+02:00 - Move prove6 to App::Prove6 - Make coloring optional 0.0.7 - Run all and only .t and .t6 files - Automatically set some configuration values from environment - Skip dot files and directories 0.0.6 - Reupload to fix packaging issues 0.0.5 - Make prove6 look for files recursively - Work around a module loading bug involving dynamic loading tap-harness6-0.3.5/LICENSE000066400000000000000000000213001417457032100150370ustar00rootroot00000000000000 The Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. tap-harness6-0.3.5/META6.json000066400000000000000000000006061417457032100155470ustar00rootroot00000000000000{ "authors" : [ "Leon Timmermans" ], "build-depends" : [ ], "depends" : [ ], "description" : "TAP harness for raku", "license" : "Artistic-2.0", "name" : "TAP", "perl" : "6.*", "provides" : { "TAP" : "lib/TAP.pm" }, "resources" : [ ], "source-url" : "https://github.com/Raku/tap-harness6.git", "tags" : [ ], "test-depends" : [ ], "version" : "0.3.5" } tap-harness6-0.3.5/README.md000066400000000000000000000052631417457032100153230ustar00rootroot00000000000000# NAME TAP # DESCRIPTION An asynchronous TAP framework written in Raku. # SYNOPSIS ```Raku use TAP; my $harness = TAP::Harness.new(|%args); $harness.run(@tests); ``` # METHODS ## Class Methods ### new ```Raku my %args = jobs => 1, err => 'ignore'; my $harness = TAP::Harness.new( |%args ); ``` The constructor returns a new `TAP::Harness` object. It accepts an optional hash whose allowed keys are: * `volume` Default value: `Normal` Possible values: `Silent` `ReallyQuiet` `Quiet` `Normal` `Verbose` * `jobs` The maximum number of parallel tests to run. Default value: `1` Possible values: An `Int` * `timer` Append run time for each test to output. Default value: `False` Possible values: `True` `False` * `err` Error reporting configuration. Default value: `stderr` Possible values: `stderr` `ignore` `merge` `Supply` `IO::Handle` |Value |Definition | |------------|--------------------------------------------------| |`stderr` |Direct the test's `$*ERR` to the harness' `$*ERR` | |`ignore` |Ignore the test scripts' `$*ERR` | |`merge` |Merge the test scripts' `$*ERR` into their `$*OUT`| |`Supply` |Direct the test's `$*ERR` to a `Supply` | |`IO::Handle`|Direct the test's `$*ERR` to an `IO::Handle` | * `ignore-exit` If set to `True` will instruct `TAP::Parser` to ignore exit and wait for status from test scripts. Default value: `False` Possible values: `True` `False` * `trap` Attempt to print summary information if run is interrupted by SIGINT (Ctrl-C). Default value: `False` Possible values: `True` `False` * `handlers` Default value: `TAP::Harness::SourceHandler::Raku` Possible values: `TAP::Harness::SourceHandler::Raku` `TAP::Harness::SourceHandler::Exec` |Language|Handler | |--------|-------------------------------------------------| |Raku |`TAP::Harness::SourceHandler::Raku.new` | |Perl 5 |`TAP::Harness::SourceHandler::Exec.new('perl')` | |Ruby |`TAP::Harness::SourceHandler::Exec.new('ruby')` | |Python |`TAP::Harness::SourceHandler::Exec.new('python')`| ## Instance Methods ### run ```Raku $harness.run(@tests); ``` Accepts an array of `@tests` to be run. This should generally be the names of test files. # TODO These features are currently not implemented but are considered desirable: * Rule based parallel scheduling * Source Handlers other than `::Raku` * Better documentation # LICENSE You can use and distribute this module under the terms of the The Artistic License 2.0. See the LICENSE file included in this distribution for complete details. tap-harness6-0.3.5/dist.ini000066400000000000000000000000371417457032100155020ustar00rootroot00000000000000[ReadmeFromPod] enable = false tap-harness6-0.3.5/lib/000077500000000000000000000000001417457032100146045ustar00rootroot00000000000000tap-harness6-0.3.5/lib/TAP.pm000066400000000000000000001053711417457032100155750ustar00rootroot00000000000000use v6; unit module TAP:ver<0.3.5>; role Entry { has Str:D $.raw is required handles ; } class Version does Entry { has Int:D $.version is required; } class Plan does Entry { has Int:D $.tests is required; has Bool $.skip-all; has Str $.explanation; } enum Directive ; class Test does Entry { has Bool:D $.ok is required; has Int $.number; has Str $.description; has Directive:D $.directive = No-Directive; has Str $.explanation; method is-ok() { $!ok || $!directive ~~ Todo; } } class Sub-Test is Test { has @.entries; method inconsistencies(Str $usable-number = ~($.number // '?')) { my @errors; my @tests = @!entries.grep(Test); if $.is-ok != ?all(@tests).is-ok { @errors.push: "Subtest $usable-number isn't coherent"; } my @plans = @!entries.grep(Plan); if !@plans { @errors.push: "Subtest $usable-number doesn't have a plan"; } elsif @plans > 1 { @errors.push: "Subtest $usable-number has multiple plans"; } elsif @plans[0].tests != @tests.elems { @errors.push: "Subtest $usable-number expected { @plans[0].tests } but contains { @tests.elems } tests"; } @errors; } } class Bailout does Entry { has Str $.explanation; } class Comment does Entry { has Str:D $.comment is required; } class Pragma does Entry { has Bool:D %.identifiers is required; } class YAML does Entry { has Str:D $.serialized is required; has Any $.deserialized; } class Unknown does Entry { } my role Entry::Handler { method handle-entry(Entry) { ... } method end-entries() { } method listen(Supply $supply) { my $act = { self.handle-entry($^entry) }; my $done = my $quit = { self.end-entries() }; $supply.act($act, :$done, :$quit); } } class Result { has Str $.name; has Int $.tests-planned; has Int $.tests-run; has Int $.passed; has Int @.failed; has Str @.errors; has Int $.actual-passed; has Int $.actual-failed; has Int $.todo; has Int @.todo-passed; has Int $.skipped; has Int $.unknowns; has Bool $.skip-all; has Proc $.exit-status; has Duration $.time; method exit() { $!exit-status.defined ?? $!exit-status.exitcode !! Int; } method wait() { $!exit-status.defined ?? ($!exit-status.exitcode +< 8) +| $!exit-status.signal !! Int; } method has-problems($ignore-exit = False) { so @!failed || @!errors || (!$ignore-exit && self.exit-failed); } method exit-failed() { so $!exit-status.defined && ($!exit-status.exitcode || $!exit-status.signal); } } class Aggregator { has Result %!results-for; has Str @!parse-order; has Int $.tests-planned = 0; has Int $.tests-run = 0; has Int $.passed = 0; has Int $.failed = 0; has Int $.errors = 0; has Int $.actual-passed = 0; has Int $.actual-failed = 0; has Int $.todo = 0; has Int $.todo-passed = 0; has Int $.skipped = 0; has Int $.exit-failed = 0; has Bool $.ignore-exit = False; method add-result(Result $result) { my $description = $result.name; die "You already have a parser for ($description). Perhaps you have run the same test twice." if %!results-for{$description}; %!results-for{$description} = $result; @!parse-order.push($result.name); $!tests-planned += $result.tests-planned // 0; $!tests-run += $result.tests-run; $!passed += $result.passed; $!failed += $result.failed.elems; $!actual-passed += $result.actual-passed; $!actual-failed += $result.actual-failed; $!todo += $result.todo; $!todo-passed += $result.todo-passed.elems; $!skipped += $result.skipped.elems; $!errors += $result.errors.elems; $!exit-failed++ if not $!ignore-exit and $result.wait; } method result-count { +@!parse-order; } method results() { %!results-for{@!parse-order}; } method has-problems() { so $!todo-passed || self.has-errors; } method has-errors() { so $!failed + $!errors + $!exit-failed; } method get-status() { self.has-errors || $!tests-run != $!passed ?? 'FAILED' !! $!tests-run ?? 'PASS' !! 'NOTESTS'; } } my grammar Grammar { regex TOP { ^ [ | | | | | || ] $ } token sp { <[\s] - [\n]> } token num { <[0..9]>+ } token plan { '1..' <.sp>* [ '#' <.sp>* $=[:i 'SKIP'] \S* [ <.sp>+ $=[\N*] ]? ]? } regex description { [ '\\\\' || '\#' || <-[\n#]> ]+ +> } token test { $=['not '?] 'ok' [ <.sp> ]? ' -'? [ <.sp>* ]? [ <.sp>* '#' <.sp>* $=[:i [ 'SKIP' \S* | 'TODO'] ] [ <.sp>+ $=[\N*] ]? ]? <.sp>* } token bailout { 'Bail out!' [ <.sp> $=[\N*] ]? } token version { :i 'TAP version ' } token pragma-identifier { $=<[+-]> $=[+] } token pragma { 'pragma ' + % ' ' } token comment { '#' <.sp>* $=[\N*] } token yaml(Int $indent = 0) { ' ---' \n [ ^^ <.indent($indent)> ' ' $=[ \N* \n] ]* <.indent($indent)> ' ...' } token sub-entry(Int $indent) { | | | | | || > } token indent(Int $indent) { ' ' ** { $indent } } token sub-test(Int $indent = 0) { ' ' [ \n ]+ % [ <.indent($indent+1)> ] <.indent($indent)> } token unknown { \N* } class Actions { method TOP($/) { make $/.values[0].made; } method plan($/) { my %args = :raw(~$/), :tests(+$); if $ { %args = True, ~$; } make TAP::Plan.new(|%args); } method description($m) { $m.make: ~$m.subst(/\\('#'|'\\')/, { $_[0] }, :g) } method !make_test($/) { my %args = (:ok($ eq '')); %args = $ ?? +$ !! Int; %args = $.made if $; %args = $ ?? TAP::Directive::{~$.substr(0,4).tclc} !! TAP::No-Directive; %args = ~$ if $; %args; } method test($/) { make TAP::Test.new(:raw(~$/), |self!make_test($/)); } method bailout($/) { make TAP::Bailout.new(:raw(~$/), :explanation($ ?? ~$ !! Str)); } method version($/) { make TAP::Version.new(:raw(~$/), :version(+$)); } method pragma-identifier($/) { make $ => ?( $ eq '+' ); } method pragma($/) { my Bool:D %identifiers = @.map(*.ast); make TAP::Pragma.new(:raw(~$/), :%identifiers); } method comment($/) { make TAP::Comment.new(:raw(~$/), :comment(~$)); } method yaml($/) { my $serialized = $.join(''); my $deserialized = try (require YAMLish) ?? YAMLish::load-yaml("---\n$serialized...") !! Any; make TAP::YAML.new(:raw(~$/), :$serialized, :$deserialized); } method sub-entry($/) { make $/.values[0].made; } method sub-test($/) { make TAP::Sub-Test.new(:raw(~$/), :entries(@».made), |self!make_test($)); } method unknown($/) { make TAP::Unknown.new(:raw(~$/)); } } method parse(|c) { my $*tap-indent = 0; nextwith(:actions(Actions), |c); } method subparse(|c) { my $*tap-indent = 0; nextwith(:actions(Actions), |c); } } my sub parser(Supply $input --> Supply) { supply { enum Mode ; my Mode $mode = Normal; my Str @buffer; sub set-state(Mode $new, Str $line) { $mode = $new; @buffer = $line; } sub emit-unknown(*@more) { @buffer.append: @more; for @buffer -> $raw { emit Unknown.new(:$raw); } @buffer = (); $mode = Normal; } sub emit-reset(Match $entry) { emit $entry.made; @buffer = (); $mode = Normal; } my token indented { ^ ' ' } my $grammar = Grammar.new; whenever $input.lines -> $line { if $mode == Normal { if $line ~~ / ^ ' ---' / { set-state(Yaml, $line); } elsif $line ~~ &indented { set-state(SubTest, $line); } else { emit-reset $grammar.parse($line); } } elsif $mode == SubTest { if $line ~~ &indented { @buffer.push: $line; } elsif $grammar.parse($line, :rule('test')) -> $test { my $raw = (|@buffer, $line).join("\n"); if $grammar.parse($raw, :rule('sub-test')) -> $subtest { emit-reset $subtest; } else { emit-unknown; emit-reset $test; } } else { emit-unknown $line; } } elsif $mode == Yaml { if $line ~~ / ^ ' ' $=[\N*] $ / { @buffer.push: $line; if $ eq '...' { my $raw = @buffer.join("\n"); if $grammar.parse($raw, :rule('yaml')) -> $yaml { emit-reset $yaml; } else { emit-unknown; } } } else { emit-unknown $line; } } } LEAVE { emit-unknown } } } role Output { method print(Str $value) { ... } method say(Str $value) { self.print($value ~ "\n"); } method flush() { } method terminal() { False; } } class Output::Handle does Output { has IO::Handle:D $.handle handles(:print, :flush, :terminal) = $*OUT; } class Output::Supplier does Output { has Supplier:D $.supplier is required; method print(Str $value) { $!supplier.emit($value); } } enum Formatter::Volume ; role Formatter { has Bool:D $.timer = False; has Formatter::Volume $.volume = Normal; has Bool:D $.ignore-exit = False; } role Reporter { has Output:D $.output is required; has Formatter:D $.formatter handles is required; method summarize(TAP::Aggregator, Bool $interrupted, Duration $duration) { ... } method open-test(Str $) { ... } } role Session does Entry::Handler { has TAP::Reporter $.reporter; has Str $.name; has Str $.header; method clear-for-close() { } method close-test(TAP::Result $result) { $!reporter.print-result(self, $result); } } class Reporter::Text::Session does Session { method handle-entry(TAP::Entry $) { } } class Formatter::Text does Formatter { has Int $!longest; submethod TWEAK(:@names) { $!longest = @names ?? @names».chars.max !! 12; } method format-name($name) { my $periods = '.' x ( $!longest + 2 - $name.chars); my @now = $.timer ?? ~DateTime.new(now, :formatter{ '[' ~ .hour ~ ':' ~ .minute ~ ':' ~ .second.Int ~ ']' }) !! (); (|@now, $name, $periods).join(' '); } method format-summary(TAP::Aggregator $aggregator, Bool $interrupted, Duration $duration) { my $output = ''; if $interrupted { $output ~= self.format-failure("Test run interrupted!\n") } if $aggregator.failed == 0 { $output ~= self.format-success("All tests successful.\n"); } if $aggregator.has-problems { $output ~= "\nTest Summary Report"; $output ~= "\n-------------------\n"; for $aggregator.results -> $result { my $name = $result.name; if $result.has-problems($!ignore-exit) { my $spaces = ' ' x min($!longest - $name.chars, 1); my $wait = $result.wait // '(none)'; my $line = "$name$spaces (Wstat: $wait Tests: {$result.tests-run} Failed: {$result.failed.elems})\n"; $output ~= self.format-failure($line); if $result.failed -> @failed { $output ~= self.format-failure(' Failed tests: ' ~ @failed.join(' ') ~ "\n"); } if $result.todo-passed -> @todo-passed { $output ~= " TODO passed: { @todo-passed.join(' ') }\n"; } if $result.wait -> $wait { if $result.exit { $output ~= self.format-failure("Non-zero exit status: { $result.exit }\n"); } else { $output ~= self.format-failure("Non-zero wait status: $wait\n"); } } if $result.errors -> @ ($head, *@tail) { $output ~= self.format-failure(" Parse errors: $head\n"); $output ~= @tail.map({ self.format-failure(' ' x 16 ~ $_ ~ "\n") }).join(''); } } } } my $timing = $duration.defined ?? ", { $duration.Int } wallclock secs" !! ''; $output ~= "Files={ $aggregator.result-count }, Tests={ $aggregator.tests-run }$timing\n"; my $status = $aggregator.get-status; $output ~= "Result: $status\n"; $output; } method format-success(Str $output) { $output; } method format-failure(Str $output) { $output; } method format-return(Str $output) { $output; } method format-result(Session $session, TAP::Result $result) { my $output; my $name = $session.header; if ($result.skip-all) { $output = self.format-return("$name skipped\n"); } elsif ($result.has-problems($!ignore-exit)) { $output = self.format-test-failure($name, $result); } else { my $time = self.timer && $result.time ?? sprintf ' %8d ms', Int($result.time * 1000) !! ''; $output = self.format-return("$name ok$time\n"); } $output; } method format-test-failure(Str $name, TAP::Result $result) { return if self.volume <= Quiet; my $output = self.format-return("$name "); my $total = $result.tests-planned // $result.tests-run; my $failed = $result.failed + abs($total - $result.tests-run); if !$!ignore-exit && $result.exit -> $status { $output ~= self.format-failure("Dubious, test returned $status\n"); } if $result.failed == 0 { $output ~= self.format-failure($total ?? "All $total subtests passed " !! 'No subtests run'); } else { $output ~= self.format-failure("Failed {$result.failed.elems}/$total subtests "); if (!$total) { $output ~= self.format-failure("\nNo tests run!"); } } if $result.skipped -> $skipped { my $passed = $result.passed - $skipped; my $test = 'subtest' ~ ( $skipped != 1 ?? 's' !! '' ); $output ~= "\n\t(less $skipped skipped $test: $passed okay)"; } if $result.todo-passed.elems -> $todo-passed { my $test = $todo-passed > 1 ?? 'tests' !! 'test'; $output ~= "\n\t($todo-passed TODO $test unexpectedly succeeded)"; } $output ~= "\n"; $output; } } class Reporter::Text does Reporter { method open-test(Str $name) { my $header = $!formatter.format-name($name); Reporter::Text::Session.new(:$name, :$header, :reporter(self)); } method summarize(TAP::Aggregator $aggregator, Bool $interrupted, Duration $duration) { self!output($!formatter.format-summary($aggregator, $interrupted, $duration)) unless self.volume === Silent; } method !output(Any $value) { $!output.print($value); } method print-result(Reporter::Text::Session $session, TAP::Result $report) { self!output($!formatter.format-result($session, $report)) unless self.volume <= Quiet; } } class Formatter::Color is Formatter::Text { has &colored = (try require Terminal::ANSIColor) !=== Nil ?? ::('Terminal::ANSIColor::EXPORT::DEFAULT::&colored') !! sub ($text, $) { $text }; method format-success(Str $output) { &colored($output, 'green'); } method format-failure(Str $output) { &colored($output, 'red'); } method format-return(Str $output) { "\r$output"; } } class Reporter::Console::Session does Session { has Int $!last-updated = 0; has Int $.plan = Int; has Int:D $.number = 0; proto method handle-entry(TAP::Entry $entry) { {*}; } multi method handle-entry(TAP::Bailout $bailout) { my $explanation = $bailout.explanation // ''; $!reporter.bailout($explanation); } multi method handle-entry(TAP::Plan $plan) { $!plan = $plan.tests; } multi method handle-entry(TAP::Test $test) { my $now = time; ++$!number; if $!last-updated != $now { $!last-updated = $now; $!reporter.update($.name, $!header, $test.number // $!number, $!plan); } } multi method handle-entry(TAP::Entry $) { } method summary() { ($!number, $!plan // '?').join("/"); } } class Reporter::Console does Reporter { has Int $!lastlength = 0; has Supplier $events = Supplier.new; has Reporter::Console::Session @!active; has Int $!tests = 0; has Int $!fails = 0; submethod TWEAK(:$!output, :$!formatter) { my $now = 0; my $start = now; sub output-ruler(Bool $refresh) { my $new-now = now; return if $now == $new-now and !$refresh; $now = $new-now; my $header = sprintf '===( %7d;%d', $!tests, $now - $start; my @items = @!active.map(*.summary); my $ruler = ($header, |@items).join(' ') ~ ')==='; $ruler = $ruler.substr(0,70) if $ruler.chars > 70; $!output.print($!formatter.format-return($ruler)); } multi receive('update', Str $name, Str $header, Int $number, Int $plan) { return if self.volume <= Quiet; if @!active.elems == 1 { my $status = ($header, $number, '/', $plan // '?').join(''); $!output.print($!formatter.format-return($status)); $!lastlength = $status.chars + 1; } else { output-ruler($number == 1); } } multi receive('bailout', Str $explanation) { return if self.volume <= Quiet; $!output.print($!formatter.format-failure("Bailout called. Further testing stopped: $explanation\n")); } multi receive('result', Reporter::Console::Session $session, TAP::Result $result) { return if self.volume <= Quiet; $!output.print($!formatter.format-return(' ' x $!lastlength) ~ $!formatter.format-result($session, $result)); @!active = @!active.grep(* !=== $session); output-ruler(True) if @!active.elems > 1; } multi receive('summary', TAP::Aggregator $aggregator, Bool $interrupted, Duration $duration) { $!output.print($!formatter.format-summary($aggregator, $interrupted, $duration)) unless self.volume == Silent; } $!events.Supply.act(-> @args { receive(|@args) }); } method update(Str $name, Str $header, Int $number, Int $plan) { $!events.emit(['update', $name, $header, $number, $plan]); } method bailout(Str $explanation) { $!events.emit(['bailout', $explanation]); } method print-result(Reporter::Console::Session $session, TAP::Result $result) { $!events.emit(['result', $session, $result]); } method summarize(TAP::Aggregator $aggregator, Bool $interrupted, Duration $duration) { $!events.emit(['summary', $aggregator, $interrupted, $duration]); } method open-test(Str $name) { my $header = $!formatter.format-name($name); my $ret = Reporter::Console::Session.new(:$name, :$header, :reporter(self)); @!active.push($ret); $ret; } } my class State does TAP::Entry::Handler { has Range $.allowed-versions = 12 .. 14; has Int $!tests-planned; has Int $!tests-run = 0; has Int $!passed = 0; has Int @!failed; has Str @!errors; has Int $!actual-passed = 0; has Int $!actual-failed = 0; has Int $!todo = 0; has Int @!todo-passed; has Int $!skipped = 0; has Int $!unknowns = 0; has Bool $!skip-all = False; has Bool $!strict; has Promise $.bailout; has Int $!seen-lines = 0; enum Seen ; has Seen $!seen-plan = Unseen; has Promise $.done = Promise.new; has Int $!version; has Bool $.loose; proto method handle-entry(TAP::Entry $entry) { if $!seen-plan == After && $entry !~~ TAP::Comment { self!add-error("Got line $entry after late plan"); } {*}; $!seen-lines++; } multi method handle-entry(TAP::Version $entry) { if $!seen-lines { self!add-error('Seen version declaration mid-stream'); } elsif $entry.version !~~ $!allowed-versions { self!add-error("Version must be in range $!allowed-versions"); } else { $!version = $entry.version; } } multi method handle-entry(TAP::Plan $plan) { if $!seen-plan != Unseen { self!add-error('Seen a second plan'); } else { $!tests-planned = $plan.tests; $!seen-plan = $!tests-run ?? After !! Before; $!skip-all = $plan.skip-all; } } multi method handle-entry(TAP::Test $test) { my $found-number = $test.number; my $expected-number = ++$!tests-run; if $found-number.defined && ($found-number != $expected-number) { self!add-error("Tests out of sequence. Found ($found-number) but expected ($expected-number)"); } if $!seen-plan == After { self!add-error("Plan must be at the beginning or end of the TAP output"); } my $usable-number = $found-number // $expected-number; if $test.is-ok { $!passed++; } else { @!failed.push($usable-number); } ($test.ok ?? $!actual-passed !! $!actual-failed)++; $!todo++ if $test.directive == TAP::Todo; @!todo-passed.push($usable-number) if $test.ok && $test.directive == TAP::Todo; $!skipped++ if $test.directive == TAP::Skip; if !$!loose && $test ~~ TAP::Sub-Test { for $test.inconsistencies(~$usable-number) -> $error { self!add-error($error); } } } multi method handle-entry(TAP::Bailout $entry) { if $!bailout.defined { $!bailout.break($entry); } else { $!done.break($entry); } } multi method handle-entry(TAP::Unknown $) { $!unknowns++; if $!strict { self!add-error('Seen invalid TAP in strict mode'); } } multi method handle-entry(TAP::Pragma $entry) { if $entry.identifiers:exists { $!strict = $entry.identifiers; } } multi method handle-entry(TAP::Entry $entry) { } method end-entries() { if $!seen-plan == Unseen { self!add-error('No plan found in TAP output'); } elsif $!tests-run != $!tests-planned { self!add-error("Bad plan. You planned $!tests-planned tests but ran $!tests-run."); } $!done.keep; } method finalize(Str $name, Proc $exit-status, Duration $time) { TAP::Result.new(:$name, :$!tests-planned, :$!tests-run, :$!passed, :@!failed, :@!errors, :$!skip-all, :$!actual-passed, :$!actual-failed, :$!todo, :@!todo-passed, :$!skipped, :$!unknowns, :$exit-status, :$time); } method !add-error(Str $error) { push @!errors, $error; } } my class Run { subset Killable of Any where { .can('kill') }; has Supply:D $.events is required; has Promise:D $.process = $!events.Promise; has Killable $!killer; has Promise $!timer; method kill() { $!killer.kill if $!process; } method exit-status() { $!process.result ~~ Proc ?? $.process.result !! Proc; } method time() { $!timer.defined ?? $!timer.result !! Duration; } } role Source { has Str $.name; } class Source::Proc does Source { has Str $.path is required; has @.args; has $.err is required; has $.cwd is required; } class Source::File does Source { has IO(Str) $.filename handles; } class Source::String does Source { has Str $.content; } class Source::Supply does Source { has Supply $.supply; } class Async { has Str $.name; has Run $!run handles ; has State $!state; has Promise $.waiter; submethod BUILD(Str :$!name, State :$!state, Run :$!run) { $!waiter = Promise.allof($!state.done, $!run.process); } multi get_runner(Source::Proc $proc) { my $async = Proc::Async.new($proc.path, $proc.args); my $events = parser($async.stdout); state $devnull; END { $devnull.close with $devnull } given $proc.err { my $err = $_; when 'stderr' { #default is correct } when 'merge' { warn "Merging isn't supported yet on Asynchronous streams"; $devnull //= open($*SPEC.devnull, :w); $async.bind-stderr($devnull); } when 'ignore' { $devnull //= open($*SPEC.devnull, :w); $async.bind-stderr($devnull); } when IO::Handle:D { $async.bind-stderr($err); } when Supplier:D { $async.stderr.act({ $err.emit($_) }, :done({ $err.done }), :quit({ $err.quit($^reason) })); } default { die "Unknown error handler"; } } my $process = $async.start(:cwd($proc.cwd)); my $start-time = now; my $timer = $process.then({ now - $start-time }); Run.new(:$process, :killer($async), :$timer, :$events); } multi get_runner(Source::Supply $supply) { my $start-time = now; my $events = parser($supply.supply); Run.new(:$events); } multi get_runner(Source::File $file) { my $events = parser(supply { emit $file.slurp(:close) }); Run.new(:$events); } multi get_runner(Source::String $string) { my $events = parser(supply { emit $string.content }); Run.new(:$events); } method new(Source :$source, Promise :$bailout, Bool :$loose) { my $state = State.new(:$bailout, :$loose); my $run = get_runner($source); $state.listen($run.events); Async.bless(:name($source.name), :$state, :$run); } has TAP::Result $!result; method result { await $!waiter; $!result //= $!state.finalize($!name, $!run.exit-status, $!run.time); } } class Harness { role SourceHandler { method can-handle {...}; method make-source {...}; } role SourceHandler::Proc does SourceHandler { } my sub normalize-path($path, IO::Path $cwd) { $path ~~ IO ?? $path.IO.relative($cwd) !! ~$path } class SourceHandler::Raku does SourceHandler::Proc { has Str:D $.path = $*EXECUTABLE.absolute; has @.incdirs; method make-source(Str:D $name, Any:D :$err, IO::Path:D :$cwd, :@include-dirs = (), *%) { my @dirs = map { normalize-path($_, $cwd) }, |@include-dirs, |@!incdirs; my @args = |@dirs.map("-I" ~ *), $name; TAP::Source::Proc.new(:$name, :$!path, :@args, :$err, :$cwd); } method can-handle(Str $name) { 0.5; } } class SourceHandler::Perl6 is SourceHandler::Raku { # This may later give deprecation warnings } class SourceHandler::Exec does SourceHandler::Proc { has Str:D $.path is required; has @.args; method new (*@ ($path, *@args)) { self.bless(:$path, :@args); } method can-handle(Str $name) { 1; } method make-source(Str:D $name, Any:D :$err, IO::Path:D :$cwd, *%) { my @args = |@!args, $name; TAP::Source::Proc.new(:$name, :$!path, :@args, :$err, :$cwd); } } my sub load-reporter(Str $name --> Reporter) { my $classname = $name.subst('-', '::', :g); my $loaded = try ::($classname); return $loaded if $loaded !eqv Any; require ::($classname); return ::($classname); } subset OutVal where any(IO::Handle:D, Supplier:D); has SourceHandler @.handlers = SourceHandler::Raku.new(); has IO::Handle $.handle = $*OUT; has OutVal $.output = $!handle; has Formatter::Volume $.volume = ?%*ENV ?? Verbose !! Normal; has Str %!env-options = (%*ENV // '').split(':').grep(*.chars).map: { / ^ (.) (.*) $ /; ~$0 => val(~$1) }; has TAP::Reporter:U $.reporter-class; has Int:D $.jobs = %!env-options // 1; has Bool:D $.timer = ?%*ENV; subset ErrValue where any(IO::Handle:D, Supplier, 'stderr', 'ignore', 'merge'); has ErrValue $.err = 'stderr'; has Bool:D $.ignore-exit = ?%*ENV; has Bool:D $.trap = False; has Bool:D $.loose = $*PERL.compiler.version before 2017.09; has Bool $.color; class Run does Awaitable { has Promise $!waiter handles ; has Promise $!bailout; submethod BUILD (Promise :$!waiter, Promise :$!bailout) { } method kill(Any:D $reason) { $!bailout.break($reason); } method get-await-handle(--> Awaitable::Handle:D) { return $!waiter.promise.get-await-handle; } } method make-aggregator() { TAP::Aggregator.new(:$!ignore-exit); } method add-handlers(Supply $events, Output $output) { if $.volume == Verbose { $events.act({ $output.say(~$^entry) }, :done({ $output.flush }), :quit({ $output.flush })); } } my &sigint = sub { signal(SIGINT) } my multi make-output(IO::Handle:D $handle) { return Output::Handle.new(:$handle); } my multi make-output(Supplier:D $supplier) { return Output::Supplier.new(:$supplier); } my sub get-reporter(Reporter $reporter-class, %env-options, $output, $volume) { if $reporter-class !=== Reporter { return $reporter-class; } elsif %env-options { return load-reporter(%env-options); } elsif $output.terminal && $volume < Verbose { return TAP::Reporter::Console; } else { return TAP::Reporter::Text; } } my sub get-color(Bool $color, %env-options, Output $output) { with $color { return $color; } orwith %env-options { return True; } orwith %*ENV { return ?%*ENV; } orwith %*ENV { return False; } else { state @safe-terminals = ; return $output.terminal && (%*ENV // '') ~~ / @safe-terminals /; } } method run(*@names, IO(Str) :$cwd = $*CWD, OutVal :$out = $!output, ErrValue :$err = $!err, *%handler-args) { my $bailout = Promise.new; my $aggregator = self.make-aggregator; my $output = make-output($out); my $formatter-class = get-color($!color, %!env-options, $output) ?? Formatter::Color !! Formatter::Text; my $formatter = $formatter-class.new(:@names, :$!volume, :$!timer, :$!ignore-exit); my $reporter-class = get-reporter($!reporter-class, %!env-options, $output, $!volume); my $reporter = $reporter-class.new(:$output, :$formatter); my @working; my $waiter = start { my $int = $!trap ?? sigint().tap({ $bailout.break("Interrupted"); $int.close(); }) !! Tap; my $begin = now; try { for @names -> $name { my $path = normalize-path($name, $cwd); my $session = $reporter.open-test($path); my $source = @!handlers.max(*.can-handle($name)).make-source($path, :$err, :$cwd, |%handler-args); my $parser = TAP::Async.new(:$source, :$bailout, :$!loose); $session.listen($parser.events); self.add-handlers($parser.events, $output); @working.push({ :$parser, :$session, :done($parser.waiter) }); next if @working < $!jobs; await Promise.anyof(@working», $bailout); reap-finished(); } while @working { await Promise.anyof(@working», $bailout); reap-finished(); } CATCH { when "Interrupted" { reap-finished(); @working».».kill; } } } $reporter.summarize($aggregator, ?$bailout, now - $begin) if !$bailout || $!trap; $int.close if $int; $aggregator; } sub reap-finished() { my @new-working; for @working -> $current (:$done, :$parser, :$session) { if $done { $aggregator.add-result($parser.result); $session.close-test($parser.result); } else { @new-working.push($current); } } @working = @new-working; } Run.new(:$waiter, :$bailout); } } # ts=4 sw=4 et tap-harness6-0.3.5/t/000077500000000000000000000000001417457032100143015ustar00rootroot00000000000000tap-harness6-0.3.5/t/source-file-test-data000066400000000000000000000000601417457032100203210ustar00rootroot000000000000001..2 ok 1 go not ok 2 stay # diagnostic message tap-harness6-0.3.5/t/source-file.t000066400000000000000000000010501417457032100166770ustar00rootroot00000000000000use v6; use TAP; use Test; plan 6; my $filename = $*PROGRAM.parent.child('source-file-test-data'); my $source = TAP::Source::File.new(:$filename); my $parser = TAP::Async.new(:$source); await $parser.waiter; my $result = $parser.result; is($result.tests-planned, 2, "planned 2"); is($result.tests-run, 2, "Ran 2"); is-deeply([@( $result.passed.list )], [ 1 ], "First test passed"); is-deeply([@( $result.failed.list )], [ 2 ], "Second test failed"); is($result.has-problems, True, 'Test failure is a problem'); is($result.errors, [], 'No errors'); tap-harness6-0.3.5/t/string.t000066400000000000000000000107341417457032100160010ustar00rootroot00000000000000use TAP; # -*- mode: perl6 -*- use Test; my $content1 = q:heredoc/END/; ok 1 - subtest 1a ok 2 - subtest 1b 1..2 ok 1 - Subtest 1 ok 1 - subtest 2a ok 2 - subtest 2b 1..2 ok 2 - Subtest 2 1..2 END parse-and-get($content1, :tests-planned(2), :tests-run(2), :passed(2), :failed(0), :todo-passed(0), :skipped(0), :unknowns(0), :errors()); my $content2 = q:heredoc/END/; ok 1 - foo not ok 1 - not ok ok 2 - bar passed 1..2 END parse-and-get($content2, :tests-planned(2), :tests-run(2), :passed(2), :failed(0), :todo-passed(0), :skipped(0), :unknowns(0), :errors(['Subtest 2 isn\'t coherent', "Subtest 2 doesn't have a plan"])); my $content3 = q:heredoc/END/; ok 1 - foo ok 1 - bar indented too far ok 2 - bar passed 1..2 END parse-and-get($content3, :tests-planned(2), :tests-run(2), :passed(2), :failed(0), :todo-passed(0), :skipped(0), :unknowns(1), :errors()); my $content4 = q:heredoc/END/; 1..2 ok 1 - a ok 1 - b 1..1 ok 1 - c 1..1 ok 2 - e END parse-and-get($content4, :tests-planned(2), :tests-run(2), :passed(2), :failed(0), :todo-passed(0), :skipped(0), :unknowns(0), :errors()); my @entries = lex-and-get($content4); isa-ok(@entries[0], TAP::Plan, 'First Entry is a Plan'); isa-ok(@entries[1], TAP::Test, 'Second entry is a subtest'); isa-ok(@entries[2], TAP::Sub-Test, 'Third entry is a subtest'); is-deeply(@entries[2].inconsistencies, [], 'Subtests has no errors'); isa-ok(@entries[2].entries[0], TAP::Sub-Test, 'First sub-entry is a subtest'); is-deeply(@entries[2].entries[0].inconsistencies, [], 'Subsubtests has no errors'); my $content5 = q:heredoc/END/; 1..2 ok 1 - a\#b ok 1 - b --- - Foo - Bar ... 1..1 ok 2 - c --- - Baz ... END parse-and-get($content5, :tests-planned(2), :tests-run(2), :passed(2), :failed(0), :todo-passed(0), :skipped(0), :unknowns(0), :errors()); my @entries2 = lex-and-get($content5); isa-ok(@entries2[0], TAP::Plan, 'First Entry is a Plan'); isa-ok(@entries2[1], TAP::Test, 'Second entry is a test'); is(@entries2[1].description, 'a#b', 'Test has a description'); isa-ok(@entries2[2], TAP::Sub-Test, 'Third entry is a subtest'); is-deeply(@entries2[2].inconsistencies, [], 'Subtests has no errors'); isa-ok(@entries2[2].entries[1], TAP::YAML, 'Got YAML'); if try (require YAMLish) { is-deeply(@entries2[2].entries[1].deserialized, [ ], 'Could deserialize YAML'); } isa-ok(@entries2[3], TAP::YAML, 'Got YAML again'); my $content6=q:heredoc/END/; 1..5 ok 1 - Pod::Htmlify module can be use-d ok 1..1 ok 1 - :page-order value extracted correctly ok 2 - 1..7 ok 1 - requires an argument ok 2 - plain url string with explicit protocol ok 3 - type name input ok 4 - routine name input ok 5 - identifier (sub) input ok 6 - operator input ok 7 - sigil/twigil input ok 3 - url-munge 1..1 ok 1 - footer text isn't empty ok 4 - footer-html 1..1 ok 1 - SVG content extracted correctly ok 5 - svg-for-file END parse-and-get($content6,:tests-planned(5), :tests-run(5), :passed(5), :failed(0), :todo-passed(0), :skipped(0), :unknowns(0), :errors()); done-testing(); my $i; sub parse-and-get($content, :$tests-planned, :$tests-run, :$passed, :$failed, :$todo-passed, :$skipped, :$unknowns, :@errors = Array, :$name = "Test-{ ++$i }") { my $source = TAP::Source::String.new(:$name, :$content); my $parser = TAP::Async.new(:$source); my $result = $parser.result; is($result.tests-planned, $tests-planned, "Expected $tests-planned planned tests in $name") if $tests-planned.defined; is($result.tests-run, $tests-run, "Expected $tests-run run tests in $name") if $tests-run.defined; is($result.passed, $passed, "Expected $passed passed tests in $name") if $passed.defined; is($result.failed.elems, $failed, "Expected $failed failed tests in $name") if $failed.defined; is($result.todo-passed.elems, $todo-passed, "Expected $todo-passed todo-passed tests in $name") if $todo-passed.defined; is($result.skipped, $skipped, "Expected $skipped skipped tests in $name") if $skipped.defined; is($result.unknowns, $unknowns, "Expected $unknowns unknown tests in $name") if $unknowns.defined; is-deeply($result.errors, Array[Str].new(|@errors), 'Got expected errors: ' ~ @errors.map({qq{"$_"}}).join(', ')) if @errors.defined; return $result; } sub lex-and-get($content) { my $source = TAP::Source::String.new(:$content); my $async = TAP::Async.new(:$source); my @events; $async.events.act({ @events.push: $^event }); await $async.waiter; return @events; }