Skip to content

Commit

Permalink
unskip some passing tests and make is-perl-idempotent more useful
Browse files Browse the repository at this point in the history
Also test some new cases which would have failed before PR#481
  • Loading branch information
skids committed Jul 28, 2015
1 parent f23ee5a commit e6487c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion S06-currying/misc.t
Expand Up @@ -10,7 +10,6 @@ plan 11;
# of the currently prototyped functionality.

is-primed-sig(sub (::T $a, $b, :$c) { }, :($b, :$c), 1);
#?rakudo 10 skip 'RT #125537 interferes with test code here'
is-primed-sig(sub (::T $a, T $b, T :$c) { }, :($b, :$c), 1);
is-primed-sig(sub (::T $a, T @b, T :@c) { }, :(@b, :@c), 1);
is-primed-sig(sub (::T $a, T $b, T :$c) { }, :(:$c), 1, 1);
Expand All @@ -20,6 +19,7 @@ is-primed-sig(sub (::T $a, Array[T] $b, Array[Int] :$c) { }, :(Array[Int] :$c),
is-primed-sig(sub (::T $a, Array[Array[T]] $b, Array[Array[Int]] :$c) { }, :($b, Array[Array[Int]] :$c), 1);
is-primed-sig(sub (::T $a, Array[Positional[T]] $b, Array[Positional[Int]] :$c) { }, :($b, Array[Positional[Int]] :$c), 1);

#?rakudo.jvm skip 'JVM binding problems with non-nominal types'
is-primed-call(sub (::T $a, T $b is copy, T :$c) { "a" ~ $a.perl ~ "b" ~ $b.perl ~ "c" ~ $c.perl }, \("A", :c<C>), ["aAb(Any)cC"], *, Nil);

# How or whether this should fail is less clear to me. Currently LTA error.
Expand Down
25 changes: 23 additions & 2 deletions S06-signature/introspection.t
Expand Up @@ -3,7 +3,7 @@ use Test;
use lib 't/spec/packages';
use Test::Util;
use Test::Idempotence;
plan 125;
plan 133;

# L<S06/Signature Introspection>

Expand Down Expand Up @@ -212,8 +212,30 @@ sub j(*@i) {
is-perl-idempotent(:(@ is parcel where True, @ is copy, Int @ is rw, @ is parcel where True = [2]), :eqv);
is-perl-idempotent(:(% is parcel where True, % is copy, Int % is rw, % is parcel where True = {:a(2)}), :eqv);
is-perl-idempotent(:(& is parcel where True, & is copy, Int & is rw, & is parcel where True = {:a(2)}), :eqv);

is-perl-idempotent(:(::T $a, T $b), :eqv);
# Not sure if this one makes much sense.
is-perl-idempotent(:(::T T $a, T $b), :eqv);

my $f;
is-perl-idempotent($f = -> $a { }, Nil,
:{ rx/Block\|\d+/ => '' });
is-perl-idempotent(-> { }, Nil,
:{ rx/Block\|\d+/ => '' });
is-perl-idempotent(-> ($a) { }, Nil,
:{ rx/Block\|\d+/ => '' });
is-perl-idempotent(-> $ { }, Nil,
:{ rx/Block\|\d+/ => '' });
is-perl-idempotent(-> $a ($b) { }, Nil,
:{ rx/Block\|\d+/ => '' });

}

role A { sub a ($a, $b, ::?CLASS $c) { }; method foo { &a } };
class C does A { };
my $rolesig = try C.foo.signature.perl;
is $rolesig, ':($a, $b, ::?CLASS $c)', ".perl of a sigature that has ::?CLASS";

# RT #123895
{
is_run q[sub wtvr(|) {}; &wtvr.perl], { err => "", out => "" }, ".perl on unnamed | parameters doesn't err";
Expand All @@ -229,5 +251,4 @@ sub j(*@i) {
'";;" in signature stringifies correctly using .perl';
}


# vim: ft=perl6
15 changes: 10 additions & 5 deletions packages/Test/Idempotence.pm
Expand Up @@ -5,26 +5,30 @@ use Test;
sub is-perl-idempotent($thing, $desc?, %subst?, :$eqv = False) is export {
my $fail = 1;
my $stage1p;
my $stage1r;
my $stage2;
my $stage2p;
subtest {
plan $eqv ?? 3 !! 2;
try {
$stage1p = $thing.perl;
my $stage1r = $stage1p;
$stage1r = $stage1p;
for %subst.kv -> $old, $new {
$stage1r ~~ s:g/$old/$new/;
}
$stage2 = EVAL $stage1r;
$stage2p = $stage2.perl;
for %subst.kv -> $old, $new {
$stage2p ~~ s:g/$old/$new/;
}
CATCH {
default { $fail = $_ };
}
}
if ($eqv) {
ok $thing eqv $stage2, "Result is same as original";
}
is $stage1p, $stage2p, "Same .perl output";
is $stage1r, $stage2p, "Same .perl output";
is $fail, 1, "...and no failures.";
}, $desc // (".perl of " ~ $thing.gist ~ " is idempotent");
}
Expand Down Expand Up @@ -85,9 +89,10 @@ hash, like so:
...in which case any keys that are Regex objects are used as such.
The substitutions are performed on $thing.perl before sending it to EVAL.
They are intended to be used to gloss over things that C<.perl> cannot
be reasonably expected to emit useable code for, and should be used sparingly.
The substitutions are performed on $thing.perl before sending it to EVAL,
and again on the result of the EVAL. They are intended to be used to gloss
over things that C<.perl> cannot be reasonably expected to emit useable code
for, and should be used sparingly.
The C<$desc> simply sets the description of the test which is output.
Expand Down

0 comments on commit e6487c5

Please sign in to comment.