pax_global_header00006660000000000000000000000064134214471100014507gustar00rootroot0000000000000052 comment=29a9fa6f27a553681e1d6c958ddeacf157b6d4f5 tap-harness6-0.0.7/000077500000000000000000000000001342144711000140265ustar00rootroot00000000000000tap-harness6-0.0.7/.gitignore000066400000000000000000000000171342144711000160140ustar00rootroot00000000000000/lib/.precomp/ tap-harness6-0.0.7/.travis.yml000066400000000000000000000001401342144711000161320ustar00rootroot00000000000000branches: sudo: false language: perl6 perl6: - latest script: - perl6 -Ilib bin/prove6 -l t tap-harness6-0.0.7/Changes000066400000000000000000000005531342144711000153240ustar00rootroot00000000000000Revision history for TAP 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.0.7/LICENSE000066400000000000000000000213001342144711000150270ustar00rootroot00000000000000 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.0.7/META6.json000066400000000000000000000034261342144711000155420ustar00rootroot00000000000000{ "authors" : [ "Leon Timmermans" ], "build-depends" : [ ], "depends" : [ ], "description" : "TAP harness for perl6", "license" : "Artistic-2.0", "name" : "TAP", "perl" : "6.*", "provides" : { "TAP" : "lib/TAP.pm", "TAP::Entry" : "lib/TAP.pm", "TAP::Entry::Version" : "lib/TAP.pm", "TAP::Entry::Plan" : "lib/TAP.pm", "TAP::Entry::Test" : "lib/TAP.pm", "TAP::Entry::Sub-Test" : "lib/TAP.pm", "TAP::Entry::Bailout" : "lib/TAP.pm", "TAP::Entry::Comment" : "lib/TAP.pm", "TAP::Entry::YAML" : "lib/TAP.pm", "TAP::Entry::Unknown" : "lib/TAP.pm", "TAP::Session" : "lib/TAP.pm", "TAP::Result" : "lib/TAP.pm", "TAP::Aggregator" : "lib/TAP.pm", "TAP::Formatter" : "lib/TAP.pm", "TAP::Reporter" : "lib/TAP.pm", "TAP::Reporter::Text" : "lib/TAP.pm", "TAP::Reporter::Console" : "lib/TAP.pm", "TAP::Source::Proc" : "lib/TAP.pm", "TAP::Source::File" : "lib/TAP.pm", "TAP::Source::String" : "lib/TAP.pm", "TAP::Source::Supply" : "lib/TAP.pm", "TAP::Async" : "lib/TAP.pm", "TAP::Harness" : "lib/TAP.pm", "TAP::Harness::SourceHandler::Perl6" : "lib/TAP.pm", "TAP::Harness::SourceHandler::Exec" : "lib/TAP.pm" }, "resources" : [ ], "source-url" : "git://github.com/perl6/tap-harness6.git", "tags" : [ ], "test-depends" : [ ], "version" : "0.0.7" } tap-harness6-0.0.7/README-prove6.md000066400000000000000000000067021342144711000165310ustar00rootroot00000000000000# NAME prove6 - Run tests through a TAP harness. # USAGE prove6 [options] [files or directories] # OPTIONS Boolean options: -v, Print all test lines. -l, Add 'lib' to the path for your tests (-Ilib). -b, Add 'blib/lib' to the path for your tests --shuffle Run the tests in random order. --ignore-exit Ignore exit status from test scripts. --reverse Run the tests in reverse order. --timer Print elapsed time after each test. --trap Trap Ctrl-C and print summary on interrupt. --help Display this help --version Display the version Options that take arguments: -e, Interpreter to run the tests ('' for compiled tests.) --harness Define test harness to use. See TAP::Harness. --reporter Result reporter to use. See REPORTERS. -j, Run N test jobs in parallel (try 9.) --err=stdout Direct the test's $*ERR to the harness' $*ERR. --err=merge Merge test scripts' $*ERR with their $*OUT. --err=ignore Ignore test script' $*ERR. # NOTES ## Default Test Directory If no files or directories are supplied, `prove6` looks for all files matching the pattern `t/*.t`. ## Colored Test Output Colored test output is the default, but if output is not to a terminal, color is disabled. Color support requires `Terminal::ANSIColor` on Unix-like platforms. If the necessary module is not installed colored output will not be available. PS: Currently not available. ## Exit Code If the tests fail `prove6` will exit with non-zero status. ## `-e` Normally you can just pass a list of Perl 6 tests and the harness will know how to execute them. However, if your tests are not written in Perl 6 or if you want all tests invoked exactly the same way, use the `-e` switch: prove6 -e='/usr/bin/ruby -w' t/ prove6 -e='/usr/bin/perl -Tw -mstrict -Ilib' t/ prove6 -e='/path/to/my/customer/exec' ## `--err` * `--err=stderr` Direct the test's `$*ERR` to the harness' `$*ERR` This is the default behavior. * `--err=merge` If you need to make sure your diagnostics are displayed in the correct order relative to test results you can merge the test scripts' `$*ERR` into their `$*OUT`. This guarantees that `$*OUT` (where the test results appear) and `$*ERR` (where the diagnostics appear) will stay in sync. The harness will display any diagnostics your tests emit on `$*ERR`. Caveat: this is a bit of a kludge. In particular note that if anything that appears on `$*ERR` looks like a test result, the test harness will get confused. Use this option only if you understand the consequences and can live with the risk. PS: Currently not supported. * `--err=ignore` Ignore the test script' `$*ERR` ## `--trap` The `--trap` option will attempt to trap SIGINT (Ctrl-C) during a test run and display the test summary even if the run is interrupted ## `$*REPO` `prove6` introduces a separation between "options passed to the perl which runs prove" and "options passed to the perl which runs tests"; this distinction is by design. Thus the perl which is running a test starts with the default `$*REPO`. Additional library directories can be added via the `PERL6LIB` environment variable, via `-Ifoo` in `PERL6OPT` or via the `-Ilib` option to `prove6`. tap-harness6-0.0.7/README.md000066400000000000000000000060241342144711000153070ustar00rootroot00000000000000# NAME TAP::Harness # DESCRIPTION An asynchronous TAP framework written in Perl 6. # prove6 This module provides the `prove6` command which runs a TAP based test suite and prints a report. The `prove6` command is a minimal wrapper around an instance of this module. For a detailed documentation on how to use `prove6` [click here](./README-prove6.md) or run `prove6 --help` # SYNOPSIS ```Perl 6 use TAP::Harness; my $harness = TAP::Harness.new(|%args); $harness.run(@tests); ``` # METHODS ## Class Methods ### new ```Perl 6 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::Perl6` Possible values: `TAP::Harness::SourceHandler::Perl6` `TAP::Harness::SourceHandler::Exec` |Language|Handler | |--------|-------------------------------------------------| |Perl 6 |`TAP::Harness::SourceHandler::Perl6.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 ```Perl 6 $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 `::Perl6` * Various `prove6` arguments * 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.0.7/bin/000077500000000000000000000000001342144711000145765ustar00rootroot00000000000000tap-harness6-0.0.7/bin/prove6000066400000000000000000000130001342144711000157340ustar00rootroot00000000000000#! perl6 use TAP; multi sub listall(IO::Path $path where .d) { for $path.dir(:test{ !$^file.starts-with('.') }) -> $entry { listall($entry); } } multi listall(IO::Path $path) { if $path.f && $path.extension eq 't'|'t6' { take ~$path; } } sub load(Str $classname) { my $loaded = try ::($classname); return $loaded if $loaded !eqv Any; require ::($classname); return ::($classname); } multi sub MAIN( Bool :l($lib), Bool :b($blib), Bool :$timer, Int :j($jobs), Bool :$ignore-exit, Bool :$trap, Bool :v($verbose), Bool :$shuffle, Str :$err, Bool :$reverse, Str :e($exec), Str :$harness, Str :$reporter, :I($incdir), Bool :$loose, *@files) { @files = 't' if not @files; die "Invalid value '$err' for --err\n" if defined $err && $err ne any('stderr','merge','ignore'); my %more; with $exec { %more = ( TAP::Harness::SourceHandler::Exec.new($exec.words) ); } else { my @incdirs; @incdirs.unshift($*CWD ~ '/lib') if $lib; @incdirs.unshift($*CWD ~ '/blib/lib') if $blib; @incdirs.prepend(@$incdir) with $incdir; %more = ( TAP::Harness::SourceHandler::Perl6.new(:@incdirs) ); } my $harness-class = $harness ?? load($harness) !! TAP::Harness; with $reporter { %more = load($reporter); } %more = TAP::Verbose if $verbose; my @sources = gather { listall($_.IO) for @files } @sources = $shuffle ?? @sources.pick(*) !! @sources.sort; @sources = @sources.reverse if $reverse; my %args = grep *.value.defined, (:$jobs, :$timer, :$trap, :$ignore-exit, :$err, :$loose); my $run = $harness-class.new(|%args, |%more).run(@sources); exit min($run.result.has-errors, 254); } multi sub MAIN(Bool :$help!) { require Pod::To::Text; my $text = ::('Pod::To::Text').render($=pod[0]); with %*ENV // %*ENV -> $pager { my $proc = shell($pager, :in); $proc.in.print($text); $proc.in.close; } else { say $text; } } multi sub MAIN(Bool :$version!) { say "prove6 0.0.7 on $*PERL"; } =begin pod =head1 NAME prove6 - Run tests through a TAP harness. =head1 USAGE prove6 [options] [files or directories] =head1 OPTIONS Boolean options: -v, Print all test lines. -l, Add 'lib' to the path for your tests (-Ilib). -b, Add 'blib/lib' to the path for your tests --shuffle Run the tests in random order. --ignore-exit Ignore exit status from test scripts. --reverse Run the tests in reverse order. --timer Print elapsed time after each test. --trap Trap Ctrl-C and print summary on interrupt. --help Display this help --version Display the version Options that take arguments: -e, Interpreter to run the tests ('' for compiled tests.) --harness Define test harness to use. See TAP::Harness. --reporter Result reporter to use. See REPORTERS. -j, Run N test jobs in parallel (try 9.) --err=stdout Direct the test's $*ERR to the harness' $*ERR. --err=merge Merge test scripts' $*ERR with their $*OUT. --err=ignore Ignore test script' $*ERR. =head1 NOTES =head2 Default Test Directory If no files or directories are supplied, C looks for all files matching the pattern C. =head2 Colored Test Output Colored test output is the default, but if output is not to a terminal, color is disabled. Color support requires C on Unix-like platforms. If the necessary module is not installed colored output will not be available. PS: Currently not available. =head2 Exit Code If the tests fail C will exit with non-zero status. =head2 C<-e> Normally you can just pass a list of Perl 6 tests and the harness will know how to execute them. However, if your tests are not written in Perl 6 or if you want all tests invoked exactly the same way, use the C<-e> switch: prove6 -e='/usr/bin/ruby -w' t/ prove6 -e='/usr/bin/perl -Tw -mstrict -Ilib' t/ prove6 -e='/path/to/my/customer/exec' =head2 C<--err> =begin item C<--err=stderr> Direct the test's $*ERR to the harness' $*ERR. This is the default behavior. =end item =begin item C<--err=merge> If you need to make sure your diagnostics are displayed in the correct order relative to test results you can use the C<--err=merge> option to merge the test scripts' $*ERR into their $*OUT. This guarantees that $*OUT (where the test results appear) and $*ERR (where the diagnostics appear) will stay in sync. The harness will display any diagnostics your tests emit on $*ERR. Caveat: this is a bit of a kludge. In particular note that if anything that appears on $*ERR looks like a test result the test harness will get confused. Use this option only if you understand the consequences and can live with the risk. PS: Currently not supported. =end item =begin item C<--err=ignore> Ignore the test script' $*ERR =end item =head2 C<--trap> The C<--trap> option will attempt to trap SIGINT (Ctrl-C) during a test run and display the test summary even if the run is interrupted =head2 $*REPO C introduces a separation between "options passed to the perl which runs prove" and "options passed to the perl which runs tests"; this distinction is by design. Thus the perl which is running a test starts with the default C<$*REPO>. Additional library directories can be added via the C environment variable, via -Ifoo in C or via the C<-Ilib> option to C. =end pod # vim:ts=4:sw=4:et:sta tap-harness6-0.0.7/lib/000077500000000000000000000000001342144711000145745ustar00rootroot00000000000000tap-harness6-0.0.7/lib/TAP.pm000066400000000000000000000766341342144711000155760ustar00rootroot00000000000000use v6; unit module TAP:ver<0.0.7>; 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 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) { $supply.act(-> $entry { self.handle-entry($entry); }, done => { self.end-entries(); }, quit => { self.end-entries(); } ); } } 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.status !! Int; } method has-problems($ignore-exit) { @!failed || @!errors || (!$ignore-exit && self.exit-failed); } method exit-failed() { $!exit-status.defined && $!exit-status.status; } } 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() { $!todo-passed || self.has-errors; } method has-errors() { $!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 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 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 } } } enum Formatter::Volume ; role Formatter { has Bool:D $.timer = False; has Formatter::Volume $.volume = Normal; has Bool:D $.ignore-exit = False; } role Reporter { 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 BUILD(:@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 { has IO::Handle $!handle; has Formatter::Text $!formatter; submethod BUILD(:@names, :$!handle = $*OUT, :$volume = Normal, :$timer = False, Bool :$ignore-exit) { $!formatter = Formatter::Text.new(:@names, :$volume, :$timer, :$ignore-exit); } 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)); } method !output(Any $value) { $!handle.print($value); } method print-result(Reporter::Text::Session $session, TAP::Result $report) { self!output($!formatter.format-result($session, $report)); } } class Formatter::Console is Formatter::Text { my &colored = (try require Terminal::ANSIColor) === Nil ?? sub ($text, $) { $text } !! ::('Terminal::ANSIColor::EXPORT::DEFAULT::&colored'); 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 Formatter::Console $!formatter; has Int $!lastlength; has Supplier $events; has Reporter::Console::Session @!active; has Int $!tests; has Int $!fails; submethod BUILD(:@names, IO::Handle :$handle = $*OUT, :$volume = Normal, :$timer = False, Bool :$ignore-exit = False) { $!formatter = Formatter::Console.new(:@names, :$volume, :$timer, :$ignore-exit); $!lastlength = 0; $!events = Supplier.new; @!active .= new; $!tests = 0; 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; return if $!formatter.volume < Quiet; 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; $handle.print($!formatter.format-return($ruler)); } multi receive('update', Str $name, Str $header, Int $number, Int $plan) { if @!active.elems == 1 { my $status = ($header, $number, '/', $plan // '?').join(''); $handle.print($!formatter.format-return($status)); $!lastlength = $status.chars + 1; } else { output-ruler($number == 1); } } multi receive('bailout', Str $explanation) { $handle.print($!formatter.format-failure("Bailout called. Further testing stopped: $explanation\n")); } multi receive('result', Reporter::Console::Session $session, TAP::Result $result) { $handle.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) { $handle.print($!formatter.format-summary($aggregator, $interrupted, $duration)); } $!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 .. 13; 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 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++; } 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; } class Source::File does Source { has Str $.filename; } 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); given $proc.err { my $err = $_; when 'stderr' { #default is correct } when 'merge' { warn "Merging isn't supported yet on Asynchronous streams"; $async.bind-stderr(open($*SPEC.devnull, :w)) } when 'ignore' { $async.bind-stderr(open($*SPEC.devnull, :w)) } when IO::Handle:D { $async.stderr.lines(:close).act({ $err.say($_) }); } when Supply:D { $async.stderr.act({ $err.emit($_) }, :done({ $err.done }), :quit({ $err.quit($^reason) })); } default { die "Unknown error handler"; } } my $process = $async.start; 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.filename.IO.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 { has Str:D $.path is required; has @.args; method make-source(Str:D $name, Any:D :$err) { TAP::Source::Proc.new(:$name, :$!path, :args[ |@!args, $name ], :$err); } } class SourceHandler::Perl6 does SourceHandler::Proc { submethod BUILD(:@incdirs, Str:D :$!path = $*EXECUTABLE.absolute) { @!args = @incdirs.map("-I" ~ *); } method can-handle(Str $name) { 0.5; } } class SourceHandler::Exec does SourceHandler::Proc { method new (*@ ($path, *@args)) { self.bless(:$path, :@args); } method can-handle(Str $name) { 1; } } has SourceHandler @.handlers = SourceHandler::Perl6.new(); has IO::Handle $.handle = $*OUT; has Formatter::Volume $.volume = ?%*ENV ?? Verbose !! Normal; has TAP::Reporter:U $.reporter-class = $!handle.t && $!volume < Verbose ?? TAP::Reporter::Console !! TAP::Reporter::Text; has Str %!env-options = (%*ENV // '').split(':').grep(*.chars).map: { / ^ (.) (.*) $ /; ~$0 => val(~$1) }; has Int:D $.jobs = %!env-options // 1; has Bool:D $.timer = ?%*ENV; subset ErrValue where any(IO::Handle:D, Supply, '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; class Run { has Promise $.waiter handles ; has Promise $!killed; submethod BUILD (Promise :$!waiter, Promise :$!killed) { } method kill(Any:D $reason) { $!killed.break($reason); } } method make-aggregator() { TAP::Aggregator.new(:$!ignore-exit); } method add-handlers(Supply $events) { if $.volume == Verbose { $events.act({ $!handle.say(~$^entry) }, :done({ $!handle.flush }), :quit({ $!handle.flush })); } } method make-source(Str $name) { @!handlers.max(*.can-handle($name)).make-source($name, :$!err); } my &sigint = sub { signal(SIGINT) } method run(*@sources) { my $killed = Promise.new; my $aggregator = self.make-aggregator; my $reporter = $!reporter-class.new(:names(@sources), :$!timer, :$!ignore-exit, :$!volume, :$!handle); my @working; my $waiter = start { my $int = $!trap ?? sigint().tap({ $killed.break("Interrupted"); $int.close(); }) !! Tap; my $begin = now; try { for @sources -> $name { my $session = $reporter.open-test($name); my $source = self.make-source($name); my $parser = TAP::Async.new(:$source, :$killed, :$!loose); $session.listen($parser.events); self.add-handlers($parser.events); @working.push({ :$parser, :$session, :done($parser.waiter) }); next if @working < $!jobs; await Promise.anyof(@working», $killed); reap-finished(); } while @working { await Promise.anyof(@working», $killed); reap-finished(); } CATCH { when "Interrupted" { reap-finished(); @working».».kill; } } } $reporter.summarize($aggregator, ?$killed, now - $begin) if !$killed || $!trap; $int.close if $int; $aggregator; } sub reap-finished() { my @new-working; for @working -> $current { if $current { $aggregator.add-result($current.result); $current.close-test($current.result); } else { @new-working.push($current); } } @working = @new-working; } Run.new(:$waiter, :$killed); } } tap-harness6-0.0.7/t/000077500000000000000000000000001342144711000142715ustar00rootroot00000000000000tap-harness6-0.0.7/t/source-file-test-data000066400000000000000000000000601342144711000203110ustar00rootroot000000000000001..2 ok 1 go not ok 2 stay # diagnostic message tap-harness6-0.0.7/t/source-file.t000066400000000000000000000006401342144711000166730ustar00rootroot00000000000000use v6; use TAP; use Test; plan 4; my $source = TAP::Source::File.new(:filename('t/source-file-test-data')); 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"); tap-harness6-0.0.7/t/string.t000066400000000000000000000074371342144711000157770ustar00rootroot00000000000000use TAP; 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'); 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; }