Skip to content

Instantly share code, notes, and snippets.

@pmurias
Created January 2, 2019 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmurias/696c5a927878657dcfa81b395ecbde34 to your computer and use it in GitHub Desktop.
Save pmurias/696c5a927878657dcfa81b395ecbde34 to your computer and use it in GitHub Desktop.
A script to run tests under precompilation
my $precompiled_tests = 't/precompiled'.IO;
mkdir($precompiled_tests);
for @*ARGS.map(*.IO) -> $file {
my $name-part = $file.relative($file.parent.parent).IO;
my $module = $file.basename.IO.extension('', :parts(0..*));
if ($module ~~ /^\d/) {
$module = 'module_' ~ $module.Str;
}
$module .= subst(/\-/, '_DASH_', :g);
my $module-file = $precompiled_tests.add($name-part.parent).add($module ~ '.pm6');
my $test-file = $precompiled_tests.add($name-part);
mkdir($module-file.parent);
my $module-fh := open(:w, $module-file);
mkdir($test-file.parent);
my $test-fh := open(:w, $test-file);
my @body;
my @finish;
my $in_finish = False;
for $file.lines(:!chomp) -> $line {
if $line ~~ /^\s* use \s* lib/ {
say("use lib: <$line>");
$test-fh.print($line);
} elsif $line ~~ /^use/ {
$module-fh.print($line);
} elsif $line ~~ /^\=finish/ || $in_finish {
$in_finish = True;
@finish.push($line);
} else {
@body.push($line);
}
}
$module-fh.say('sub body is export {');
$module-fh.say(@body.join);
$module-fh.say('}');
$module-fh.print(@finish.join);
$test-fh.say("use lib {$module-file.parent.absolute.perl};\nuse $module;\nbody();\n");
$test-fh.close;
$module-fh.close;
say $test-file.Str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment