From 0a6cec31bcfa8c898f4b1b47c95159ade27e1054 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 16 Jan 2024 21:29:06 +0800 Subject: [PATCH] Add tests for exception safety --- file-io.cabal | 8 ++++++++ tests/T8.hs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/T8.hs diff --git a/file-io.cabal b/file-io.cabal index 2b52e83..d2e21dd 100644 --- a/file-io.cabal +++ b/file-io.cabal @@ -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 diff --git a/tests/T8.hs b/tests/T8.hs new file mode 100644 index 0000000..ed2917a --- /dev/null +++ b/tests/T8.hs @@ -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