Move lib/System tests to base/tests
authorIan Lynagh <igloo@earth.li>
Sat, 19 Nov 2011 23:43:03 +0000 (23:43 +0000)
committerIan Lynagh <igloo@earth.li>
Sat, 19 Nov 2011 23:43:03 +0000 (23:43 +0000)
tests/System/Makefile [new file with mode: 0644]
tests/System/all.T [new file with mode: 0644]
tests/System/exitWith001.hs [new file with mode: 0644]
tests/System/exitWith001.stdout [new file with mode: 0644]
tests/System/getArgs001.hs [new file with mode: 0644]
tests/System/getArgs001.stdout [new file with mode: 0644]
tests/System/getEnv001.hs [new file with mode: 0644]
tests/System/getEnv001.stdout [new file with mode: 0644]
tests/System/system001.hs [new file with mode: 0644]
tests/System/system001.stdout [new file with mode: 0644]

diff --git a/tests/System/Makefile b/tests/System/Makefile
new file mode 100644 (file)
index 0000000..4ca7751
--- /dev/null
@@ -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/System/all.T b/tests/System/all.T
new file mode 100644 (file)
index 0000000..996946f
--- /dev/null
@@ -0,0 +1,8 @@
+
+test('exitWith001', exit_code(42), compile_and_run, [''])
+test('getArgs001',  normal, compile_and_run, [''])
+test('getEnv001',   normal, compile_and_run, [''])
+
+test('system001',   if_platform("i386-unknown-mingw32", expect_fail), \
+       compile_and_run, [''])
+
diff --git a/tests/System/exitWith001.hs b/tests/System/exitWith001.hs
new file mode 100644 (file)
index 0000000..38dc38a
--- /dev/null
@@ -0,0 +1,3 @@
+import System.Exit (exitWith, ExitCode(..))
+
+main = exitWith (ExitFailure 42)
diff --git a/tests/System/exitWith001.stdout b/tests/System/exitWith001.stdout
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/System/getArgs001.hs b/tests/System/getArgs001.hs
new file mode 100644 (file)
index 0000000..4b8df91
--- /dev/null
@@ -0,0 +1,9 @@
+import System.Environment (getProgName, getArgs)
+
+main = 
+    getProgName >>= \ argv0 ->
+    putStr argv0 >>
+    getArgs >>= \ argv ->
+    sequence (map (\ x -> putChar ' ' >> putStr x) argv) >>
+    putChar '\n'
+
diff --git a/tests/System/getArgs001.stdout b/tests/System/getArgs001.stdout
new file mode 100644 (file)
index 0000000..e732087
--- /dev/null
@@ -0,0 +1 @@
+getArgs001
diff --git a/tests/System/getEnv001.hs b/tests/System/getEnv001.hs
new file mode 100644 (file)
index 0000000..745f8ea
--- /dev/null
@@ -0,0 +1,15 @@
+
+import System.Environment (getEnv)
+import System.IO.Error (catchIOError, isDoesNotExistError)
+
+main :: IO ()
+main = do
+    term <- getEnv "PATH"
+    putStrLn "Got $PATH"
+    fish <- getEnv "One fish, two fish, red fish, blue fish" `catchIOError` getEnv_except
+    putStrLn fish
+
+getEnv_except :: IOError -> IO String
+getEnv_except ioe
+ | isDoesNotExistError ioe = return ""
+ | otherwise              = ioError ioe
diff --git a/tests/System/getEnv001.stdout b/tests/System/getEnv001.stdout
new file mode 100644 (file)
index 0000000..b191cc3
--- /dev/null
@@ -0,0 +1,2 @@
+Got $PATH
+
diff --git a/tests/System/system001.hs b/tests/System/system001.hs
new file mode 100644 (file)
index 0000000..4237d52
--- /dev/null
@@ -0,0 +1,14 @@
+-- Not run on mingw, because of /dev/null use
+
+import System.Cmd (system)
+import System.Exit (ExitCode(..), exitWith)
+
+main = 
+    system "cat dog 1>/dev/null 2>&1" >>= \ ec ->
+    case ec of
+        ExitSuccess   -> putStr "What?!?\n" >> ioError (userError "dog succeeded")
+        ExitFailure _ ->
+            system "cat system001.hs 2>/dev/null" >>= \ ec ->
+           case ec of
+               ExitSuccess   -> exitWith ExitSuccess
+               ExitFailure _ -> putStr "What?!?\n" >> ioError (userError "cat failed")
diff --git a/tests/System/system001.stdout b/tests/System/system001.stdout
new file mode 100644 (file)
index 0000000..4237d52
--- /dev/null
@@ -0,0 +1,14 @@
+-- Not run on mingw, because of /dev/null use
+
+import System.Cmd (system)
+import System.Exit (ExitCode(..), exitWith)
+
+main = 
+    system "cat dog 1>/dev/null 2>&1" >>= \ ec ->
+    case ec of
+        ExitSuccess   -> putStr "What?!?\n" >> ioError (userError "dog succeeded")
+        ExitFailure _ ->
+            system "cat system001.hs 2>/dev/null" >>= \ ec ->
+           case ec of
+               ExitSuccess   -> exitWith ExitSuccess
+               ExitFailure _ -> putStr "What?!?\n" >> ioError (userError "cat failed")