Skip to content

Test withFilePath #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,6 +55,7 @@ main = defaultMain $ testGroup "All"
, posix010 -- JS: missing "sysconf"
]
#endif
, testWithFilePath
]

executeFile001 :: TestTree
Expand Down Expand Up @@ -245,6 +252,20 @@ posix010 = testCase "posix010" $ do

homeDirectory root @?= homeDirectory root'

testWithFilePath :: TestTree
testWithFilePath =
adjustOption (\(QuickCheckTests n) -> QuickCheckTests (n `max` 10000)) $
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

Expand Down
2 changes: 1 addition & 1 deletion unix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down