From 013f8500dfb7becc9346314e4eef9172da503ca0 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Tue, 31 Dec 2024 19:32:50 +0000 Subject: [PATCH 1/3] Slightly colorized output --- META6.json | 3 ++- bin/iutils | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/META6.json b/META6.json index 0918894..5bcad19 100644 --- a/META6.json +++ b/META6.json @@ -7,7 +7,8 @@ "Nathan McCarty " ], "depends": [ - "paths" + "paths", + "Terminal::ANSIColor" ], "provides": { "IUtils": "lib/IUtils.rakumod", diff --git a/bin/iutils b/bin/iutils index 9c2671d..29a6357 100755 --- a/bin/iutils +++ b/bin/iutils @@ -1,5 +1,8 @@ #!/usr/bin/env raku use v6.d; + +use Terminal::ANSIColor; + use IUtils; use IUtils::Regexes; use IUtils::Compiler; @@ -24,25 +27,32 @@ multi MAIN( # CD to the local directory to make sure idris can exec the expressions indir $runable.ipkg.parent, { next unless $runable.tests.elems > 0; - say "** Testing {$runable.ipkg.relative: $basedir}"; + my $test-module-name = + colored($runable.ipkg.relative($basedir), 'magenta bold'); + say "{colored '*', 'yellow bold'} Testing $test-module-name"; for $runable.tests.keys -> $module-name { my $module = $runable.tests{$module-name}; next unless $module.tests.elems > 0; - say "-- Testing $module-name".indent(2); + my $colored-module = colored $module-name, 'cyan bold'; + say "{colored '**', 'magenta bold'} Testing $colored-module" + .indent(2); for $module.tests -> $test { try { idris-exec $test, $module.source.relative; } + my $testf = colored $test, 'underline'; if $! { my $stdout = $1.err.lines.map(*.indent(8)).join("\n"); - say "+ $test: FAIL".indent(4); + say "{colored '+', 'red'} $testf: {colored 'FAIL', 'red bold'}" + .indent(4); say "stdout:".indent(6); $!.err.lines.map(*.indent(8)).join("\n"); say "stderr:".indent(6); $!.err.lines.map(*.indent(8)).join("\n"); say "exit code: {$!.exit-code}" } else { - say "+ $test: Pass".indent(4); + say "{colored '+', 'green'} $testf: {colored 'pass', 'green'}" + .indent(4); } } } From c5ff9186409083cbe46cf1b2414f2f9743aa6406 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Tue, 31 Dec 2024 20:00:20 +0000 Subject: [PATCH 2/3] Failure reporting --- bin/iutils | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bin/iutils b/bin/iutils index 29a6357..f0076e8 100755 --- a/bin/iutils +++ b/bin/iutils @@ -21,7 +21,9 @@ multi MAIN( my @runables = @packages.map: *.runnables; # Run the tests my $basedir = $*CWD; + my $total-failures = 0; for @runables -> $runable { + my $package-failures = 0; # Make sure the package is built pack-build $runable.ipkg.relative; # CD to the local directory to make sure idris can exec the expressions @@ -31,6 +33,7 @@ multi MAIN( colored($runable.ipkg.relative($basedir), 'magenta bold'); say "{colored '*', 'yellow bold'} Testing $test-module-name"; for $runable.tests.keys -> $module-name { + my $module-failures = 0; my $module = $runable.tests{$module-name}; next unless $module.tests.elems > 0; my $colored-module = colored $module-name, 'cyan bold'; @@ -38,10 +41,12 @@ multi MAIN( .indent(2); for $module.tests -> $test { try { + # FIXME this doesn't actually capture the exit code idris-exec $test, $module.source.relative; } my $testf = colored $test, 'underline'; if $! { + $module-failures += 1; my $stdout = $1.err.lines.map(*.indent(8)).join("\n"); say "{colored '+', 'red'} $testf: {colored 'FAIL', 'red bold'}" .indent(4); @@ -55,7 +60,30 @@ multi MAIN( .indent(4); } } + 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'); + } + $total-failures += $package-failures; + say ''; + } + say ''; + if $total-failures == 0 { + say 'All ', colored('tests passed', 'green underline'); + } else { + say $total-failures, ' ', colored('tests failed', 'red bold underline'); } } } From cab0cb5ce150e5330dcd19843bc153c7710ae69c Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Tue, 31 Dec 2024 20:35:04 +0000 Subject: [PATCH 3/3] clean up error display --- bin/iutils | 10 +++++----- lib/IUtils/Compiler.rakumod | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/iutils b/bin/iutils index f0076e8..2000339 100755 --- a/bin/iutils +++ b/bin/iutils @@ -8,6 +8,7 @@ use IUtils::Regexes; use IUtils::Compiler; # TODO: Add filtering for tests based on module/name +# TODO: Move some of this functionality into methods for the relevant structs #| Execute the tests in an idris project multi MAIN( "test", @@ -46,15 +47,14 @@ multi MAIN( } my $testf = colored $test, 'underline'; if $! { + # TODO: Don't show stdout if its empty $module-failures += 1; - my $stdout = $1.err.lines.map(*.indent(8)).join("\n"); say "{colored '+', 'red'} $testf: {colored 'FAIL', 'red bold'}" .indent(4); say "stdout:".indent(6); - $!.err.lines.map(*.indent(8)).join("\n"); - say "stderr:".indent(6); - $!.err.lines.map(*.indent(8)).join("\n"); - say "exit code: {$!.exit-code}" + say $!.err.lines.map(*.indent(8)).join("\n"); + say (colored 'exit code', 'red').indent(6), + ": {$!.exit-code}"; } else { say "{colored '+', 'green'} $testf: {colored 'pass', 'green'}" .indent(4); diff --git a/lib/IUtils/Compiler.rakumod b/lib/IUtils/Compiler.rakumod index d8bfcba..90054c6 100644 --- a/lib/IUtils/Compiler.rakumod +++ b/lib/IUtils/Compiler.rakumod @@ -66,6 +66,7 @@ sub idris-run(*@cmd) is export { return $out; } +# TODO: Special handling for IO Bool to make this eaiser #| Exec the expression with the given name in the given file sub idris-exec($expr, $file) is export { idris-run '--find-ipkg', '--exec', $expr, $file