Comments (7)
I've created a working example which is coming along nicely so far 🙂
from raku.
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 $exercise
, and $version
for any updates.
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 @subs
needs changing here and will check all the subroutines needed in the exercise are present. We need to bail-out
on failure as we won't get past require if a subroutine is missing.
subtest 'Class method(s)', {
plan 1;
ok ::($exercise).can($_), $_ for <my-method>;
}
For classes. We can use the safe call method operator .?my-method
in subsequent tests as it will return Nil if the method doesn't exist.
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. my %cases;
still needs declaring earlier on in the file, but it's better than shoving the JSON into the middle of everything 🙂
from raku.
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.
from raku.
Added in #124.
from raku.
There is another issue tied to this Epic @mienaikage should it also be closed then, or is this epic not completed quite yet?
from raku.
Oh? What's the issue?
from raku.
#36 I think.
from raku.
Related Issues (20)
- [v3] Add tags HOT 1
- Add prerequisites to Practice Exercises HOT 1
- Pass linting checks HOT 1
- [v3] Build Test Runner
- Build Representer and Analyzer HOT 1
- Update status of track
- Update status of Concept Exercises HOT 1
- Launch Tracker 🔴
- 🤖 Sync error for commit 9ec57c
- Extract track-specific help instructions from `config/exercise_readme.go.tmpl`
- Extract track-specific test instructions from `config/exercise_readme.go.tmpl`
- Build representer
- Check docs are up to date HOT 4
- CI is failing HOT 1
- [Syntax highlighting] Hyphen in quote words HOT 2
- Help.md problems with prove6 & test files HOT 3
- exercise-gen.raku doesn't work on Macs due to wrong configlet cache location HOT 1
- [Track Documentation] Need instructions for running lib exercises HOT 1
- Building a training set of tags for raku HOT 21
- New Testcase for the  vs  unicode HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raku.