-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create generator for tests #63
Comments
Recently I've been putting code in exercises to allow as much interchangeability as possible. We can likely use it in a generator. #!/usr/bin/env perl6
use v6;
use Test;
use lib IO::Path.new($?FILE).parent.path;
my $exercise = 'MyExercise';
my $version = v1;
my $module = %*ENV<EXERCISM> ?? 'Example' !! $exercise;
plan 2;
use-ok $module or bail-out;
require ::($module);
if ::($exercise).^ver !~~ $version {
warn "\nExercise version mismatch. Further tests may fail!"
~ "\n$exercise is $(::($exercise).^ver.gist). "
~ "Test is $($version.gist).\n";
bail-out 'Example version must match test version.' if %*ENV<EXERCISM>;
} It should be possible to drop this into any test with only a change to my @subs;
BEGIN { @subs = <&my-sub> };
subtest 'Subroutine(s)', {
plan 1;
eval-lives-ok "use $module; ::('$_').defined or die '$_ is not defined.'", $_ for @subs;
} or bail-out 'All subroutines must be defined and exported.';
require ::($module) @subs.eager; For modules with subroutines. Only subtest 'Class method(s)', {
plan 1;
ok ::($exercise).can($_), $_ for <my-method>;
} For classes. We can use the safe call method operator INIT {
require JSON::Tiny <&from-json>;
%cases := from-json 「
{"my":"json"}
」
} We can stick this at the bottom of the test suite for any JSON we use from canonical data. |
I've created a working example which is coming along nicely so far 🙂 |
The script could use some improvements in terms of user friendliness, but I believe it is functionally sound. I've added the generator and template in #124, along with a handful of yaml files for some exercises, which all give functional test files when put through the generator. |
Added in #124. |
There is another issue tied to this Epic @mienaikage should it also be closed then, or is this epic not completed quite yet? |
Oh? What's the issue? |
#36 I think. |
This will have the advantage of directly using the canonical data in x-common.
An example of doing this can be found with the Go and Ruby tracks.
Go executable
Go test helper
ruby generate executable
ruby generate library
Sample test cases handler
The text was updated successfully, but these errors were encountered: