Skip to content

Commit

Permalink
Use Test::Util::is_run instead of Test::Helpers::is-run
Browse files Browse the repository at this point in the history
Previously some tests were relying on using `is-run`, a test helper
function from the rakudo (not roast) repo. This updates the code
to use the `is_run` test helper that is already included in the
roast.
  • Loading branch information
ugexe committed May 19, 2024
1 parent 6aaf159 commit 99b194b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
27 changes: 17 additions & 10 deletions S11-modules/versioning.t
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
use Test;
use lib <t/packages>;
use Test::Helpers;
use lib $?FILE.IO.parent(2).add("packages/Test-Helpers");
use Test::Util;

my $lib-path = $?FILE.IO.parent(2).add("packages/S11-modules/lib");

plan 9;

my @compiler-args = '-I', $lib-path.absolute;

for <c d e.PREVIEW> -> $from-rev {
for <c d e> -> $mod-rev {
subtest "6.$mod-rev from 6.$from-rev", {
plan 8;
for (:core-revision($mod-rev), :raku-version("6.$mod-rev")) -> (:key($routine), :value($response)) {
for (:use(''), :require(" <\&$routine>")) -> (:key($statement), :value($starg)) {
is-run 'use v6.' ~$from-rev ~ '; ' ~ $statement ~ ' Module_6' ~ $mod-rev ~ $starg ~ '; print ' ~ $routine,
"$statement: $routine is $response",
:compiler-args('-I', $lib-path),
:out($response), :err(""), :exitcode(0);
is-run 'use v6.' ~ $from-rev ~ '; print EVAL("' ~ $statement ~ ' Module_6' ~ $mod-rev ~ $starg ~ '; ' ~ $routine ~ '")',
"$statement in EVAL: $routine is $response",
:compiler-args('-I', $lib-path),
:out($response), :exitcode(0);
is_run 'use v6.' ~$from-rev ~ '; ' ~ $statement ~ ' Module_6' ~ $mod-rev ~ $starg ~ '; print ' ~ $routine,
:@compiler-args,
{
:err(''), :exitcode, :out($response),
},
"$statement: $routine is $response";

is_run 'use v6.' ~ $from-rev ~ '; print EVAL("' ~ $statement ~ ' Module_6' ~ $mod-rev ~ $starg ~ '; ' ~ $routine ~ '")',
:@compiler-args,
{
:err(''), :exitcode, :out($response),
},
"$statement in EVAL: $routine is $response";
}
}
}
Expand Down
48 changes: 24 additions & 24 deletions S12-subset/type-subset.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lib <t/packages/>;
use Test;
use Test::Helpers;
use lib $?FILE.IO.parent(2).add("packages/Test-Helpers");
use Test::Util;

plan 11;

Expand Down Expand Up @@ -93,60 +93,60 @@ subtest "When used with smartmatch", {
subtest "When a subset is created with the name of a stubbed package", {
plan 2;

is-run 'class F::B {}; subset F where 5',
:exitcode(0),
is_run 'class F::B {}; subset F where 5',
{ :exitcode(0), },
"Can create subset with a name that exists as a stubbed package";
is-run 'class F::B {}; subset F where 5; die unless F::.keys.grep("B");',
:exitcode(0),
is_run 'class F::B {}; subset F where 5; die unless F::.keys.grep("B");',
{ :exitcode(0) },
"The WHO package is stolen from the replaced stubbed package";
}

subtest "When a subset is declared within a module", {
plan 4;

is-run 'module M { my subset F where 5 }; my M::F $f = 5',
:exitcode(1), :err({ .contains: 'Malformed my' }),
is_run 'module M { my subset F where 5 }; my M::F $f = 5',
{ :exitcode(1), :err({ .contains: 'Malformed my' }), },
"'my' scoped subset in a module is unavailable outside the module";

is-run 'module M { subset F where 5 }; my M::F $f = 5',
:exitcode(0),
is_run 'module M { subset F where 5 }; my M::F $f = 5',
{ :exitcode(0), },
"'our' scoped subset in a module is available outside the module";

is-run 'my module M { subset F where 5 }; my M::F $f = 5',
:exitcode(0),
is_run 'my module M { subset F where 5 }; my M::F $f = 5',
{ :exitcode(0), },
"'our' scoped subset in a module is available outside a my-scoped module";

is-run 'my subset P::F where 5; my P::F $f = 5',
:exitcode(0),
is_run 'my subset P::F where 5; my P::F $f = 5',
{ :exitcode(0), },
"Subset with a stubby package in their name resolve correctly";
}

subtest "When a subset has no where block", {
plan 3;

is-run 'subset MyInt of Int; my MyInt $f = 5',
:exitcode(0),
is_run 'subset MyInt of Int; my MyInt $f = 5',
{ :exitcode(0), },
"subset with of but no where succeeds when type constraint met";

#?rakudo todo 'in RakuAST this is a compile time error, not runtime'
is-run 'subset MyInt of Int; my MyInt $f = 5.0',
:exitcode(1), :err({ .contains: 'Cannot assign a literal of type Rat' }),
is_run 'subset MyInt of Int; my MyInt $f = 5.0',
{ :exitcode(1), :err({ .contains: 'Cannot assign a literal of type Rat' }), },
"subset with of but no where fails when type constraint not met";

is-run 'my Str subset MyStr; die unless Str ~~ MyStr',
:exitcode(0),
is_run 'my Str subset MyStr; die unless Str ~~ MyStr',
{ :exitcode(0), },
"subset form 'my Str subset MyStr' creates essentially a type alias";
}

subtest "When a subset is a subset of a subset", {
plan 2;

is-run 'subset F of Int where * %% 2; subset G of F where * %% 3; my G $g = 6',
:exitcode(0),
is_run 'subset F of Int where * %% 2; subset G of F where * %% 3; my G $g = 6',
{ :exitcode(0), },
"Subset works as 'of' of a subset (assignment meets criteria)";

is-run 'subset F of Int where * %% 2; subset G of F where * %% 3; my $n = 9; my G $g = $n',
:exitcode(1), :err({ .contains: 'Type check failed in assignment ' }),
is_run 'subset F of Int where * %% 2; subset G of F where * %% 3; my $n = 9; my G $g = $n',
{ :exitcode(1), :err({ .contains: 'Type check failed in assignment ' }), },
"Subset works as 'of' of a subset (assigment fails criteria)";
}

Expand Down

0 comments on commit 99b194b

Please sign in to comment.