I am writing a new Perl 6 project for work, and would like to be able to test whether all parts can be use
d correctly. For this, I'm using the use-ok
subroutine from the Test
module. I'm trying to easily test all module files using the following code:
"META6.json".IO.slurp.&from-json<provides>
.grep(*.value.starts-with("lib")).Hash.keys
.map({ use-ok $_ })
My issue here is that there are a few files that contain a definition for a MAIN
subroutine. From the output I see when running prove -e 'perl6 -Ilib' t
, it looks like one of the files is having their MAIN
executed, and then the testing stops.
I want to test whether these files can be use
d correctly, without actually running the MAIN
subs that are defined within them. How would I do this?
The MAIN
of a file is only executed if it is in the top level of the mainline of a program. So:
sub MAIN() is export { } # this will be executed when the mainline executes
However, if you move the MAIN
sub out of the toplevel, it will not get executed. But you can still export it.
{
sub MAIN() is export { } # will *not* execute
}
Sorry for it taking so long to answer: it took a while for me to figure what the question was :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With