aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoruid20013 <uid20013>2005-08-16 00:11:15 +0000
committeruid20013 <uid20013>2005-08-16 00:11:15 +0000
commite224c98838fd37372eb9ca592f30e3b888d1cc3a (patch)
tree5b54c6fc4b9d34b9538e66484a9b4ce04a6b8bdd /tests
parent865d2453ff6b3a87a2551b2b398ebbb5d580531a (diff)
downloadluafilesystem-e224c98838fd37372eb9ca592f30e3b888d1cc3a.tar.gz
luafilesystem-e224c98838fd37372eb9ca592f30e3b888d1cc3a.tar.bz2
luafilesystem-e224c98838fd37372eb9ca592f30e3b888d1cc3a.zip
Closing directory after a complete traversal.
Adding tests for that.
Diffstat (limited to 'tests')
-rw-r--r--tests/test.lua57
1 files changed, 30 insertions, 27 deletions
diff --git a/tests/test.lua b/tests/test.lua
index d0018cd..07436f9 100644
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -9,7 +9,7 @@ require"lfs"
9function attrdir (path) 9function attrdir (path)
10 for file in lfs.dir(path) do 10 for file in lfs.dir(path) do
11 if file ~= "." and file ~= ".." then 11 if file ~= "." and file ~= ".." then
12 local f = path..sep..file 12 local f = path..'/'..file
13 print ("\t=> "..f.." <=") 13 print ("\t=> "..f.." <=")
14 local attr = lfs.attributes (f) 14 local attr = lfs.attributes (f)
15 assert (type(attr) == "table") 15 assert (type(attr) == "table")
@@ -32,35 +32,38 @@ assert (lfs.chdir (reldir), "could not change back to current directory")
32assert (lfs.currentdir() == current, "error trying to change directories") 32assert (lfs.currentdir() == current, "error trying to change directories")
33assert (lfs.chdir ("this couldn't be an actual directory") == nil, "could change to a non-existent directory") 33assert (lfs.chdir ("this couldn't be an actual directory") == nil, "could change to a non-existent directory")
34-- Changing creating and removing directories 34-- Changing creating and removing directories
35local tmpdir = tmp..sep.."lfs_tmp_dir" 35local tmpdir = tmp.."/lfs_tmp_dir"
36assert (lfs.mkdir (tmpdir), "could not make a new directory") 36assert (lfs.mkdir (tmpdir), "could not make a new directory")
37-- create a new file 37local attrib, errmsg = lfs.attributes (tmpdir)
38local tmpfile = tmpdir..sep.."lfs_tmp_file"
39assert (io.open(tmpfile, "w"), "could not make a new file")
40local attrib, errmsg = lfs.attributes (tmpfile)
41if not attrib then 38if not attrib then
42 error ("could not get attributes of file `"..tmpfile.."':\n"..errmsg) 39 error ("could not get attributes of file `"..tmpdir.."':\n"..errmsg)
43else
44 -- Change access time
45 assert (lfs.touch (tmpfile, 11))
46 local new_att = assert (lfs.attributes (tmpfile))
47 assert (new_att.access == 11, string.format("could not set access time: %s", tostring(new_att.access)))
48 assert (new_att.modification == 11, "could not set modification time")
49 -- Change access and modification time
50 assert (lfs.touch (tmpfile, 33, 22))
51 local new_att = assert (lfs.attributes (tmpfile))
52 assert (new_att.access == 33, "could not set access time")
53 assert (new_att.modification == 22, "could not set modification time")
54 -- Restore access time to current value
55 assert (lfs.touch (tmpfile))
56 new_att = assert (lfs.attributes (tmpfile))
57 assert (new_att.access == attrib.access)
58 assert (new_att.modification == attrib.modification)
59end 40end
60assert (os.remove (tmpfile), "could not remove file") 41-- Change access time
61assert (lfs.rmdir (tmpdir), "could not remove new directory") 42assert (lfs.touch (tmpdir, 11))
62assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == false, "could create a directory inside a non-existent one") 43local new_att = assert (lfs.attributes (tmpdir))
63-- 44assert (new_att.access == 11, "could not set access time")
45assert (new_att.modification == 11, "could not set modification time")
46-- Change access and modification time
47assert (lfs.touch (tmpdir, 33, 22))
48local new_att = assert (lfs.attributes (tmpdir))
49assert (new_att.access == 33, "could not set access time")
50assert (new_att.modification == 22, "could not set modification time")
51-- Restore access time to current value
52assert (lfs.touch (tmpdir))
53new_att = assert (lfs.attributes (tmpdir))
54assert (new_att.access == attrib.access)
55assert (new_att.modification == attrib.modification)
56-- Remove new directory
57assert (os.remove (tmpdir), "could not remove new directory")
58assert (lfs.mkdir (tmpdir.."/lfs_tmp_dir") == false, "could create a directory inside a non-existent one")
59-- Trying to get attributes of a non-existent file
64assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file") 60assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file")
65assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") 61assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory")
62-- Stressing directory iterator
63count = 0
64for i = 1, 4000 do
65 for file in lfs.dir (tmp) do
66 count = count + 1
67 end
68end
66print"Ok!" 69print"Ok!"