From b28b91d5d2c98fdc0ddb4e873441c6818248dd01 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Thu, 2 Jan 2025 00:00:13 -0500 Subject: [PATCH] Working idris2 error detection Idris 2 doesn't have a failing exit code in this context when it fails to compile an expr given at the command line, we need to check for an error message in the output --- examples/testy/test/src/TestModule/Booleans.idr | 10 ++++++---- lib/IUtils/Compiler.rakumod | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/testy/test/src/TestModule/Booleans.idr b/examples/testy/test/src/TestModule/Booleans.idr index 9545eb7..8fbc4a0 100644 --- a/examples/testy/test/src/TestModule/Booleans.idr +++ b/examples/testy/test/src/TestModule/Booleans.idr @@ -1,9 +1,11 @@ module TestModule.Booleans +import System + -- @@test Boolean Integration passes -passes : IO Bool -passes = pure True +doesWork : IO Bool +doesWork = pure True -- @@test Boolean Integration fails -fails : IO Bool -fails = pure False +dontWork : IO Bool +dontWork = pure False diff --git a/lib/IUtils/Compiler.rakumod b/lib/IUtils/Compiler.rakumod index 6aad5de..14cb559 100644 --- a/lib/IUtils/Compiler.rakumod +++ b/lib/IUtils/Compiler.rakumod @@ -51,6 +51,8 @@ class IdrisError is Exception { qq:to/END/; Error running idris command: $.command Command exited with $.exit-code + StdOut: + {$.out.lines.map(*.indent: 2).join("\n")} END } } @@ -75,7 +77,7 @@ sub idris-run(*@cmd) is export { my $proc = run "idris2", @cmd, :out, :err; my $out = $proc.out.slurp(:close); my $err = $proc.err.slurp(:close); - unless $proc { + if !$proc || $out.contains("Error:") { IdrisError.new( out => $out, err => $err, exit-code => $proc.exitcode, command => @cmd.Str) @@ -117,5 +119,7 @@ sub idris-exec($expr, $file, $output-type? = Unit) is export { exit-code => $proc.exitcode, expr => $expr ).throw; } + # Remove the output file + 'build/exec/iutils_out'.IO.unlink; return $out; }