softmoth / raku-Template-Mustache

Raku library for the Mustache template format
https://modules.raku.org/dist/Template::Mustache:cpan:SOFTMOTH
Artistic License 2.0
21 stars 19 forks source link

Tests fail on current rakudo #5

Closed moritz closed 9 years ago

moritz commented 9 years ago
$ perl6-m --version
This is perl6 version 2015.04-45-gecd3159 built on MoarVM version 2015.04-20-g10f3ad3

A panda install Task::Star fails with

==> Building Template::Mustache
Compiling lib/Template/Mustache.pm to mbc
==> Testing Template::Mustache
t/01-basic.t ....... ok
t/02-file.t ........ ok
t/03-cascade.t ..... ok
t/04-lambda.t ...... ok
t/10-objects.t ..... ok
t/50-readme.t ...... ok
Failed to get the directory contents of '/home/moritz/.panda-work/1429944310_14/../mustache-spec/specs': chdir failed: Unknown system error
  in method dir at src/gen/m-CORE.setting:18969
  in sub dir at src/gen/m-CORE.setting:19288
  in sub load-specs at t/91-specs.t:26
  in block <unit> at t/91-specs.t:5
t/91-specs.t ....... 
No subtests run 
Failed to get the directory contents of '/home/moritz/.panda-work/1429944310_14/../mustache-spec/specs': chdir failed: Unknown system error
  in method dir at src/gen/m-CORE.setting:18969
  in sub dir at src/gen/m-CORE.setting:19288
  in sub load-specs at t/92-specs-file.t:42
  in block <unit> at t/92-specs-file.t:16
t/92-specs-file.t .. 
No subtests run 
Test Summary Report
-------------------
t/91-specs.t     (Wstat: 0 Tests: 0 Failed: 0)
  Parse errors: No plan found in TAP output
t/92-specs-file.t (Wstat: 0 Tests: 0 Failed: 0)
  Parse errors: No plan found in TAP output
Files=8, Tests=25, 26 wallclock secs ( 0.07 usr  0.02 sys + 21.58 cusr  0.98 csys = 22.65 CPU)
Result: FAIL
softmoth commented 9 years ago

See the README for how to run the full tests. Do you have a suggestion of how to make this automatic for distributions?

moritz commented 9 years ago

You could skip the tests that need them if the mustache specs aren't found.

softmoth commented 9 years ago

Fixed, thank you!

softmoth commented 9 years ago

Issue is not fixed, I can reproduce now with a fresh rakudo and panda build. It does not fail with OS X homebrew version This is perl6 version 2015.03 built on MoarVM version 2015.03.

Although the CATCH block is being called, the program still aborts. Here is a simplified test case:

my @files;
try {
    @files = dir('NONEXISTENT-DIR', :test(rx{ '.json' $ })).sort;
    note "After dir() call, which returned ", @files.perl;
    CATCH {
        @files = (); # Doesn't matter if this is here or not
        note "Caught an error reading nonexistent dir.";
    }
}

# This isn't reached
say "OK, files is ", @files.perl;

And result:

tsmith@ganesha:~/local/src/p6/panda/.panda-work/1430350453_1 (master %=)
[17:53:25] &4 $ perl6 --version
This is perl6 version 2015.04-112-gbcf3f1c built on MoarVM version 2015.04-24-g6ef0f8f

tsmith@ganesha:~/local/src/p6/panda/.panda-work/1430350453_1 (master %=)
[17:53:33] &4 $ perl6 t.pl6
Caught an error reading nonexistent dir.
Failed to get the directory contents of '/Users/tsmith/local/src/p6/panda/.panda-work/1430350453_1/NONEXISTENT-DIR': chdir failed: Unknown system error
  in method dir at src/gen/m-CORE.setting:19003
  in sub dir at src/gen/m-CORE.setting:19322
  in block <unit> at t.pl6:3

tsmith@ganesha:~/local/src/p6/panda/.panda-work/1430350453_1 !127 (master %=)
[17:53:49] &4 $ /usr/local/bin/perl6 --version
This is perl6 version 2015.03 built on MoarVM version 2015.03

tsmith@ganesha:~/local/src/p6/panda/.panda-work/1430350453_1 (master %=)
[17:53:55] &4 $ /usr/local/bin/perl6 t.pl6
After dir() call, which returned Array.new(Failure.new(exception => X::IO::Dir.new(path => "/Users/tsmith/local/src/p6/panda/.panda-work/1430350453_1/NONEXISTENT-DIR", os-error => "chdir failed: Unknown system error")))
OK, files is Array.new(Failure.new(exception => X::IO::Dir.new(path => "/Users/tsmith/local/src/p6/panda/.panda-work/1430350453_1/NONEXISTENT-DIR", os-error => "chdir failed: Unknown system error")))
raydiak commented 9 years ago

Putting a default { ... } block around the code inside the CATCH will fix it. This oversight was hidden by the fact that until recently, a 'try' didn't properly enforce 'use fatal', so your code would continue to run if it was a "soft" Failure, instead of an Exception.

As documented at http://design.perl6.org/S04.html#Exception_handlers , a CATCH is similar to a 'given' block, with the important difference that putting code directly in the block is not the same as having an actual default {}, because not "handling" the exception by an explicit when or default case will cause it to be rethrown. Hope that helps and makes sense. :)

moritz commented 9 years ago

Since dir() produces a Failure, you don't even need a try/catch, you can do something like this:

my @files = given dir('NONEXISTENT-DIR', :test(rx{ '.json' $ })) {
    when Failure {
        note "Caught an error reading nonexistent dir.";
        ();
    }
    default {
        .sort;
    }
};
softmoth commented 9 years ago

Thank you, raydiak and moritz. Issue is actually fixed now, see a0bf17f.