Skip to content

Commit

Permalink
Some more CompUnit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jul 9, 2014
1 parent 16320f1 commit 62446ba
Showing 1 changed file with 60 additions and 11 deletions.
71 changes: 60 additions & 11 deletions S22-package-format/local.t
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
use v6;
use Test;

plan 21;
plan 38;

chdir 't/spec/S22-package-format';
my $cwd = $*CWD;
my $cwd := $*CWD;
my $nanoonanoo := '
use v6;
class NanooNanoo { }
';
my $module := 'NanooNanoo';
my $ext := 'pm';
my $src := "$module.$ext";
my $srcdir := 'local-file-src';
my $srcsrc := "$srcdir/$src";
my $cmpdir := 'local-file-cmp';
my $cmpsrc := "$cmpdir/$src";
my $cmpcmp := "$cmpdir/$module\.{$*VM.precomp-ext}";

my $initialized = True; # try to cleanup from here on out
ok mkdir($srcdir), "Could we create '$srcdir'";
ok $srcsrc.IO.spurt($nanoonanoo), "Could we create '$srcsrc'";
ok mkdir($cmpdir), "Could we create $cmpdir";
ok $cmpsrc.IO.spurt($nanoonanoo), "Could we create '$cmpsrc'";

#?rakudo.parrot skip 'cannot do signals in parrot';
ok signal(SIGINT).tap( {die} ), 'install Ctrl-C handler for cleanup in END';

my $curlf1 = CompUnitRepo::Local::File.new(".");
isa_ok $curlf1, CompUnitRepo::Local::File;
Expand All @@ -17,21 +38,49 @@ my $curlf2 = CompUnitRepo::Local::File.new(".");
isa_ok $curlf2, CompUnitRepo::Local::File;
ok $curlf1 === $curlf2, 'are they the same';

my $compdir = 'localfile';
my $curlf3 = CompUnitRepo::Local::File.new($compdir);
isa_ok $curlf3, CompUnitRepo::Local::File;
ok $curlf2 !=== $curlf3, 'are they different';
isa_ok $curlf3.path, IO::Path;
is $curlf3.path, IO::Path.new("$cwd/$compdir"), "is '$compdir' looking at the right dir";
my $curlf = CompUnitRepo::Local::File.new($srcdir);
isa_ok $curlf, CompUnitRepo::Local::File;
ok $curlf2 !=== $curlf, 'are they different';
isa_ok $curlf.path, IO::Path;
is $curlf.path, IO::Path.new("$cwd/$srcdir"), "is '$srcdir' looking at the right dir";

my $compunit;
for False, True -> $no-precomp {
my $what = $no-precomp ?? ' with :no-precomp' !! '';
my $candidates = $curlf3.candidates('NanooNanoo',:$no-precomp);

# all candidates
my $candidates = $curlf.candidates(:$no-precomp);
ok $candidates ~~ Positional, "did we get a Positional$what";
is $candidates.elems, 1, "did we get 1 candidate$what";
$compunit = $candidates[0];
isa_ok $compunit, CompUnit;

# a specific existing candidate
$candidates = $curlf.candidates('NanooNanoo',:$no-precomp);
ok $candidates ~~ Positional, "did we get a Positional$what";
is $candidates.elems, 1, "did we get 1 candidate$what";
isa_ok $candidates[0], CompUnit;
my $second = $candidates[0];
isa_ok $second, CompUnit;
ok $compunit === $second, 'did we get the same CompUnit object';

$candidates = $curlf3.candidates('Shazbat',:$no-precomp);
# a specific non-existing candidate
$candidates = $curlf.candidates('Shazbat',:$no-precomp);
ok $candidates ~~ Positional, "did we get a Positional$what";
is $candidates.elems, 0, "did we get 0 candidates$what";
}

is $compunit.from, 'Perl6', "is the language 'Perl6'";
is $compunit.name, $module, "is the name '$module'";
is $compunit.extension, $ext, "is the extension '$ext'";
is $compunit.path, "$cwd/$srcsrc", "is the path '$srcsrc'";

# always cleanup
END {
if $initialized {
try unlink $srcsrc;
try rmdir $srcdir;
try unlink $cmpsrc;
try unlink $cmpcmp;
try rmdir $cmpdir;
}
}

0 comments on commit 62446ba

Please sign in to comment.