App::Yath::Filter - Source filter used to make yath preload+fork work without any extra stack frames.
This is a source filter that allows the yath script to change itself into your test file post-fork in preload mode.
yath
The "obvious" was to preload+fork would be to preload, then fork, then use do or require to execute the test file. The problem with the "obvious" way is that your test file is no longer the bottom of the stack, The code that called your test file is. This has implications for stack traces, warnings, caller, and several other things.
do
require
Ideally the test file will be the bottom of the stack, no caller. This is REALLY hard to do. Special form of goto &code cannot do it, and there is no equivilent for files. We also cannot use exec, that defeats the purpose of preload.
goto &code
What this filter does is it prevents the parser from reading the rest of the originally running script (usually yath itself) and instead returns lines from the test file. It also uses some #line magic to make sure filename and line numbers are all correct.
#line
#!/usr/bin/perl BEGIN { my $test_file = do_stuff(); require App::Yath::Filter; App::Yath::Filter->import($test_file); } die "This statement will never be seen! Lines from the test file will be seen instead.";
Sometimes yath gets codeblocks instead of files, this filter will inject lines that call the sub in such cases.
#!/usr/bin/perl BEGIN { require App::Yath::Filter; App::Yath::Filter->import(sub { ok(1, "pass") }); } die "This statement will never be seen!";
The source code repository for Test2-Harness can be found at http://github.com/Test-More/Test2-Harness/.
Copyright 2017 Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
To install Test2::Harness, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test2::Harness
CPAN shell
perl -MCPAN -e shell install Test2::Harness
For more information on module installation, please visit the detailed CPAN module installation guide.