Skip to content

Commit 87c4b73

Browse files
committed
Test withFilePath
1 parent fadc6e1 commit 87c4b73

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tests/Test.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ import Control.Applicative
1010
import Control.Concurrent
1111
import qualified Control.Exception as E
1212
import Control.Monad
13+
import qualified Data.ByteString as B
14+
import qualified Data.ByteString.Short as Sh
1315
import Data.List (sort)
1416
import System.Exit
1517
import System.IO
18+
import System.OsString.Internal.Types
1619
import System.Posix
1720
import qualified System.Posix.Env.ByteString as ByteString
21+
import qualified System.Posix.ByteString.FilePath as BSFP
22+
import qualified System.Posix.PosixPath.FilePath as PPFP
1823
import Test.Tasty
1924
import Test.Tasty.HUnit
25+
import Test.Tasty.QuickCheck
2026

2127
import qualified FileStatus
2228
import qualified FileStatusByteString
@@ -49,6 +55,7 @@ main = defaultMain $ testGroup "All"
4955
, posix010 -- JS: missing "sysconf"
5056
]
5157
#endif
58+
, testWithFilePath
5259
]
5360

5461
executeFile001 :: TestTree
@@ -245,6 +252,19 @@ posix010 = testCase "posix010" $ do
245252

246253
homeDirectory root @?= homeDirectory root'
247254

255+
testWithFilePath :: TestTree
256+
testWithFilePath =
257+
testGroup "withFilePath"
258+
[ testProperty "ByteString" $
259+
\xs -> let ys = B.pack $ filter (/= 0) xs in
260+
ioProperty $ BSFP.withFilePath ys
261+
(\ptr -> (=== ys) <$> B.packCString ptr)
262+
, testProperty "PosixPath" $
263+
\xs -> let ys = Sh.pack $ filter (/= 0) xs in
264+
ioProperty $ PPFP.withFilePath (PosixString ys)
265+
(\ptr -> (=== ys) <$> Sh.packCString ptr)
266+
]
267+
248268
-------------------------------------------------------------------------------
249269
-- Utils
250270

unix.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ test-suite unix-tests
171171
Signals001
172172
type: exitcode-stdio-1.0
173173
default-language: Haskell2010
174-
build-depends: base, tasty, tasty-hunit, unix
174+
build-depends: base, bytestring, filepath, tasty, tasty-hunit, tasty-quickcheck, unix
175175
ghc-options: -Wall -with-rtsopts=-V0
176176

177177
test-suite FdReadBuf001

0 commit comments

Comments
 (0)