From 87c4b73aaac6ce77c73ead84b9fb0be03c6b54ab Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Sat, 16 Sep 2023 00:38:19 +0100 Subject: [PATCH] Test withFilePath --- tests/Test.hs | 20 ++++++++++++++++++++ unix.cabal | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/Test.hs b/tests/Test.hs index be08e5e..4c41b2e 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -10,13 +10,19 @@ import Control.Applicative import Control.Concurrent import qualified Control.Exception as E import Control.Monad +import qualified Data.ByteString as B +import qualified Data.ByteString.Short as Sh import Data.List (sort) import System.Exit import System.IO +import System.OsString.Internal.Types import System.Posix import qualified System.Posix.Env.ByteString as ByteString +import qualified System.Posix.ByteString.FilePath as BSFP +import qualified System.Posix.PosixPath.FilePath as PPFP import Test.Tasty import Test.Tasty.HUnit +import Test.Tasty.QuickCheck import qualified FileStatus import qualified FileStatusByteString @@ -49,6 +55,7 @@ main = defaultMain $ testGroup "All" , posix010 -- JS: missing "sysconf" ] #endif + , testWithFilePath ] executeFile001 :: TestTree @@ -245,6 +252,19 @@ posix010 = testCase "posix010" $ do homeDirectory root @?= homeDirectory root' +testWithFilePath :: TestTree +testWithFilePath = + testGroup "withFilePath" + [ testProperty "ByteString" $ + \xs -> let ys = B.pack $ filter (/= 0) xs in + ioProperty $ BSFP.withFilePath ys + (\ptr -> (=== ys) <$> B.packCString ptr) + , testProperty "PosixPath" $ + \xs -> let ys = Sh.pack $ filter (/= 0) xs in + ioProperty $ PPFP.withFilePath (PosixString ys) + (\ptr -> (=== ys) <$> Sh.packCString ptr) + ] + ------------------------------------------------------------------------------- -- Utils diff --git a/unix.cabal b/unix.cabal index 8facf86..0b6642d 100644 --- a/unix.cabal +++ b/unix.cabal @@ -171,7 +171,7 @@ test-suite unix-tests Signals001 type: exitcode-stdio-1.0 default-language: Haskell2010 - build-depends: base, tasty, tasty-hunit, unix + build-depends: base, bytestring, filepath, tasty, tasty-hunit, tasty-quickcheck, unix ghc-options: -Wall -with-rtsopts=-V0 test-suite FdReadBuf001