[commit: testsuite] master: Enable and fix the posix* tests (ff84085)
Ian Lynagh
igloo at earth.li
Sun Nov 20 16:08:14 CET 2011
Repository : ssh://darcs.haskell.org//srv/darcs/testsuite
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/ff8408526f92b4ee4f513a1b3ce37433e2eb78d4
>---------------------------------------------------------------
commit ff8408526f92b4ee4f513a1b3ce37433e2eb78d4
Author: Ian Lynagh <igloo at earth.li>
Date: Sun Nov 20 01:23:48 2011 +0000
Enable and fix the posix* tests
>---------------------------------------------------------------
tests/lib/libposix/all.T | 3 +
tests/lib/libposix/posix002.hs | 2 +-
tests/lib/libposix/posix003.hs | 21 +++++++--
tests/lib/libposix/posix003.stdout | 1 +
tests/lib/libposix/posix004.hs | 80 +++++++++++++++---------------------
5 files changed, 54 insertions(+), 53 deletions(-)
diff --git a/tests/lib/libposix/all.T b/tests/lib/libposix/all.T
new file mode 100644
index 0000000..49d25d8
--- /dev/null
+++ b/tests/lib/libposix/all.T
@@ -0,0 +1,3 @@
+test('posix002', reqlib('unix'), compile_and_run, [''])
+test('posix003', normal, compile_and_run, [''])
+test('posix004', reqlib('unix'), compile_and_run, [''])
diff --git a/tests/lib/libposix/posix002.hs b/tests/lib/libposix/posix002.hs
index 8d01e8b..c5909ab 100644
--- a/tests/lib/libposix/posix002.hs
+++ b/tests/lib/libposix/posix002.hs
@@ -1,4 +1,4 @@
-import Posix
+import System.Posix.Process
main =
executeFile "printenv" True [] (Just [("ONE","1"),("TWO","2")])
diff --git a/tests/lib/libposix/posix003.hs b/tests/lib/libposix/posix003.hs
index dbea5e1..1298450 100644
--- a/tests/lib/libposix/posix003.hs
+++ b/tests/lib/libposix/posix003.hs
@@ -1,6 +1,17 @@
-import IO
-import Posix
-main =
- openFile "po003.out" WriteMode >>= \ h ->
- runProcess "pwd" [] Nothing (Just "/usr/tmp") Nothing (Just h) Nothing
+import Control.Monad
+import Data.Char
+import System.Exit
+import System.IO
+import System.Process
+
+main = do hw <- openFile "po003.out" WriteMode
+ ph <- runProcess "pwd" [] (Just "/tmp") Nothing Nothing (Just hw) Nothing
+ ec <- waitForProcess ph
+ hClose hw
+ unless (ec == ExitSuccess) $ error "pwd failed"
+ hr <- openFile "po003.out" ReadMode
+ output <- hGetContents hr
+ putStrLn ("Got: " ++ show (filter (not . isSpace) output))
+ hClose hr
+
diff --git a/tests/lib/libposix/posix003.stdout b/tests/lib/libposix/posix003.stdout
index e69de29..0bef00a 100644
--- a/tests/lib/libposix/posix003.stdout
+++ b/tests/lib/libposix/posix003.stdout
@@ -0,0 +1 @@
+Got: "/tmp"
diff --git a/tests/lib/libposix/posix004.hs b/tests/lib/libposix/posix004.hs
index 2423f3f..20e2af2 100644
--- a/tests/lib/libposix/posix004.hs
+++ b/tests/lib/libposix/posix004.hs
@@ -1,58 +1,44 @@
-import Posix
-import System(ExitCode(..), exitWith)
-main =
- forkProcess >>= \ maybe_pid ->
- case maybe_pid of
- Nothing -> raiseSignal floatingPointException
- _ -> doParent
+import System.Exit (ExitCode(..), exitWith)
+import System.Posix.Process
+import System.Posix.Signals
-doParent =
- getAnyProcessStatus True False >>= \ (Just (pid, tc)) ->
- case tc of
- Terminated sig | sig == floatingPointException -> forkChild2
- _ -> fail (userError "unexpected termination cause")
-
-forkChild2 =
- forkProcess >>= \ maybe_pid ->
- case maybe_pid of
- Nothing -> exitImmediately (ExitFailure 42)
- _ -> doParent2
+main = do test1
+ test2
+ test3
+ test4
+ putStrLn "I'm happy."
-doParent2 =
- getAnyProcessStatus True False >>= \ (Just (pid, tc)) ->
+test1 = do
+ forkProcess $ raiseSignal floatingPointException
+ Just (pid, tc) <- getAnyProcessStatus True False
case tc of
- Exited (ExitFailure 42) -> forkChild3
- _ -> fail (userError "unexpected termination cause (2)")
+ Terminated sig | sig == floatingPointException -> return ()
+ _ -> error "unexpected termination cause"
-forkChild3 =
- forkProcess >>= \ maybe_pid ->
- case maybe_pid of
- Nothing -> exitImmediately (ExitSuccess)
- _ -> doParent3
-
-doParent3 =
- getAnyProcessStatus True False >>= \ (Just (pid, tc)) ->
+test2 = do
+ forkProcess $ exitImmediately (ExitFailure 42)
+ Just (pid, tc) <- getAnyProcessStatus True False
case tc of
- Exited ExitSuccess -> forkChild4
- _ -> fail (userError "unexpected termination cause (3)")
-
-forkChild4 =
- forkProcess >>= \ maybe_pid ->
- case maybe_pid of
- Nothing -> raiseSignal softwareStop
- _ -> doParent4
+ Exited (ExitFailure 42) -> return ()
+ _ -> error "unexpected termination cause (2)"
-doParent4 =
- getAnyProcessStatus True True >>= \ (Just (pid, tc)) ->
+test3 = do
+ forkProcess $ exitImmediately ExitSuccess
+ Just (pid, tc) <- getAnyProcessStatus True False
case tc of
- Stopped sig | sig == softwareStop -> enoughAlready pid
- _ -> fail (userError "unexpected termination cause (4)")
+ Exited ExitSuccess -> return ()
+ _ -> error "unexpected termination cause (3)"
-enoughAlready pid =
- signalProcess killProcess pid >>
- getAnyProcessStatus True True >>= \ (Just (pid, tc)) ->
+test4 = do
+ forkProcess $ raiseSignal softwareStop
+ Just (pid, tc) <- getAnyProcessStatus True True
case tc of
- Terminated sig | sig == killProcess -> putStr "I'm happy.\n"
- _ -> fail (userError "unexpected termination cause (5)")
+ Stopped sig | sig == softwareStop -> do
+ signalProcess killProcess pid
+ Just (pid, tc) <- getAnyProcessStatus True True
+ case tc of
+ Terminated sig | sig == killProcess -> return ()
+ _ -> error "unexpected termination cause (5)"
+ _ -> error "unexpected termination cause (4)"
More information about the Cvs-ghc
mailing list