Improve test running
Move test running to a method on the Test class and improve output printing logic.
This commit is contained in:
parent
09ac7506ee
commit
4b2c2eb4dd
3 changed files with 40 additions and 24 deletions
|
@ -3,6 +3,8 @@ unit module IUtils;
|
|||
|
||||
need IUtils::IDEMode;
|
||||
|
||||
use Terminal::ANSIColor;
|
||||
|
||||
use IUtils::Regexes;
|
||||
use IUtils::Compiler;
|
||||
|
||||
|
@ -16,6 +18,38 @@ class Test {
|
|||
has Str:D $.expr is required;
|
||||
#| The output type of the test
|
||||
has ExprOutput:D $.output-type is required;
|
||||
|
||||
#| Run this test, and return true if it failed, false if it passed
|
||||
method run(IO::Path:D $source, Int:D $indent-level? = 4 --> Bool) {
|
||||
CATCH {
|
||||
when ExpressionError {
|
||||
say "{colored '+', 'red'} $.name: {colored 'FAIL', 'red bold'}"
|
||||
.indent($indent-level);
|
||||
say "{colored('exit code', 'red')}: {$_.exit-code}"
|
||||
.indent($indent-level + 2);
|
||||
if $_.out.trim {
|
||||
say colored('stdout:', 'underline')
|
||||
.indent($indent-level + 2);
|
||||
say $_.out.trim.lines.map(*.indent($indent-level + 2))
|
||||
.join("\n");
|
||||
}
|
||||
if $_.err.trim {
|
||||
say colored('stderr:', 'underline')
|
||||
.indent($indent-level + 2);
|
||||
say $_.err.trim.lines.map(*.indent($indent-level + 2))
|
||||
.join("\n");
|
||||
}
|
||||
return True;
|
||||
}
|
||||
}
|
||||
|
||||
idris-exec $.expr, $source.relative, $.output-type;
|
||||
# The exception handler graps flow if the test failed, here the test passed
|
||||
my $output =
|
||||
"{colored '+', 'green'} $.name: {colored 'pass', 'green'}";
|
||||
say $output.indent($indent-level);
|
||||
return False;
|
||||
}
|
||||
}
|
||||
|
||||
#| Structure representing the tests in a module
|
||||
|
@ -60,7 +94,6 @@ class PackageInfo {
|
|||
when * eq 'Bool' {succeed Boolean};
|
||||
when * eq 'Either' {succeed Either};
|
||||
};
|
||||
say $output-type;
|
||||
my $test =
|
||||
Test.new(name => $match<test-name>.Str,
|
||||
expr => $match<expression-name>.Str,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue