Skip to content

Commit 3d02405

Browse files
committed
Tests: if disk is full, it's not our problem, skip the test
1 parent 8f45869 commit 3d02405

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

tests/Tests/Regressions.hs

Lines changed: 16 additions & 10 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,9 +34,8 @@ 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
@@ -50,12 +49,19 @@ lazy_encode_crash = withTempFile $ \ _ h ->
5049
-- exception).
5150
hGetContents_crash :: IO ()
5251
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'
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

Comments
 (0)