Skip to content

Commit 5eb0993

Browse files
luispedrohs-viktor
authored andcommitted
Add a test for createLink
Very basic, but tests that the created link is a hard link and points to the original file
1 parent 4ecf524 commit 5eb0993

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

tests/FileStatus.hs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ main = do
1616
fs <- testRegular
1717
ds <- testDir
1818
testSymlink fs ds
19+
testLink
1920
cleanup
2021

21-
regular = "regular"
22-
dir = "dir"
23-
link_regular = "link-regular"
24-
link_dir = "link-dir"
22+
regular = "regular"
23+
dir = "dir"
24+
slink_regular = "link-regular-symlink"
25+
hlink_regular = "link-regular-hardlink"
26+
link_dir = "link-dir"
2527

2628
testRegular = do
2729
_ <- createFile regular ownerReadMode
@@ -42,9 +44,9 @@ testDir = do
4244
return ds
4345

4446
testSymlink fs ds = do
45-
createSymbolicLink regular link_regular
47+
createSymbolicLink regular slink_regular
4648
createSymbolicLink dir link_dir
47-
(fs', ls) <- getStatus link_regular
49+
(fs', ls) <- getStatus slink_regular
4850
(ds', lds) <- getStatus link_dir
4951

5052
let expected = (False,False,False,False,False,True,False)
@@ -63,10 +65,35 @@ testSymlink fs ds = do
6365
when (statusElements ds /= statusElements ds') $
6466
fail "status for a directory does not match when it's accessed via a symlink"
6567

68+
69+
testLink = do
70+
createLink regular hlink_regular
71+
(fs, _) <- getStatus regular -- we need to retrieve it again as creating the link causes it to change!
72+
(fs', ls) <- getStatus hlink_regular
73+
let expected = (
74+
False, -- isBlockDevice
75+
False, -- isCharacterDevice
76+
False, -- isNamedPipe
77+
True, -- isRegularFile
78+
False, -- isDirectory
79+
False, -- isSymbolicLink
80+
False) -- isSocket
81+
actualF = snd (statusElements ls)
82+
83+
when (actualF /= expected) $
84+
fail "unexpected file status bits for hard link to regular file"
85+
86+
when (linkCount fs' /= 2) $
87+
fail "newly created hard link was expected to contain have a link count of 2"
88+
89+
when (statusElements fs /= statusElements fs') $
90+
fail "status for a file does not match when it's accessed via a link"
91+
92+
6693
cleanup = do
6794
ignoreIOExceptions $ removeDirectory dir
6895
mapM_ (ignoreIOExceptions . removeLink)
69-
[regular, link_regular, link_dir]
96+
[regular, hlink_regular, slink_regular, link_dir]
7097

7198
ignoreIOExceptions io = io `E.catch`
7299
((\_ -> return ()) :: IOException -> IO ())

0 commit comments

Comments
 (0)