Skip to content

Commit

Permalink
Adapt Test::Compile to new CompUnit architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Nov 28, 2015
1 parent f13d3c5 commit 974205d
Showing 1 changed file with 3 additions and 124 deletions.
127 changes: 3 additions & 124 deletions packages/Test/Compile.pm
Expand Up @@ -167,88 +167,8 @@ sub init_compunit {
diag "Cannot do any precomp tests; Could not create a file";
return;
}
EVAL "use lib <$precomp_dir>;";

@compunits_to_delete.push("$fp.pm6");
try { $cu = EVAL '
CompUnit.new("$fp.pm6");
';
CATCH {
# For some reason rmdir does not work here. Rely on END until that gets sussed.
# my $pd = $precomp_dir;
# $precomp_dir = False;
# try rmdir($pd);
diag "Cannot do any precomp tests because: " ~ $_;
return;
}
}
unless $cu.defined {
# For some reason rmdir does not work here. Rely on END until that gets sussed.
# my $pd = $precomp_dir;
# $precomp_dir = False;
# try rmdir($pd);
diag "Cannot do any precomp tests, CompUnit did not instantiate.";
return;
}
try {
EVAL '
$cu.precomp;
';
CATCH {
diag "Cannot do real precomp tests, precomp failed because: " ~ $_;
# But we still may be able to load without precomp
diag "Will try to run such tests anyway direct from source.";
$compunit_available = "Source";
# Very weird but we need an additional CATCH here or it throws.
CATCH { }
}
}
@compunits_to_delete.push($cu.precomp-path) if $cu.precomp-path;
try {
EVAL '
# CompUnit.load is broken right now.
# $cu.load($fp, { from => "Perl6" });
# So we hit some rakudo internals to do the same thing
use nqp;
my Mu $p6ml := nqp::gethllsym("perl6", "ModuleLoader");
if ($compunit_available eq "Source") {
$cu = $p6ml.load_module("$fn", { },
:chosen{
:pm("$fp.pm6")
}
);
}
else {
$cu = $p6ml.load_module("$fn", { },
:chosen{
:pm("$fp.pm6")
:load($cu.precomp-path)
:key($cu.precomp-path)
}
);
}
';
CATCH {
delete_compunits;
my $pd = $precomp_dir;
$precomp_dir = False;
try rmdir($pd);
$compunit_available = False;
diag "Still cannot do any precomp tests, load failed because: " ~ $_;
return;
}
}
# XXX Actually I am not sure how to test for a "{ }" created in .nqp
# versus any legit return value, but this seems to let the successes through.
if nqp::ishash($cu) {
delete_compunits;
my $pd = $precomp_dir;
$precomp_dir = False;
try rmdir($pd);
$compunit_available = False;
diag "Still cannot do any precomp tests, load failed.";
return;
}
delete_compunits;
$compunit_available ||= "Precomp";
}
Expand Down Expand Up @@ -294,46 +214,19 @@ multi sub do_compunit($code_as_str, $reason, $leavefiles = False,
}
@compunits_to_delete.push("$fp.pm6");
my $cr;
try EVAL '
$cu = CompUnit.new("$fp.pm6");
$cr = $cu.precomp;
';
$cu = $*REPO.need(CompUnit::DependencySpecification.new(:short-name($fn)));
if defined $! {
flunk($reason);
diag($!);
delete_compunits($leavefiles);
return;
}
unless $cr {
# Would be nice to divert the compiler errors here somehow.
flunk($reason);
diag("Failed to create CompUnit, normal compilation failure.");
delete_compunits($leavefiles);
return;
}
if not defined $cu {
flunk($reason);
diag("Failed to create CompUnit, no but Failure thrown.");
delete_compunits($leavefiles);
return;
}
@compunits_to_delete.push($cu.precomp-path);
try EVAL '
use nqp;
# CompUnit.load is broken right now.
# $cu.load($fp, { from => "Perl6" });
# So we hit some rakudo internals to do the same thing
my Mu $p6ml := nqp::gethllsym("perl6", "ModuleLoader");
$cu = $p6ml.load_module("$fn", { },
:chosen{
:pm("$fp.pm6")
:load($cu.precomp-path)
:key($cu.precomp-path)
}
);
';
if defined $! {
flunk($reason);
diag($!);
Expand All @@ -352,21 +245,7 @@ multi sub do_compunit($code_as_str, $reason, $leavefiles = False,
return;
}
@compunits_to_delete.push("$fp.pm6");
try EVAL '
use nqp;
$cu = CompUnit.new("$fp.pm6");
# CompUnit.load is broken right now.
# $cu.load($fp, { from => "Perl6" });
# So we hit some rakudo internals to do the same thing
my Mu $p6ml := nqp::gethllsym("perl6", "ModuleLoader");
$cu = $p6ml.load_module("$fn", { },
:chosen{
:pm("$fp.pm6")
}
);
';
my $comp-unit = $*REPO.need(CompUnit::DependencySpecification.new(:short-name($fn)));
if defined $! {
flunk($reason);
diag($!);
Expand Down

0 comments on commit 974205d

Please sign in to comment.