aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2020-04-21 00:10:28 -0300
committerHisham Muhammad <hisham@gobolinux.org>2020-04-21 13:45:50 -0300
commit6048863a96779db026d369dccb92d53076490065 (patch)
tree07c81ad72eab9b03afc63a4b56165374faf30fde
parent1a61e5284df50cdccd065424dfcb1975dace4c2d (diff)
downloadluafilesystem-6048863a96779db026d369dccb92d53076490065.tar.gz
luafilesystem-6048863a96779db026d369dccb92d53076490065.tar.bz2
luafilesystem-6048863a96779db026d369dccb92d53076490065.zip
tests: behavior test for hard links
Also check nlink on Unix only and test if something is a symlink
-rw-r--r--tests/test.lua35
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/test.lua b/tests/test.lua
index 591ee25..095f072 100644
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -4,6 +4,8 @@ local tmp = "/tmp"
4local sep = string.match (package.config, "[^\n]+") 4local sep = string.match (package.config, "[^\n]+")
5local upper = ".." 5local upper = ".."
6 6
7local is_unix = package.config:sub(1,1) == "/"
8
7local lfs = require"lfs" 9local lfs = require"lfs"
8print (lfs._VERSION) 10print (lfs._VERSION)
9 11
@@ -60,6 +62,8 @@ if not attrib then
60 error ("could not get attributes of file `"..tmpdir.."':\n"..errmsg) 62 error ("could not get attributes of file `"..tmpdir.."':\n"..errmsg)
61end 63end
62local f = io.open(tmpfile, "w") 64local f = io.open(tmpfile, "w")
65local data = "hello, file!"
66f:write(data)
63f:close() 67f:close()
64 68
65io.write(".") 69io.write(".")
@@ -93,8 +97,37 @@ if lfs.link (tmpfile, "_a_link_for_test_", true) then
93 assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link") 97 assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link")
94 assert (lfs.symlinkattributes"_a_link_for_test_".target == tmpfile) 98 assert (lfs.symlinkattributes"_a_link_for_test_".target == tmpfile)
95 assert (lfs.symlinkattributes("_a_link_for_test_", "target") == tmpfile) 99 assert (lfs.symlinkattributes("_a_link_for_test_", "target") == tmpfile)
100
101 assert (lfs.symlinkattributes(tmpfile).mode == "file")
102
96 assert (lfs.link (tmpfile, "_a_hard_link_for_test_")) 103 assert (lfs.link (tmpfile, "_a_hard_link_for_test_"))
97 assert (lfs.attributes (tmpfile, "nlink") == 2) 104 assert (lfs.symlinkattributes"_a_hard_link_for_test_".mode == "file")
105
106 local fd = io.open(tmpfile)
107 assert(fd:read("*a") == data)
108 fd:close()
109
110 fd = io.open("_a_link_for_test_")
111 assert(fd:read("*a") == data)
112 fd:close()
113
114 fd = io.open("_a_hard_link_for_test_")
115 assert(fd:read("*a") == data)
116 fd:close()
117
118 fd = io.open("_a_hard_link_for_test_", "w+")
119 local data2 = "write in hard link"
120 fd:write(data2)
121 fd:close()
122
123 fd = io.open(tmpfile)
124 assert(fd:read("*a") == data2)
125 fd:close()
126
127 if is_unix then
128 assert (lfs.attributes (tmpfile, "nlink") == 2)
129 end
130
98 assert (os.remove"_a_link_for_test_") 131 assert (os.remove"_a_link_for_test_")
99 assert (os.remove"_a_hard_link_for_test_") 132 assert (os.remove"_a_hard_link_for_test_")
100end 133end