Coder Social home page Coder Social logo

Create generator for tests about raku HOT 7 CLOSED

exercism avatar exercism commented on August 27, 2024
Create generator for tests

from raku.

Comments (7)

m-dango avatar m-dango commented on August 27, 2024 1

I've created a working example which is coming along nicely so far 🙂

from raku.

m-dango avatar m-dango commented on August 27, 2024

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.

m-dango avatar m-dango commented on August 27, 2024

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.

m-dango avatar m-dango commented on August 27, 2024

Added in #124.

from raku.

kotp avatar kotp commented on August 27, 2024

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.

m-dango avatar m-dango commented on August 27, 2024

Oh? What's the issue?

from raku.

kotp avatar kotp commented on August 27, 2024

#36 I think.

from raku.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.