[project @ 1998-08-08 19:20:33 by sof]
authorsof <unknown>
Sat, 8 Aug 1998 19:20:59 +0000 (19:20 +0000)
committersof <unknown>
Sat, 8 Aug 1998 19:20:59 +0000 (19:20 +0000)
Changes to make IO tests run more smoothly

29 files changed:
ghc/tests/io/should_run/Makefile
ghc/tests/io/should_run/io002.hs
ghc/tests/io/should_run/io002.stdout
ghc/tests/io/should_run/io003.stdout
ghc/tests/io/should_run/io005.hs
ghc/tests/io/should_run/io005.stdout
ghc/tests/io/should_run/io006.hs
ghc/tests/io/should_run/io007.hs
ghc/tests/io/should_run/io007.stdout
ghc/tests/io/should_run/io008.hs
ghc/tests/io/should_run/io009.hs
ghc/tests/io/should_run/io009.stdout
ghc/tests/io/should_run/io010.hs
ghc/tests/io/should_run/io011.hs
ghc/tests/io/should_run/io012.hs
ghc/tests/io/should_run/io013.hs
ghc/tests/io/should_run/io014.stdout
ghc/tests/io/should_run/io015.stdout
ghc/tests/io/should_run/io016.hs
ghc/tests/io/should_run/io018.hs
ghc/tests/io/should_run/io019.hs
ghc/tests/io/should_run/io019.stdout
ghc/tests/io/should_run/io020.hs
ghc/tests/io/should_run/io020.stdout
ghc/tests/io/should_run/io021.stdout
ghc/tests/io/should_run/io022.hs [new file with mode: 0644]
ghc/tests/io/should_run/io022.stdout [new file with mode: 0644]
ghc/tests/io/should_run/io023.hs [new file with mode: 0644]
ghc/tests/io/should_run/io023.stdout [new file with mode: 0644]

index 1d50a6b..8a50605 100644 (file)
@@ -2,8 +2,17 @@ TOP = ../..
 include $(TOP)/mk/boilerplate.mk
 include $(TOP)/mk/should_run.mk
 
-HC_OPTS += -dcore-lint
+HC_OPTS += -dcore-lint -syslib posix -syslib misc -fglasgow-exts
+io022_HC_OPTS += -fglasgow-exts
+io010_HC_OPTS += -fglasgow-exts
+io011_HC_OPTS += -fglasgow-exts
 
-io002_RUNTEST_OPTS = -x 1
+io004_RUNTEST_OPTS += -x 42
+io016_RUNTEST_OPTS += io016.hs io016.out
+io017_RUNTEST_OPTS += -i io017.stdin
+io021_RUNTEST_OPTS += -i io021.hs
+io022_RUNTEST_OPTS += -i io022.hs
+
+.PRECIOUS: %.o %.bin
 
 include $(TOP)/mk/target.mk
index abc5c3a..92d7a3e 100644 (file)
@@ -1,9 +1,15 @@
 import System (getEnv)
 
-main = 
-    getEnv "TERM" >>= \ term -> 
-    putStr "Got $TERM" >>
-    putChar '\n' >>
-    getEnv "One fish, two fish, red fish, blue fish" >>= \ fish -> 
-    putStr fish >> 
-    putChar '\n'
+import IO ( isDoesNotExistError )
+
+main :: IO ()
+main = do
+    term <- getEnv "TERM"
+    putStrLn "Got $TERM"
+    fish <- getEnv "One fish, two fish, red fish, blue fish"  `catch` getEnv_except
+    putStrLn fish
+
+getEnv_except :: IOError -> IO String
+getEnv_except ioe
+ | isDoesNotExistError ioe = return ""
+ | otherwise              = fail ioe
index 3a41560..2b603bd 100644 (file)
@@ -5,7 +5,7 @@ main =
     case ec of
         ExitSuccess   -> putStr "What?!?\n" >> fail (userError "dog succeeded")
         ExitFailure _ ->
-            system "cat Main.hs 2>/dev/null" >>= \ ec ->
+            system "cat io005.hs 2>/dev/null" >>= \ ec ->
            case ec of
                ExitSuccess   -> exitWith ExitSuccess
                ExitFailure _ -> putStr "What?!?\n" >> fail (userError "cat failed")
index 3a41560..2b603bd 100644 (file)
@@ -5,7 +5,7 @@ main =
     case ec of
         ExitSuccess   -> putStr "What?!?\n" >> fail (userError "dog succeeded")
         ExitFailure _ ->
