Skip to content

Commit 626af39

Browse files
BodigrimLysxia
authored andcommitted
Tests: if disk is full, it's not our problem, skip the test
1 parent 08e006e commit 626af39

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

tests/Tests/Regressions.hs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
1414
import Data.Char (isLetter, chr)
1515
import GHC.Exts (Int(..), sizeofByteArray#)
1616
import System.IO
1717
import System.IO.Temp (withSystemTempFile)
18-
import Test.Tasty.HUnit (assertBool, assertEqual, assertFailure)
18+
import Test.Tasty.HUnit (assertBool, assertEqual, assertFailure, (@?=))
1919
import qualified Data.ByteString as B
2020
import Data.ByteString.Char8 ()
2121
import qualified Data.ByteString.Lazy as LB
@@ -34,28 +34,40 @@ import qualified Data.Text.Lazy.Encoding as LE
3434
import qualified Data.Text.Unsafe as T
3535
import qualified Test.Tasty as F
3636
import qualified Test.Tasty.HUnit as F
37-
import Test.Tasty.HUnit ((@?=))
38-
3937
import 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
4342
-- of bytes.
4443
lazy_encode_crash :: IO ()
45-
lazy_encode_crash = withTempFile $ \ _ h ->
46-
LB.hPut h . LE.encodeUtf8 . LT.pack . replicate 100000 $ 'a'
44+
lazy_encode_crash = withTempFile $ \ _ h -> do
45+
putRes <- try $ LB.hPut h $ LE.encodeUtf8 $ LT.pack $ replicate 100000 'a'
46+
case putRes of
47+
Left e
48+
-- If disk is full (as it happens on some of our CI runners), it's not our issue, skip it
49+
| isFullError e -> pure ()
50+
| otherwise -> assertFailure $ "hPut crashed because of " ++ displayException e
51+
Right () -> pure ()
4752

4853
-- Reported by Pieter Laeremans: attempting to read an incorrectly
4954
-- encoded file can result in a crash in the RTS (i.e. not merely an
5055
-- exception).
5156
hGetContents_crash :: IO ()
5257
hGetContents_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'
58+
putRes <- try $ B.hPut h (B.pack [0x78, 0xc4 ,0x0a])
59+
case putRes of
60+
Left e
61+
-- If disk is full (as it happens on some of our CI runners), it's not our issue, skip it
62+
| isFullError e -> pure ()
63+
| otherwise -> assertFailure $ "hPut crashed because of " ++ displayException e
64+
Right () -> do
65+
hClose h
66+
h' <- openFile path ReadMode
67+
hSetEncoding h' utf8
68+
handle (\(_::SomeException) -> pure ()) $
69+
T.hGetContents h' >> assertFailure "T.hGetContents should crash"
70+
hClose h'
5971

6072
-- Reported by Ian Lynagh: attempting to allocate a sufficiently large
6173
-- string (via either Array.new or Text.replicate) could result in an

0 commit comments

Comments
 (0)