module Test::Corpus:auth<github:flussence>:ver<1.0.0>;
use Test;

sub test-basename {
    # <!--[if IE]>
    return ($*PROGRAM_NAME ~~ m{ '/' (<-[/]>+) $ })[0]
        if $*EXECUTABLE_NAME ~~ /Niecza/;
    # <![end if]-->

    return $*PROGRAM_NAME.path.basename;
}

# Convenience sub for testing filter functions of arity 1
sub simple-test(&func) is export {
    return sub ($in, $out, $filename) {
        is &func($in.slurp), $out.slurp, $filename;
    }
}

# Runs tests on a callback. This gets passed an input filehandle, an output
# filehandle, and the filename each is derived from.
sub run-tests(
    &test,
    Str :$input-dir = "t_files/{test-basename}.input",
    Str :$output-dir = "t_files/{test-basename}.output",
    Int :$tests-per-block = 1,
    Int :$add-to-plan = 0
) is export {
    my @files = dir($output-dir);
    plan $tests-per-block * @files + $add-to-plan;

    for @files -> $filename {
        my $in = open("$input-dir/$filename");
        my $out = open("$output-dir/$filename");

        &test($in, $out, $filename);
    }
}

=comment vim: set tw=80 :
