diff options
Diffstat (limited to '3rdparty/luafilesystem/tests/test.lua')
-rw-r--r-- | 3rdparty/luafilesystem/tests/test.lua | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/3rdparty/luafilesystem/tests/test.lua b/3rdparty/luafilesystem/tests/test.lua index abfbd4d9690..ed154c09362 100644 --- a/3rdparty/luafilesystem/tests/test.lua +++ b/3rdparty/luafilesystem/tests/test.lua @@ -4,6 +4,8 @@ local tmp = "/tmp" local sep = string.match (package.config, "[^\n]+") local upper = ".." +local is_unix = package.config:sub(1,1) == "/" + local lfs = require"lfs" print (lfs._VERSION) @@ -60,6 +62,8 @@ if not attrib then error ("could not get attributes of file `"..tmpdir.."':\n"..errmsg) end local f = io.open(tmpfile, "w") +local data = "hello, file!" +f:write(data) f:close() io.write(".") @@ -87,12 +91,42 @@ assert (new_att.modification == testdate1, "could not set modification time") io.write(".") io.flush() --- Checking link (does not work on Windows) if lfs.link (tmpfile, "_a_link_for_test_", true) then assert (lfs.attributes"_a_link_for_test_".mode == "file") assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link") + assert (lfs.symlinkattributes"_a_link_for_test_".target == tmpfile) + assert (lfs.symlinkattributes("_a_link_for_test_", "target") == tmpfile) + + assert (lfs.symlinkattributes(tmpfile).mode == "file") + assert (lfs.link (tmpfile, "_a_hard_link_for_test_")) - assert (lfs.attributes (tmpfile, "nlink") == 2) + assert (lfs.symlinkattributes"_a_hard_link_for_test_".mode == "file") + + local fd = io.open(tmpfile) + assert(fd:read("*a") == data) + fd:close() + + fd = io.open("_a_link_for_test_") + assert(fd:read("*a") == data) + fd:close() + + fd = io.open("_a_hard_link_for_test_") + assert(fd:read("*a") == data) + fd:close() + + fd = io.open("_a_hard_link_for_test_", "w+") + local data2 = "write in hard link" + fd:write(data2) + fd:close() + + fd = io.open(tmpfile) + assert(fd:read("*a") == data2) + fd:close() + + if is_unix then + assert (lfs.attributes (tmpfile, "nlink") == 2) + end + assert (os.remove"_a_link_for_test_") assert (os.remove"_a_hard_link_for_test_") end @@ -107,6 +141,9 @@ assert(result) -- on non-Windows platforms, mode is always returned as "binary" result, mode = lfs.setmode(f, "text") assert(result and mode == "binary") f:close() +local ok, err = pcall(lfs.setmode, f, "binary") +assert(not ok, "could setmode on closed file") +assert(err:find("closed file"), "bad error message for setmode on closed file") io.write(".") io.flush() @@ -127,6 +164,17 @@ for key, value in pairs(attr) do "lfs.attributes values not consistent") end +-- Check that lfs.attributes accepts a table as second argument +local attr2 = {} +lfs.attributes(tmpfile, attr2) +for key, value in pairs(attr2) do + assert (value == lfs.attributes (tmpfile, key), + "lfs.attributes values with table argument not consistent") +end + +-- Check that extra arguments are ignored +lfs.attributes(tmpfile, attr2, nil) + -- Remove new file and directory assert (os.remove (tmpfile), "could not remove new file") assert (lfs.rmdir (tmpdir), "could not remove new directory") @@ -136,7 +184,10 @@ io.write(".") io.flush() -- Trying to get attributes of a non-existent file -assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file") +local attr_ok, err, errno = lfs.attributes("this couldn't be an actual file") +assert(attr_ok == nil, "could get attributes of a non-existent file") +assert(type(err) == "string", "failed lfs.attributes did not return an error message") +assert(type(errno) == "number", "failed lfs.attributes did not return error code") assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") io.write(".") |