iutils-raku/bin/iutils

91 lines
3.6 KiB
Plaintext
Raw Normal View History

2024-12-30 11:08:48 +00:00
#!/usr/bin/env raku
use v6.d;
2024-12-31 19:32:50 +00:00
use Terminal::ANSIColor;
2024-12-30 13:43:26 +00:00
use IUtils;
2024-12-31 16:28:24 +00:00
use IUtils::Regexes;
2024-12-31 19:11:46 +00:00
use IUtils::Compiler;
2024-12-30 13:32:52 +00:00
2024-12-31 19:11:46 +00:00
# TODO: Add filtering for tests based on module/name
2024-12-31 20:35:04 +00:00
# TODO: Move some of this functionality into methods for the relevant structs
2024-12-31 16:25:05 +00:00
#| Execute the tests in an idris project
multi MAIN(
"test",
Str $project-path?, #= Base directory of the project, defaults to $*CWD
) {
# CD into the project path if needed
chdir($project-path.IO.resolve: :completely) if $project-path;
# Scan for our packages
my @packages = scan-packages;
2024-12-31 19:11:46 +00:00
# Collect runables
my @runables = @packages.map: *.runnables;
# Run the tests
my $basedir = $*CWD;
2024-12-31 20:00:20 +00:00
my $total-failures = 0;
2024-12-31 19:11:46 +00:00
for @runables -> $runable {
2024-12-31 20:00:20 +00:00
my $package-failures = 0;
2024-12-31 19:11:46 +00:00
# Make sure the package is built
pack-build $runable.ipkg.relative;
# CD to the local directory to make sure idris can exec the expressions
indir $runable.ipkg.parent, {
next unless $runable.tests.elems > 0;
2024-12-31 19:32:50 +00:00
my $test-module-name =
colored($runable.ipkg.relative($basedir), 'magenta bold');
say "{colored '*', 'yellow bold'} Testing $test-module-name";
2024-12-31 19:11:46 +00:00
for $runable.tests.keys -> $module-name {
2024-12-31 20:00:20 +00:00
my $module-failures = 0;
2024-12-31 19:11:46 +00:00
my $module = $runable.tests{$module-name};
next unless $module.tests.elems > 0;
2024-12-31 19:32:50 +00:00
my $colored-module = colored $module-name, 'cyan bold';
say "{colored '**', 'magenta bold'} Testing $colored-module"
.indent(2);
2024-12-31 19:11:46 +00:00
for $module.tests -> $test {
try {
2024-12-31 20:00:20 +00:00
# FIXME this doesn't actually capture the exit code
2024-12-31 23:12:35 +00:00
idris-exec $test.expr, $module.source.relative, $test.output-type;
2024-12-31 19:11:46 +00:00
}
my $testf = colored $test.name, 'underline';
2024-12-31 23:12:35 +00:00
if $! ~~ ExpressionError {
2024-12-31 20:35:04 +00:00
# TODO: Don't show stdout if its empty
2024-12-31 20:00:20 +00:00
$module-failures += 1;
2024-12-31 19:32:50 +00:00
say "{colored '+', 'red'} $testf: {colored 'FAIL', 'red bold'}"
.indent(4);
2024-12-31 19:11:46 +00:00
say "stdout:".indent(6);
2024-12-31 20:35:04 +00:00
say $!.err.lines.map(*.indent(8)).join("\n");
say (colored 'exit code', 'red').indent(6),
": {$!.exit-code}";
2024-12-31 23:12:35 +00:00
} elsif $! {
die $!;
2024-12-31 19:11:46 +00:00
} else {
2024-12-31 19:32:50 +00:00
say "{colored '+', 'green'} $testf: {colored 'pass', 'green'}"
.indent(4);
2024-12-31 19:11:46 +00:00
}
}
2024-12-31 20:00:20 +00:00
if $module-failures == 0 {
say "All $colored-module ".indent(4),
colored('tests passed', 'green underline');
} else {
say "$module-failures $colored-module ".indent(4),
colored('tests failed', 'red bold underline');
}
$package-failures += $module-failures;
}
if $package-failures == 0 {
say "All $test-module-name ".indent(2),
colored('tests passed', 'green underline');
} else {
say "$package-failures $test-module-name ".indent(2),
colored('tests failed', 'red bold underline');
2024-12-31 19:11:46 +00:00
}
2024-12-31 20:00:20 +00:00
$total-failures += $package-failures;
2024-12-31 16:25:05 +00:00
}
}
say '';
if $total-failures == 0 {
say 'All ', colored('tests passed', 'green underline');
} else {
say $total-failures, ' ', colored('tests failed', 'red bold underline');
}
2024-12-31 16:25:05 +00:00
}