[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / interpreter / test / std / system1.hs
1 --!!! Testing System
2 module T where
3
4 import System(getArgs,getProgName,getEnv,system)
5
6 -- like print but no annoying "\n"
7 pr :: Show a => a -> IO ()
8 pr = putStr . show
9
10 test1 = system "exit 0" >>= pr
11 test2 = system "exit 1" >>= pr
12 test3 = system "exit 2" >>= pr
13
14 test4 = getArgs        >>= pr
15 test5 = getProgName    >>= pr
16
17 -- We want to test getEnv - but there's too much variety in possible 
18 -- environments so we pick an env var that doesn't vary too much
19 -- and list every variation we've ever come across.
20 test6 = do
21   shell <- getEnv "SHELL"
22   let sh = last $ chop '/' shell
23   if (sh `elem` shells) 
24     then
25       putStr "getEnv \"SHELL\" returns known shell"
26     else
27       putStr "getEnv \"SHELL\" returns unknown shell"
28   return ()
29  where
30   shells = ["sh" 
31            ,"csh"
32            ,"tcsh"
33            ,"bash"
34            ,"zsh"
35            ]
36
37 chop :: Eq a => a -> [a] -> [[a]]
38 chop seq [] = []
39 chop sep xs = ys : case zs of 
40                    []    -> []
41                    _:zs' -> chop sep zs'
42  where
43   (ys,zs) = break (sep ==) xs