on master help sign in
Merge pull request #4320 from yanok/exec-fail

Print error message if :exec'ed program exits with failure

commite96f3bbec9baa94b43fa71d3bf2a97eb0c91399b authorAhmad Salim Al-Sibahi <asal@itu.dk> dateTue 13 Feb 2018, 17:02 (9 years ago) parent18d9c5e8e2aff5
8 files changed+27−3
CHANGELOG.md+5 src/Idris/REPL.hs+11−2 test/TestData.hs+2−1 test/interpret003/expected+1 test/interpret003/input+1 test/interpret003/interpret003.idr+4 test/interpret003/run+3 test/interpret003/test
CHANGELOG.md+5
@@ -1,3 +1,8 @@
1+# New in 1.2.*
2+
3++ REPL now prints an error message if program compiled by `:exec` terminates
4+ abnormally.
5+
16# New in 1.2.0
27
38## Language updates
src/Idris/REPL.hs+11−2
@@ -1264,8 +1264,17 @@ process fn (Execute tm)
12641264 ir <- compile t tmpn (Just m)
12651265 runIO $ generate t (fst (head (idris_imported ist))) ir
12661266 case idris_outputmode ist of
1267− RawOutput h -> do runIO $ rawSystem progName []
1268− return ()
1267+ RawOutput h ->
1268+ do res <- runIO $ rawSystem progName []
1269+ case res of
1270+ ExitSuccess -> return ()
1271+ ExitFailure err ->
1272+ ifail $ "Compiled program " ++
1273+ if err < 0
1274+ then "was killed by signal " ++
1275+ show (0 - err)
1276+ else "terminated with exit code " ++
1277+ show err
12691278 IdeMode n h -> runIO . hPutStrLn h $
12701279 IdeMode.convSExp "run-program" tmpn n)
12711280 (\e -> getIState >>= iRenderError . flip pprintErr e)
test/TestData.hs+2−1
@@ -183,7 +183,8 @@ testFamiliesData = [
183183 ( 8, ANY )]),
184184 ("interpret", "Interpret",
185185 [ ( 1, ANY ),
186− ( 2, ANY )]),
186+ ( 2, ANY ),
187+ ( 3, C_CG )]),
187188 ("io", "IO monad",
188189 [ ( 1, C_CG ),
189190 ( 2, ANY ),
test/interpret003/expectednew file+1
@@ -0,0 +1 @@
1+Compiled program terminated with exit code 1
test/interpret003/inputnew file+1
@@ -0,0 +1 @@
1+:exec
test/interpret003/interpret003.idrnew file+4
@@ -0,0 +1,4 @@
1+import System
2+
3+main : IO ()
4+main = exitFailure
test/interpret003/runnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+${IDRIS:-idris} $@ --quiet --port none --nocolour interpret003.idr < input
3+rm -f *.ibc
test/interpret003/testnew file

Binary file not shown.