Skip to content

Commit

Permalink
Add tests for exception safety
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Jan 16, 2024
1 parent b176eb5 commit 0a6cec3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions file-io.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ test-suite T14
build-depends: base, file-io, filepath, temporary
ghc-options: -Wall

test-suite T8
hs-source-dirs: tests
main-is: T8.hs
type: exitcode-stdio-1.0
default-language: Haskell2010
build-depends: base, bytestring, file-io, filepath, temporary
ghc-options: -Wall -threaded

test-suite CLC237
hs-source-dirs: tests
main-is: CLC237.hs
Expand Down
26 changes: 26 additions & 0 deletions tests/T8.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}

module Main where

import Control.Concurrent
import Control.Monad
import System.File.OsPath
import System.OsPath
import System.IO.Temp

import qualified Data.ByteString.Lazy as BL
import qualified System.OsPath as OSP
import qualified System.File.OsPath as OSP

main :: IO ()
main = withSystemTempDirectory "test" $ \baseDir' -> do
let fn = [osp|test.txt|]
baseDir <- OSP.encodeFS baseDir'
let fp = baseDir OSP.</> fn
OSP.writeFile fp ""

replicateM_ 100000 $ do
thr <- forkIO (System.File.OsPath.readFile fp >>= BL.putStr)
threadDelay 1
void $ killThread thr

0 comments on commit 0a6cec3

Please sign in to comment.