Commit 95ef187c authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add a test for rawSystemStdInOut exception handling

Not all the exception handling, just for the case fixed by the previous
patch.

Turns out of course that this is sensitive to the locale encoding, so we
just skip the test when the localeEncoding is not UTF-8.
parent cc35a48a
......@@ -9,7 +9,9 @@ import Data.IORef
import System.Directory ( doesDirectoryExist, doesFileExist
, getTemporaryDirectory
, removeDirectoryRecursive, removeFile )
import System.IO (hClose)
import System.IO (hClose, localeEncoding)
import System.IO.Error
import qualified Control.Exception as Exception
import Test.Tasty
import Test.Tasty.HUnit
......@@ -46,6 +48,24 @@ withTempDirRemovedTest = do
withTempDirectory normal tempDir "foo" $ \dirPath -> do
removeDirectoryRecursive dirPath
rawSystemStdInOutTextDecodingTest :: Assertion
rawSystemStdInOutTextDecodingTest
-- We can only get this exception when the locale encoding is UTF-8
-- so skip the test if it's not.
| show localeEncoding /= "UTF-8" = return ()
| otherwise = do
res <- Exception.try $
rawSystemStdInOut normal
-- hopefully this is sufficiently portable, we just need to execute a
-- program that will produce non-unicode output:
"ghc" ["-e", "Data.ByteString.putStr (Data.ByteString.pack [255])"]
Nothing Nothing Nothing
False -- not binary mode output, ie utf8 text mode so try to decode
case res of
Right _ -> assertFailure "expected IO decoding exception"
Left err | isDoesNotExistError err -> Exception.throwIO err -- no ghc!
| otherwise -> return ()
tests :: [TestTree]
tests =
[ testCase "withTempFile works as expected" $
......@@ -56,4 +76,6 @@ tests =
withTempDirTest
, testCase "withTempDirectory can handle removed directories" $
withTempDirRemovedTest
, testCase "rawSystemStdInOut reports text decoding errors" $
rawSystemStdInOutTextDecodingTest
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment