diff options
author | uid20013 <uid20013> | 2005-08-16 00:11:15 +0000 |
---|---|---|
committer | uid20013 <uid20013> | 2005-08-16 00:11:15 +0000 |
commit | e224c98838fd37372eb9ca592f30e3b888d1cc3a (patch) | |
tree | 5b54c6fc4b9d34b9538e66484a9b4ce04a6b8bdd /tests | |
parent | 865d2453ff6b3a87a2551b2b398ebbb5d580531a (diff) | |
download | luafilesystem-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.lua | 57 |
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" | |||
9 | function attrdir (path) | 9 | function 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") | |||
32 | assert (lfs.currentdir() == current, "error trying to change directories") | 32 | assert (lfs.currentdir() == current, "error trying to change directories") |
33 | assert (lfs.chdir ("this couldn't be an actual directory") == nil, "could change to a non-existent directory") | 33 | assert (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 |
35 | local tmpdir = tmp..sep.."lfs_tmp_dir" | 35 | local tmpdir = tmp.."/lfs_tmp_dir" |
36 | assert (lfs.mkdir (tmpdir), "could not make a new directory") | 36 | assert (lfs.mkdir (tmpdir), "could not make a new directory") |
37 | -- create a new file | 37 | local attrib, errmsg = lfs.attributes (tmpdir) |
38 | local tmpfile = tmpdir..sep.."lfs_tmp_file" | ||
39 | assert (io.open(tmpfile, "w"), "could not make a new file") | ||
40 | local attrib, errmsg = lfs.attributes (tmpfile) | ||
41 | if not attrib then | 38 | if 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) |
43 | else | ||
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) | ||
59 | end | 40 | end |
60 | assert (os.remove (tmpfile), "could not remove file") | 41 | -- Change access time |
61 | assert (lfs.rmdir (tmpdir), "could not remove new directory") | 42 | assert (lfs.touch (tmpdir, 11)) |
62 | assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == false, "could create a directory inside a non-existent one") | 43 | local new_att = assert (lfs.attributes (tmpdir)) |
63 | -- | 44 | assert (new_att.access == 11, "could not set access time") |
45 | assert (new_att.modification == 11, "could not set modification time") | ||
46 | -- Change access and modification time | ||
47 | assert (lfs.touch (tmpdir, 33, 22)) | ||
48 | local new_att = assert (lfs.attributes (tmpdir)) | ||
49 | assert (new_att.access == 33, "could not set access time") | ||
50 | assert (new_att.modification == 22, "could not set modification time") | ||
51 | -- Restore access time to current value | ||
52 | assert (lfs.touch (tmpdir)) | ||
53 | new_att = assert (lfs.attributes (tmpdir)) | ||
54 | assert (new_att.access == attrib.access) | ||
55 | assert (new_att.modification == attrib.modification) | ||
56 | -- Remove new directory | ||
57 | assert (os.remove (tmpdir), "could not remove new directory") | ||
58 | assert (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 | ||
64 | assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file") | 60 | assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file") |
65 | assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") | 61 | assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") |
62 | -- Stressing directory iterator | ||
63 | count = 0 | ||
64 | for i = 1, 4000 do | ||
65 | for file in lfs.dir (tmp) do | ||
66 | count = count + 1 | ||
67 | end | ||
68 | end | ||
66 | print"Ok!" | 69 | print"Ok!" |