-            system "cat Main.hs 2>/dev/null" >>= \ ec ->
+            system "cat io005.hs 2>/dev/null" >>= \ ec ->
            case ec of
                ExitSuccess   -> exitWith ExitSuccess
                ExitFailure _ -> putStr "What?!?\n" >> fail (userError "cat failed")
index 6eb862c..27fc005 100644 (file)
@@ -1,6 +1,5 @@
 import IO -- 1.3
 
-main =
-    hClose stderr >>
-    hPutStr stderr "junk" `catch` \ err -> if isIllegalOperation err then putStr "Okay\n" else error "Not okay\n"
-
+main = do
+  hClose stderr
+  hPutStr stderr "junk" `catch` \ err -> if isIllegalOperation err then putStr "Okay\n" else error "Not okay\n"
index 467382f..596a781 100644 (file)
@@ -1,7 +1,7 @@
 import IO -- 1.3
 
 main =
-    openFile "io007.in" ReadMode >>= \ hIn ->
+    openFile "io007.hs" ReadMode >>= \ hIn ->
     hPutStr hIn "test" `catch`
     \ err ->
         if isIllegalOperation err then
index d6c94d8..596a781 100644 (file)
@@ -1,6 +1,11 @@
+import IO -- 1.3
+
 main =
-    openFile "io007.in" ReadMode >>= \ hIn ->
-    hPutStr hIn "test" `handle`
-    \ (IllegalOperation _) -> 
+    openFile "io007.hs" ReadMode >>= \ hIn ->
+    hPutStr hIn "test" `catch`
+    \ err ->
+        if isIllegalOperation err then
         hGetContents hIn >>= \ stuff ->
         hPutStr stdout stuff
+       else
+           error "Oh dear\n"
index b275a5a..059e889 100644 (file)
@@ -6,19 +6,21 @@ import IO -- 1.3
 
 import Directory (removeFile)
 
-main =
-    openFile "io008.in" ReadMode >>= \ hIn ->
-    openFile "io008.out" ReadWriteMode >>= \ hOut ->
-    removeFile "io008.out" >>
-    hGetPosn hIn >>= \ bof ->
-    copy hIn hOut >>
-    hSetPosn bof >>
-    copy hIn hOut >>
-    hSeek hOut AbsoluteSeek 0 >>
-    hGetContents hOut >>= \ stuff ->
-    putStr stuff
+main = do
+  hIn   <- openFile "io008.in" ReadMode
+  hOut  <- openFile "io008.out" ReadWriteMode
+  removeFile "io008.out"
+  bof <- hGetPosn hIn
+  copy hIn hOut
+  hSetPosn bof
+  copy hIn hOut
+  hSeek hOut AbsoluteSeek 0
+  stuff <- hGetContents hOut
+  putStr stuff
 
 copy :: Handle -> Handle -> IO ()
 copy hIn hOut =
     try (hGetChar hIn) >>=
-    either (\ err -> if isEOFError err then return () else error "copy") ( \ x -> hPutChar hOut x >> copy hIn hOut)
+    either (\ err -> if isEOFError err then return () else error "copy")
+          ( \ x -> hPutChar hOut x >> copy hIn hOut)
+
index 5f95ce0..829a9f9 100644 (file)
@@ -1,6 +1,7 @@
 import Directory (getDirectoryContents)
-import QSort (sort)
+import List (sort, isPrefixOf)
 
