@@ -10,12 +10,12 @@ module Tests.Regressions
1010 tests
1111 ) where
1212
13- import Control.Exception (ErrorCall , SomeException , handle , evaluate )
13+ import Control.Exception (ErrorCall , SomeException , handle , evaluate , displayException , try )
1414import Data.Char (isLetter , chr )
1515import GHC.Exts (Int (.. ), sizeofByteArray #)
1616import System.IO
1717import System.IO.Temp (withSystemTempFile )
18- import Test.Tasty.HUnit (assertBool , assertEqual , assertFailure )
18+ import Test.Tasty.HUnit (assertBool , assertEqual , assertFailure , (@?=) )
1919import qualified Data.ByteString as B
2020import Data.ByteString.Char8 ()
2121import qualified Data.ByteString.Lazy as LB
@@ -34,9 +34,8 @@ import qualified Data.Text.Lazy.Encoding as LE
3434import qualified Data.Text.Unsafe as T
3535import qualified Test.Tasty as F
3636import qualified Test.Tasty.HUnit as F
37- import Test.Tasty.HUnit ((@?=) )
38-
3937import Tests.Utils (withTempFile )
38+ import System.IO.Error (isFullError )
4039
4140-- Reported by Michael Snoyman: UTF-8 encoding a large lazy bytestring
4241-- caused either a segfault or attempt to allocate a negative number
@@ -50,12 +49,19 @@ lazy_encode_crash = withTempFile $ \ _ h ->
5049-- exception).
5150hGetContents_crash :: IO ()
5251hGetContents_crash = withSystemTempFile " crashy.txt" $ \ path h -> do
53- B. hPut h (B. pack [0x78 , 0xc4 ,0x0a ]) >> hClose h
54- h' <- openFile path ReadMode
55- hSetEncoding h' utf8
56- handle (\ (_:: SomeException ) -> return () ) $
57- T. hGetContents h' >> assertFailure " T.hGetContents should crash"
58- hClose h'
52+ putRes <- try $ B. hPut h (B. pack [0x78 , 0xc4 ,0x0a ])
53+ case putRes of
54+ Left e
55+ -- If disk is full (as it happens on some of our CI runners), it's not our issue, skip it
56+ | isFullError e -> pure ()
57+ | otherwise -> assertFailure $ " B.hPut crashed because of " ++ displayException e
58+ Right () -> do
59+ hClose h
60+ h' <- openFile path ReadMode
61+ hSetEncoding h' utf8
62+ handle (\ (_:: SomeException ) -> pure () ) $
63+ T. hGetContents h' >> assertFailure " T.hGetContents should crash"
64+ hClose h'
5965
6066-- Reported by Ian Lynagh: attempting to allocate a sufficiently large
6167-- string (via either Array.new or Text.replicate) could result in an
0 commit comments