Running mixed Perl 5 and Perl 6 tests.
Those two tricks are especially useful when refactoring big codebase from Perl 5 to Perl 6. Such process may take weeks or even a months, and you will encounter two cases:
1. Some features are still in Perl 5, some are fully refactored to Perl 6. So you want to
run separate Perl 5 and Perl 6 test files on single prove command. Prove is not very smart. It does not peek into test files to use correct interpreter (Perl 5 is assumed) and it does not recognize ".t6" extension some people use. But there is a solution. First create your test files.
#!/usr/bin/env perl use v5; use Test::Simple 'tests' => 1; ok 1, 'Hello Perl 5';
#!/usr/bin/env perl6 use v6; use Test; plan 1; ok 1, 'Hello Perl 6';
Using shebang is crucial here because it will cause the system to use proper interpreter. Now make tests executable. And explicitly pass empty interpreter to prove, so it won't enforce anything.
$ prove -e '' t/perl5.t .. ok t/perl6.t .. ok All tests successful. Files=2, Tests=2, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.19 cusr 0.03 csys = 0.24 CPU) Result: PASS
2. Some feature components are entangled. For example you have communication protocol with client already refactored to Perl 6 but server still in Perl 5. To test them you need to interpolate Perl 6 test within Perl 5 test and combine test output. One of the Perl 5 core modules - Tap::Parser - has just what we need. First create your test files (we will use Perl 6 version from example above).
t/interpolated.t#!/usr/bin/env perl use v5; use Tap::Parser; use Test::Simple 'tests' => 3; ok 1, 'Hello Perl 5'; my $parser = TAP::Parser->new( { 'exec' => [ 'perl6', 't/perl6.t' ] } ); while ( my $result = $parser->next ) { next unless $result->is_test; ok $result->is_ok, $result->description; } ok 1, 'Bye Perl 5';
Tap parser allows to run any test code using any interpreter from your script and access those test results using nice, OO interface. Line "ok $result->is_ok" is what makes foreign test result your own.
$ perl t/interpolated.t 1..3 ok 1 - Hello Perl 5 ok 2 - - Hello Perl 6 ok 3 - Bye Perl 5
This is the very basic way to interpolate tests. As you may notice description output from Perl 6 is a bit messy, also comments, subtests, bailouts are not handled yet. However with excellent TAP::Parser documentation you should be able to implement more complex scenarios in no time.
Stay calm an keep testing!
prove also includes the --source option to allow you to use custom TAP::Parser::SourceHandlers.