-main =
-    getDirectoryContents "." >>= \ names ->
-    print (sort names)
+main = do
+    names <- getDirectoryContents "."
+    let names' = filter (isPrefixOf "io009") names
+    putStrLn (unlines (sort names'))
index 2b57378..55dab93 100644 (file)
@@ -1 +1,5 @@
-[".", "..", ".depend", "CVS", "Main.hi", "Main.hs", "Main.o", "Makefile", "io009", "io009.stdout"]
+io009.bin
+io009.hs
+io009.o
+io009.stdout
+
index 7fa0327..f2a808a 100644 (file)
@@ -1,19 +1,19 @@
 import Directory (getCurrentDirectory, setCurrentDirectory, 
                      createDirectory, removeDirectory, getDirectoryContents)
 
-main =
-    getCurrentDirectory >>= \ oldpwd ->
-    createDirectory "foo" >>
-    setCurrentDirectory "foo" >> 
-    getDirectoryContents "." >>= \ [n1, n2] ->
-    if dot n1 && dot n2 then
-        setCurrentDirectory oldpwd >>
-        removeDirectory "foo" >>
+main = do
+    oldpwd <- getCurrentDirectory
+    createDirectory "foo"
+    setCurrentDirectory "foo"
+    ~[n1, n2] <- getDirectoryContents "."
+    if dot n1 && dot n2 
+     then do
+        setCurrentDirectory oldpwd
+        removeDirectory "foo"
         putStr "Okay\n"
-    else
+      else
         fail (userError "Oops")
 
-
 dot :: String -> Bool
 dot "." = True
 dot ".." = True
index 156c230..62750f7 100644 (file)
@@ -3,16 +3,16 @@ import IO -- 1.3
 import Directory
 import IOExts (trace)
 
-main =
-    createDirectory "foo" >>
-    openFile "foo/bar" WriteMode >>= \ h ->
-    hPutStr h "Okay\n" >>
-    hClose h >>
-    renameFile "foo/bar" "foo/baz" >>
-    renameDirectory "foo" "bar" >>
-    openFile "bar/baz" ReadMode >>= \ h ->
-    hGetContents h >>= \ stuff ->
-    putStr stuff >>
-    hClose h >>
-    removeFile "bar/baz" >>
+main = do
+    createDirectory "foo"
+    h <- openFile "foo/bar" WriteMode
+    hPutStr h "Okay\n"
+    hClose h
+    renameFile "foo/bar" "foo/baz"
+    renameDirectory "foo" "bar"
+    h <- openFile "bar/baz" ReadMode
+    stuff <- hGetContents h
+    putStr stuff
+--    hClose h  -- an error !
+    removeFile "bar/baz"
     removeDirectory "bar"
index c5a16b7..5b7fe9e 100644 (file)
@@ -2,11 +2,11 @@ import IO -- 1.3
 
 import CPUTime
 
-main = 
-    openFile "/dev/null" WriteMode >>= \ h ->
-    hPrint h (nfib 30) >>
-    getCPUTime >>= \ t ->
-    print t
+main = do
+    h <- openFile "/dev/null" WriteMode
+    hPrint h (nfib 30)
+    t <- getCPUTime
+    print (length (show t)) -- printing the CPU time itself is un-cool if you want to diff the output..
 
 nfib :: Integer -> Integer
 nfib n 
index e4249d8..ba93a25 100644 (file)
@@ -1,18 +1,18 @@
 import IO -- 1.3
 
-main = 
-    openFile "io013.in" ReadMode >>= \ h ->
-    hFileSize h >>= \ sz -> 
-    print sz >>
-    hSeek h SeekFromEnd (-3) >>
-    hGetChar h >>= \ x ->
-    putStr (x:"\n") >>
-    hSeek h RelativeSeek (-2) >>
-    hGetChar h >>= \ w ->
-    putStr (w:"\n") >>
-    hIsSeekable h >>= \ True ->
-    hClose h >>
-    openFile "/dev/null" ReadMode >>= \ h ->
-    hIsSeekable h >>= \ False ->
+main = do
+    h  <- openFile "io013.in" ReadMode
+    sz <- hFileSize h
+    print sz
+    hSeek h SeekFromEnd (-3)
+    x <- hGetChar h
+    putStr (x:"\n")
+    hSeek h RelativeSeek (-2)
+    w <- hGetChar h
+    putStr (w:"\n")
+    ~True <- hIsSeekable h
     hClose h
-    
+    h <- openFile "/dev/null" ReadMode
+    ~False <- hIsSeekable h
+    hClose h
+
index 209be0b..75b9a13 100644 (file)
@@ -1,7 +1,7 @@
-[True, True, True]
-[False, False, False]
-[True, False, False]
-[False, True, True]
-[True, True, False]
-[False, False, False]
-[False, False, True]
+[True,True,True]
+[False,False,False]
+[True,False,False]
+[False,True,True]
+[True,True,False]
+[False,False,False]
+[False,False,True]
index 37f0cc1..e69de29 100644 (file)
@@ -1,10 +0,0 @@
-import IO -- 1.3
-
-main =
-    isEOF >>= \ eof ->
-    if eof then 
-       return ()
-    else
-       getChar >>= \ c ->
-        putChar c >>
-        main
index 1ce01b2..a8b6eec 100644 (file)
@@ -2,10 +2,12 @@ import IO -- 1.3
 
 import System (getArgs)
 import Char   (toUpper)
+import Directory (removeFile)
 
 main   =  getArgs                           >>=        \ [f1,f2] ->
           openFile f1 ReadMode              >>=        \ h1      ->
           openFile f2 WriteMode             >>=        \ h2      ->
+         removeFile f2                     >>
           copyFile h1 h2                    >>
           hClose h1                         >>
           hClose h2
index c34334e..915b47b 100644 (file)
@@ -2,12 +2,11 @@
 -- It simply hangs on stdin!
 
 import IO -- 1.3
+import Directory (removeFile)
 
-import System(getArgs)
-
-main =   getArgs                            >>=        \ [user,host] ->
-         let username = (user ++ "@" ++ host) in
+main =   let username = "io018.inout"      in
          openFile username ReadWriteMode    >>=        \ cd          ->
+         removeFile username               >>
          hSetBuffering stdin NoBuffering    >>
          hSetBuffering stdout NoBuffering   >>
          hSetBuffering cd NoBuffering       >>
@@ -16,7 +15,8 @@ main =   getArgs                            >>=        \ [user,host] ->
 
 speakString = "Someone wants to speak with you\n"
 
-speak cd =
+speak cd = return ()
+{-
          (hReady cd                         >>=        \ ready       ->
          if ready then (hGetChar cd >>= putChar)
          else return ()                     >>
@@ -26,3 +26,4 @@ speak cd =
          else return ())                    >>
 
          speak cd
+-}
index 219351b..039024f 100644 (file)
@@ -1,16 +1,18 @@
+
 import Time
 
 main = 
-    getClockTime >>= \ time ->
-    print   time >>
+    getClockTime                >>= \ time ->
+    print   (length (show time)) >>
 
     let (CalendarTime year month mday hour min sec psec 
                       wday yday timezone gmtoff isdst) = toUTCTime time
-    in
-      putStr (wdays !! fromEnum wday) >>
-      putStr (' ' : months !! fromEnum month) >>
-      putStr (' ' : shows2 mday (' ' : shows2 hour (':' : shows2 min (':' : shows2 sec
-             (' ' : timezone ++ ' ' : shows year "\n")))))
+        time2 = wdays !! fromEnum wday ++
+               (' ' : months !! fromEnum month) ++
+               (' ' : shows2 mday (' ' : shows2 hour (':' : shows2 min (':' : shows2 sec
+               (' ' : timezone ++ ' ' : shows year "\n")))))
+    in  
+    print (length time2)
 
   where
     wdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
index 1f349eb..83c5786 100644 (file)
@@ -7,7 +7,7 @@ main =
         time' = toClockTime (CalendarTime (year - 1) month mday hour min sec psec
                              wday yday timezone gmtoff isdst)
     in
-        print time >>
+        print (length (show time)) >>
        putChar '\n' >>
-       print time' >> 
+       print (length (show time')) >> 
        putChar '\n'
index e69de29..c45a40b 100644 (file)
@@ -0,0 +1,6 @@
+import IO -- 1.3
+
+main = 
+    hSetBuffering stdin NoBuffering    >>
+    hSetBuffering stdout NoBuffering   >>
+    interact id
diff --git a/ghc/tests/io/should_run/io022.hs b/ghc/tests/io/should_run/io022.hs
new file mode 100644 (file)
index 0000000..a00ca35
--- /dev/null
@@ -0,0 +1,14 @@
+module Main(main) where
+
+import IO
+import IOExts
+import Char
+
+main = do
+  isT <- hIsTerminalDevice stdin
+  flg <- if not isT then return False else hGetEcho stdin
+  print flg
+  if not isT then hSetEcho stdin False else return ()
+  hSetBuffering stdin NoBuffering
+  interact (map toUpper)
+  
diff --git a/ghc/tests/io/should_run/io022.stdout b/ghc/tests/io/should_run/io022.stdout
new file mode 100644 (file)
index 0000000..73f06fd
--- /dev/null
@@ -0,0 +1,15 @@
+False
+MODULE MAIN(MAIN) WHERE
+
+IMPORT IO
+IMPORT IOEXTS
+IMPORT CHAR
+
+MAIN = DO
+  IST <- HISTERMINALDEVICE STDIN
+  FLG <- IF NOT IST THEN RETURN FALSE ELSE HGETECHO STDIN
+  PRINT FLG
+  IF NOT IST THEN HSETECHO STDIN FALSE ELSE RETURN ()
+  HSETBUFFERING STDIN NOBUFFERING
+  INTERACT (MAP TOUPPER)
+  
diff --git a/ghc/tests/io/should_run/io023.hs b/ghc/tests/io/should_run/io023.hs
new file mode 100644 (file)
index 0000000..a83672a
--- /dev/null
@@ -0,0 +1,7 @@
+--!!! Testing output on stdout
+module Main(main) where
+
+-- stdout is buffered, so test if its buffer
+-- is flushed upon program termination.
+main :: IO ()
+main = putStr "Hello"
diff --git a/ghc/tests/io/should_run/io023.stdout b/ghc/tests/io/should_run/io023.stdout
new file mode 100644 (file)
index 0000000..5ab2f8a
--- /dev/null
@@ -0,0 +1 @@
+Hello
\ No newline at end of file