diff options
Diffstat (limited to 'libraries/base/tests/IO')
-rw-r--r-- | libraries/base/tests/IO/T4144.hs | 23 | ||||
-rw-r--r-- | libraries/base/tests/IO/all.T | 15 | ||||
-rw-r--r-- | libraries/base/tests/IO/hClose002.stdout-mingw32 | 4 | ||||
-rw-r--r-- | libraries/base/tests/IO/openFile002.stderr-mingw32 | 1 | ||||
-rw-r--r-- | libraries/base/tests/IO/openFile002.stderr-mingw32-2 | 1 | ||||
-rw-r--r-- | libraries/base/tests/IO/openFile003.stdout-mingw32 | 8 | ||||
-rw-r--r-- | libraries/base/tests/IO/openFile009.hs | 19 | ||||
-rw-r--r-- | libraries/base/tests/IO/openFile009.stdout | 1 |
8 files changed, 55 insertions, 17 deletions
diff --git a/libraries/base/tests/IO/T4144.hs b/libraries/base/tests/IO/T4144.hs index 329601ca38..1fc16c0f07 100644 --- a/libraries/base/tests/IO/T4144.hs +++ b/libraries/base/tests/IO/T4144.hs @@ -46,15 +46,21 @@ remaining (BSIODevice bs mPos) sizeBS :: BSIODevice -> Int sizeBS (BSIODevice bs _) = B.length bs -seekBS :: BSIODevice -> SeekMode -> Int -> IO () -seekBS dev AbsoluteSeek pos +seekBS :: BSIODevice -> SeekMode -> Int -> IO Integer +seekBS dev@(BSIODevice _ mPos) mode pos + = do seekBS' dev mode pos + maybe 0 fromIntegral <$> tryReadMVar mPos + + +seekBS' :: BSIODevice -> SeekMode -> Int -> IO () +seekBS' dev AbsoluteSeek pos | pos < 0 = error "Cannot seek to a negative position!" | pos > sizeBS dev = error "Cannot seek past end of handle!" | otherwise = case dev of BSIODevice _ mPos -> modifyMVar_ mPos $ \_ -> return pos -seekBS dev SeekFromEnd pos = seekBS dev AbsoluteSeek (sizeBS dev - pos) -seekBS dev RelativeSeek pos +seekBS' dev SeekFromEnd pos = seekBS' dev AbsoluteSeek (sizeBS dev - pos) +seekBS' dev RelativeSeek pos = case dev of BSIODevice _bs mPos -> modifyMVar_ mPos $ \curPos -> @@ -69,12 +75,12 @@ tellBS (BSIODevice _ mPos) = readMVar mPos dupBS :: BSIODevice -> IO BSIODevice dupBS (BSIODevice bs mPos) = BSIODevice bs <$> (readMVar mPos >>= newMVar) -readBS :: BSIODevice -> Ptr Word8 -> Int -> IO Int -readBS dev@(BSIODevice bs mPos) buff amount +readBS :: BSIODevice -> Ptr Word8 -> Word64 -> Int -> IO Int +readBS dev@(BSIODevice bs mPos) buff offset amount = do rem <- remaining dev if amount > rem - then readBS dev buff rem + then readBS dev buff offset rem else B.unsafeUseAsCString bs $ \ptr -> do memcpy buff (castPtr ptr) (fromIntegral amount) @@ -91,7 +97,7 @@ instance BufferedIO BSIODevice where instance RawIO BSIODevice where read = readBS - readNonBlocking dev buff n = Just `liftM` readBS dev buff n + readNonBlocking dev buff offset n = Just `liftM` readBS dev buff offset n instance IODevice BSIODevice where ready _ True _ = return False -- read only @@ -112,3 +118,4 @@ instance IODevice BSIODevice where main = bsHandle "test" "<fake file>" >>= Data.ByteString.Char8.hGetContents >>= print + diff --git a/libraries/base/tests/IO/all.T b/libraries/base/tests/IO/all.T index 0ba27f1b42..f03f6a01f1 100644 --- a/libraries/base/tests/IO/all.T +++ b/libraries/base/tests/IO/all.T @@ -16,8 +16,8 @@ test('hFileSize001', normal, compile_and_run, ['']) test('hFileSize002', [omit_ways(['ghci'])], compile_and_run, ['']) test('hFlush001', [], compile_and_run, ['']) -test('hGetBuffering001', - [omit_ways(['ghci']), set_stdin('hGetBuffering001.hs')], +test('hGetBuffering001', + [omit_ways(['ghci']), set_stdin('hGetBuffering001.hs')], compile_and_run, ['']) test('hGetContentsS001', normal, compile_and_run, ['']) @@ -47,7 +47,7 @@ test('hSeek004', [], compile_and_run, ['-cpp']) test('hSetBuffering002', set_stdin('hSetBuffering002.hs'), compile_and_run, ['']) test('hSetBuffering003', - [omit_ways(['ghci']), set_stdin('hSetBuffering003.hs')], + [omit_ways(['ghci']), set_stdin('hSetBuffering003.hs')], compile_and_run, ['']) test('hSetBuffering004', set_stdin('hSetBuffering004.hs'), compile_and_run, ['']) @@ -68,6 +68,7 @@ test('openFile005', [], compile_and_run, ['']) test('openFile006', [], compile_and_run, ['']) test('openFile007', [], compile_and_run, ['']) test('openFile008', cmd_prefix('ulimit -n 2048; '), compile_and_run, ['']) +test('openFile009', [], compile_and_run, ['']) test('putStr001', normal, compile_and_run, ['']) test('readFile001', [], compile_and_run, ['']) @@ -86,7 +87,8 @@ test('hGetBuf001', compile_and_run, ['-package unix']) # As discussed in #16819, this test is racy in a threaded environment. -test('hDuplicateTo001', [omit_ways(concurrent_ways)], compile_and_run, ['']) +test('hDuplicateTo001', [omit_ways(concurrent_ways), + when(opsys('mingw32'), skip)], compile_and_run, ['']) test('countReaders001', [], compile_and_run, ['']) @@ -130,7 +132,10 @@ test('T4144', normal, compile_and_run, ['']) test('encodingerror001', normal, compile_and_run, ['']) -test('T4808', [fragile_for(16909, concurrent_ways), exit_code(1)], compile_and_run, ['']) +# Requires use of the FD interface which is not supported under WINIO +test('T4808', [when(opsys('mingw32'), skip) + ,fragile_for(16909, concurrent_ways), exit_code(1)] + , compile_and_run, ['']) test('T4895', normal, compile_and_run, ['']) test('T7853', normal, compile_and_run, ['']) # Tests ability to perform >32-bit IO operations diff --git a/libraries/base/tests/IO/hClose002.stdout-mingw32 b/libraries/base/tests/IO/hClose002.stdout-mingw32 new file mode 100644 index 0000000000..e05b87a7eb --- /dev/null +++ b/libraries/base/tests/IO/hClose002.stdout-mingw32 @@ -0,0 +1,4 @@ +Left hClose002.tmp: hClose: invalid argument (The handle is invalid.) +Right () +Right () +Right () diff --git a/libraries/base/tests/IO/openFile002.stderr-mingw32 b/libraries/base/tests/IO/openFile002.stderr-mingw32 new file mode 100644 index 0000000000..a75cc496f4 --- /dev/null +++ b/libraries/base/tests/IO/openFile002.stderr-mingw32 @@ -0,0 +1 @@ +openFile002.exe: nonexistent: openFile: does not exist (The system cannot find the file specified.) diff --git a/libraries/base/tests/IO/openFile002.stderr-mingw32-2 b/libraries/base/tests/IO/openFile002.stderr-mingw32-2 new file mode 100644 index 0000000000..b011f34146 --- /dev/null +++ b/libraries/base/tests/IO/openFile002.stderr-mingw32-2 @@ -0,0 +1 @@ +openFile002: nonexistent: openFile: does not exist (No such file or directory) diff --git a/libraries/base/tests/IO/openFile003.stdout-mingw32 b/libraries/base/tests/IO/openFile003.stdout-mingw32 index 77ad0a860a..b808fccc3f 100644 --- a/libraries/base/tests/IO/openFile003.stdout-mingw32 +++ b/libraries/base/tests/IO/openFile003.stdout-mingw32 @@ -1,4 +1,4 @@ -Left openFile003Dir: openFile: permission denied (Permission denied) -Left openFile003Dir: openFile: permission denied (Permission denied) -Left openFile003Dir: openFile: permission denied (Permission denied) -Left openFile003Dir: openFile: permission denied (Permission denied) +Left openFile003Dir: openFile: permission denied (Access is denied.) +Left openFile003Dir: openFile: permission denied (Access is denied.) +Left openFile003Dir: openFile: permission denied (Access is denied.) +Left openFile003Dir: openFile: permission denied (Access is denied.) diff --git a/libraries/base/tests/IO/openFile009.hs b/libraries/base/tests/IO/openFile009.hs new file mode 100644 index 0000000000..b3aa8c9f9b --- /dev/null +++ b/libraries/base/tests/IO/openFile009.hs @@ -0,0 +1,19 @@ +import System.IO +import System.Cmd +import System.FilePath +import Text.Printf +import System.Directory +import Control.Monad + +testfile = "openFile009_testfile" + +-- Make sure opening with append doesn't truncate files. +main = do + h <- openFile testfile WriteMode + hPutStr h "Hello" + hClose h + h <- openFile testfile AppendMode + hPutStr h " World!" + hClose h + s <- readFile testfile + putStrLn s diff --git a/libraries/base/tests/IO/openFile009.stdout b/libraries/base/tests/IO/openFile009.stdout new file mode 100644 index 0000000000..980a0d5f19 --- /dev/null +++ b/libraries/base/tests/IO/openFile009.stdout @@ -0,0 +1 @@ +Hello World! |