Do not print the result of 'main' after invoking ':main' (fixes #9086).
authorGintautas Miliauskas <gintautas.miliauskas@gmail.com>
Sun, 8 Jun 2014 11:49:29 +0000 (11:49 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Mon, 7 Jul 2014 07:21:13 +0000 (09:21 +0200)
ghc/InteractiveUI.hs
testsuite/tests/ghc-e/should_run/Makefile
testsuite/tests/ghc-e/should_run/T9086.hs [new file with mode: 0644]
testsuite/tests/ghc-e/should_run/all.T
testsuite/tests/ghci/scripts/T9086b.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/T9086b.stdout [new file with mode: 0644]
testsuite/tests/ghci/scripts/all.T

index 0a56799..c3d9f25 100644 (file)
@@ -1141,9 +1141,10 @@ runMain s = case toArgs s of
             Left err   -> liftIO (hPutStrLn stderr err)
             Right args ->
                 do dflags <- getDynFlags
-                   case mainFunIs dflags of
-                       Nothing -> doWithArgs args "main"
-                       Just f  -> doWithArgs args f
+                   let main = fromMaybe "main" (mainFunIs dflags)
+                   -- Wrap the main function in 'void' to discard its value instead
+                   -- of printing it (#9086). See Haskell 2010 report Chapter 5.
+                   doWithArgs args $ "Control.Monad.void (" ++ main ++ ")"
 
 -----------------------------------------------------------------------------
 -- :run
index 1971004..5ed1ec2 100644 (file)
@@ -30,3 +30,5 @@ T3890:
 T7299:
        '$(TEST_HC)' $(TEST_HC_OPTS) -ignore-dot-ghci -e "Control.Concurrent.threadDelay (1000 * 1000)"
 
+T9086:
+       '$(TEST_HC)' $(TEST_HC_OPTS) -ignore-dot-ghci -e ":main" T9086.hs
diff --git a/testsuite/tests/ghc-e/should_run/T9086.hs b/testsuite/tests/ghc-e/should_run/T9086.hs
new file mode 100644 (file)
index 0000000..a2b4ace
--- /dev/null
@@ -0,0 +1 @@
+main = return "this should not be printed"
index 4ab7567..9f64918 100644 (file)
@@ -14,3 +14,4 @@ test('T2228',
 test('T2636', req_interp, run_command, ['$MAKE --no-print-directory -s T2636'])
 test('T3890', req_interp, run_command, ['$MAKE --no-print-directory -s T3890'])
 test('T7299', req_interp, run_command, ['$MAKE --no-print-directory -s T7299'])
+test('T9086', req_interp, run_command, ['$MAKE --no-print-directory -s T9086'])
diff --git a/testsuite/tests/ghci/scripts/T9086b.script b/testsuite/tests/ghci/scripts/T9086b.script
new file mode 100644 (file)
index 0000000..d60156a
--- /dev/null
@@ -0,0 +1,2 @@
+let main = do { putStrLn "hello"; return "discarded" }
+:main
diff --git a/testsuite/tests/ghci/scripts/T9086b.stdout b/testsuite/tests/ghci/scripts/T9086b.stdout
new file mode 100644 (file)
index 0000000..ce01362
--- /dev/null
@@ -0,0 +1 @@
+hello
index b71dfd1..d1e67eb 100755 (executable)
@@ -175,3 +175,4 @@ test('T8931', normal, ghci_script, ['T8931.script'])
 test('T8959', normal, ghci_script, ['T8959.script'])
 test('T8959b', expect_broken(8959), ghci_script, ['T8959b.script'])
 test('T9181', normal, ghci_script, ['T9181.script'])
+test('T9086b', normal, ghci_script, ['T9086b.script'])