diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2020-04-21 00:10:28 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2020-04-21 13:45:50 -0300 |
| commit | 6048863a96779db026d369dccb92d53076490065 (patch) | |
| tree | 07c81ad72eab9b03afc63a4b56165374faf30fde /tests/test.lua | |
| parent | 1a61e5284df50cdccd065424dfcb1975dace4c2d (diff) | |
| download | luafilesystem-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
Diffstat (limited to 'tests/test.lua')
| -rw-r--r-- | tests/test.lua | 35 |
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" | |||
| 4 | local sep = string.match (package.config, "[^\n]+") | 4 | local sep = string.match (package.config, "[^\n]+") |
| 5 | local upper = ".." | 5 | local upper = ".." |
| 6 | 6 | ||
| 7 | local is_unix = package.config:sub(1,1) == "/" | ||
| 8 | |||
| 7 | local lfs = require"lfs" | 9 | local lfs = require"lfs" |
| 8 | print (lfs._VERSION) | 10 | print (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) |
| 61 | end | 63 | end |
| 62 | local f = io.open(tmpfile, "w") | 64 | local f = io.open(tmpfile, "w") |
| 65 | local data = "hello, file!" | ||
| 66 | f:write(data) | ||
| 63 | f:close() | 67 | f:close() |
| 64 | 68 | ||
| 65 | io.write(".") | 69 | io.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_") |
| 100 | end | 133 | end |
