aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Paolo Capriotti <p.capriotti@gmail.com>2012-03-09 11:44:41 +0000
committerGravatar Paolo Capriotti <p.capriotti@gmail.com>2012-03-09 11:44:41 +0000
commit891c0bf89b89e3995d2dbc1f6f72b43312b14a44 (patch)
tree2f49d3817b718b226ca37489302bae735bf9ade0 /tests
parent0e8de7869a0f3b32d2ac8cbe2aad74eb7dcf054a (diff)
Copy tests from GHC testsuite (#1161)
Diffstat (limited to 'tests')
-rw-r--r--tests/libposix/Makefile7
-rw-r--r--tests/libposix/all.T15
-rw-r--r--tests/libposix/posix002.hs4
-rw-r--r--tests/libposix/posix002.stdout2
-rw-r--r--tests/libposix/posix003.hs17
-rw-r--r--tests/libposix/posix003.stdout1
-rw-r--r--tests/libposix/posix004.hs44
-rw-r--r--tests/libposix/posix004.stdout1
-rw-r--r--tests/libposix/posix005.hs21
-rw-r--r--tests/libposix/posix005.stdout7
-rw-r--r--tests/libposix/posix006.hs18
-rw-r--r--tests/libposix/posix006.stdout1
-rw-r--r--tests/libposix/posix009.hs15
-rw-r--r--tests/libposix/posix009.stdout6
-rw-r--r--tests/libposix/posix010.hs16
-rw-r--r--tests/libposix/posix010.stdout3
-rw-r--r--tests/libposix/posix014.hs13
-rw-r--r--tests/libposix/posix014.stdout1
18 files changed, 192 insertions, 0 deletions
diff --git a/tests/libposix/Makefile b/tests/libposix/Makefile
new file mode 100644
index 0000000..4ca7751
--- /dev/null
+++ b/tests/libposix/Makefile
@@ -0,0 +1,7 @@
+# This Makefile runs the tests using GHC's testsuite framework. It
+# assumes the package is part of a GHC build tree with the testsuite
+# installed in ../../../testsuite.
+
+TOP=../../../../testsuite
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/tests/libposix/all.T b/tests/libposix/all.T
new file mode 100644
index 0000000..a266040
--- /dev/null
+++ b/tests/libposix/all.T
@@ -0,0 +1,15 @@
+test('posix002', [ reqlib('unix'), omit_ways(prof_ways) ],
+ compile_and_run, [''])
+
+# Skip on mingw32: assumes existence of 'pwd' and /tmp
+test('posix003', if_os('mingw32', skip), compile_and_run, [''])
+
+test('posix004', [ reqlib('unix') ], compile_and_run, [''])
+
+test('posix005', [reqlib('unix'), expect_broken(5648)], compile_and_run, [''])
+
+test('posix006', reqlib('unix'), compile_and_run, [''])
+test('posix009', [ omit_ways(threaded_ways), reqlib('unix') ], compile_and_run, [''])
+test('posix010', reqlib('unix'), compile_and_run, [''])
+
+test('posix014', [ reqlib('unix') ], compile_and_run, [''])
diff --git a/tests/libposix/posix002.hs b/tests/libposix/posix002.hs
new file mode 100644
index 0000000..c5909ab
--- /dev/null
+++ b/tests/libposix/posix002.hs
@@ -0,0 +1,4 @@
+import System.Posix.Process
+
+main =
+ executeFile "printenv" True [] (Just [("ONE","1"),("TWO","2")])
diff --git a/tests/libposix/posix002.stdout b/tests/libposix/posix002.stdout
new file mode 100644
index 0000000..5e17a60
--- /dev/null
+++ b/tests/libposix/posix002.stdout
@@ -0,0 +1,2 @@
+ONE=1
+TWO=2
diff --git a/tests/libposix/posix003.hs b/tests/libposix/posix003.hs
new file mode 100644
index 0000000..b28f9f7
--- /dev/null
+++ b/tests/libposix/posix003.hs
@@ -0,0 +1,17 @@
+
+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 "/dev") 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/libposix/posix003.stdout b/tests/libposix/posix003.stdout
new file mode 100644
index 0000000..5206ef3
--- /dev/null
+++ b/tests/libposix/posix003.stdout
@@ -0,0 +1 @@
+Got: "/dev"
diff --git a/tests/libposix/posix004.hs b/tests/libposix/posix004.hs
new file mode 100644
index 0000000..20e2af2
--- /dev/null
+++ b/tests/libposix/posix004.hs
@@ -0,0 +1,44 @@
+
+import System.Exit (ExitCode(..), exitWith)
+import System.Posix.Process
+import System.Posix.Signals
+
+main = do test1
+ test2
+ test3
+ test4
+ putStrLn "I'm happy."
+
+test1 = do
+ forkProcess $ raiseSignal floatingPointException
+ Just (pid, tc) <- getAnyProcessStatus True False
+ case tc of
+ Terminated sig | sig == floatingPointException -> return ()
+ _ -> error "unexpected termination cause"
+
+test2 = do
+ forkProcess $ exitImmediately (ExitFailure 42)
+ Just (pid, tc) <- getAnyProcessStatus True False
+ case tc of
+ Exited (ExitFailure 42) -> return ()
+ _ -> error "unexpected termination cause (2)"
+
+test3 = do
+ forkProcess $ exitImmediately ExitSuccess
+ Just (pid, tc) <- getAnyProcessStatus True False
+ case tc of
+ Exited ExitSuccess -> return ()
+ _ -> error "unexpected termination cause (3)"
+
+test4 = do
+ forkProcess $ raiseSignal softwareStop
+ Just (pid, tc) <- getAnyProcessStatus True True
+ case tc of
+ 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)"
+
diff --git a/tests/libposix/posix004.stdout b/tests/libposix/posix004.stdout
new file mode 100644
index 0000000..8ed7ee5
--- /dev/null
+++ b/tests/libposix/posix004.stdout
@@ -0,0 +1 @@
+I'm happy.
diff --git a/tests/libposix/posix005.hs b/tests/libposix/posix005.hs
new file mode 100644
index 0000000..9ca569c
--- /dev/null
+++ b/tests/libposix/posix005.hs
@@ -0,0 +1,21 @@
+
+import System.IO
+import System.Posix.Env
+
+main = do
+ hSetBuffering stdout NoBuffering
+ term <- getEnvVar "TERM"
+ putStrLn term
+ setEnvironment [("one","1"),("two","2")]
+ getEnvironment >>= print
+ setEnv "foo" "bar" True
+ getEnvironment >>= print
+ setEnv "foo" "baz" True
+ getEnvironment >>= print
+ setEnv "fu" "bar" True
+ getEnvironment >>= print
+ unsetEnv "foo"
+ getEnvironment >>= print
+ setEnvironment []
+ getEnvironment >>= print
+
diff --git a/tests/libposix/posix005.stdout b/tests/libposix/posix005.stdout
new file mode 100644
index 0000000..9896f43
--- /dev/null
+++ b/tests/libposix/posix005.stdout
@@ -0,0 +1,7 @@
+emacs
+[("one","1"),("two","2")]
+[("one","1"),("two","2"),("foo","bar")]
+[("one","1"),("two","2"),("foo","baz")]
+[("one","1"),("two","2"),("foo","baz"),("fu","bar")]
+[("one","1"),("two","2"),("fu","bar")]
+[]
diff --git a/tests/libposix/posix006.hs b/tests/libposix/posix006.hs
new file mode 100644
index 0000000..697e4e6
--- /dev/null
+++ b/tests/libposix/posix006.hs
@@ -0,0 +1,18 @@
+
+import System.Posix.Time
+import System.Posix.Unistd
+import System.Posix.Signals
+
+main = do start <- epochTime
+ blockSignals reservedSignals -- see #4504
+ sleep 1
+ finish <- epochTime
+ let slept = finish - start
+ if slept >= 1 && slept <= 2
+ then putStrLn "OK"
+ else do putStr "Started: "
+ print start
+ putStr "Finished: "
+ print finish
+ putStr "Slept: "
+ print slept
diff --git a/tests/libposix/posix006.stdout b/tests/libposix/posix006.stdout
new file mode 100644
index 0000000..d86bac9
--- /dev/null
+++ b/tests/libposix/posix006.stdout
@@ -0,0 +1 @@
+OK
diff --git a/tests/libposix/posix009.hs b/tests/libposix/posix009.hs
new file mode 100644
index 0000000..067d3a9
--- /dev/null
+++ b/tests/libposix/posix009.hs
@@ -0,0 +1,15 @@
+import System.Posix.Signals
+import System.Posix.Unistd
+
+main = do
+ putStrLn "Blocking real time alarms."
+ blockSignals (addSignal realTimeAlarm reservedSignals)
+ putStrLn "Scheduling an alarm in 2 seconds..."
+ scheduleAlarm 2
+ putStrLn "Sleeping 5 seconds."
+ sleep 5
+ putStrLn "Woken up"
+ ints <- getPendingSignals
+ putStrLn "Checking pending interrupts for RealTimeAlarm"
+ print (inSignalSet realTimeAlarm ints)
+
diff --git a/tests/libposix/posix009.stdout b/tests/libposix/posix009.stdout
new file mode 100644
index 0000000..d294675
--- /dev/null
+++ b/tests/libposix/posix009.stdout
@@ -0,0 +1,6 @@
+Blocking real time alarms.
+Scheduling an alarm in 2 seconds...
+Sleeping 5 seconds.
+Woken up
+Checking pending interrupts for RealTimeAlarm
+True
diff --git a/tests/libposix/posix010.hs b/tests/libposix/posix010.hs
new file mode 100644
index 0000000..420d210
--- /dev/null
+++ b/tests/libposix/posix010.hs
@@ -0,0 +1,16 @@
+import System.Posix
+
+main = do
+ root <- getUserEntryForName "root"
+ putStrLn (ue2String root)
+ root' <- getUserEntryForID (userID root)
+ putStrLn (ue2String root')
+ if homeDirectory root == homeDirectory root' &&
+ userShell root == userShell root'
+ then putStrLn "OK"
+ else putStrLn "Mismatch"
+
+ue2String ue = concat [name, ":", show uid, ":", show gid]
+ where name = userName ue
+ uid = userID ue
+ gid = userGroupID ue
diff --git a/tests/libposix/posix010.stdout b/tests/libposix/posix010.stdout
new file mode 100644
index 0000000..77a5024
--- /dev/null
+++ b/tests/libposix/posix010.stdout
@@ -0,0 +1,3 @@
+root:0:0
+root:0:0
+OK
diff --git a/tests/libposix/posix014.hs b/tests/libposix/posix014.hs
new file mode 100644
index 0000000..9d844b2
--- /dev/null
+++ b/tests/libposix/posix014.hs
@@ -0,0 +1,13 @@
+-- !! Basic pipe usage
+module Main (main) where
+
+import System.Posix
+
+main = do
+ (rd, wd) <- createPipe
+ pid <- forkProcess $ do (str, _) <- fdRead rd 32
+ putStrLn str
+ fdWrite wd "Hi, there - forked child calling"
+ getProcessStatus True False pid
+ return ()
+
diff --git a/tests/libposix/posix014.stdout b/tests/libposix/posix014.stdout
new file mode 100644
index 0000000..cab0a57
--- /dev/null
+++ b/tests/libposix/posix014.stdout
@@ -0,0 +1 @@
+Hi, there - forked child calling