Skip to content

Fix struct dirent d_type macro test #348

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cbits/HsUnix.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ char *__hscore_d_name( struct dirent* d )

char __hscore_d_type( struct dirent* d )
{
#ifdef HAVE_DIRENT_D_TYPE
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
return (d->d_type);
#else
return CONST_DT_UNKNOWN;
Expand Down
33 changes: 33 additions & 0 deletions tests/DirEntType.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{-# LANGUAGE LambdaCase #-}

module Main (main) where

import Control.Exception (bracket)
import Foreign.C.String (peekCString)
import System.Exit (die)
import System.Posix.Directory
import System.Posix.Directory.Internals
import Text.Printf (printf)

peekDirEnt :: DirEnt -> IO (String, DirType)
peekDirEnt dirEnt = do
dName <- dirEntName dirEnt >>= peekCString
dType <- dirEntType dirEnt
return (dName, dType)

testDirTypeOfProcSelf :: DirStream -> IO ()
testDirTypeOfProcSelf dirStream = go where
go = readDirStreamWith peekDirEnt dirStream >>= \case
Just (dName, dType) -> case dName of
"self" -> case dType of
SymbolicLinkType -> return ()
_ -> die $
printf "DirEnt of /proc/self has %s; expected %s!"
(show dType)
(show SymbolicLinkType)
_ -> go
Nothing -> die
"Didn't find \"self\" DirEnt while reading /proc DirStream!"

main :: IO ()
main = bracket (openDirStream "/proc") closeDirStream testDirTypeOfProcSelf
12 changes: 12 additions & 0 deletions unix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,15 @@ test-suite T13660
else
build-depends: filepath >= 1.4.100.0 && < 1.5.0.0
ghc-options: -Wall

test-suite DirEntType
if !os(linux)
build-depends: unbuildable<0
buildable: False

hs-source-dirs: tests
main-is: DirEntType.hs
type: exitcode-stdio-1.0
default-language: Haskell2010
build-depends: base, unix
ghc-options: -Wall