aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test.lua33
1 files changed, 22 insertions, 11 deletions
diff --git a/tests/test.lua b/tests/test.lua
index a152bbb..3522bee 100644
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -1,4 +1,4 @@
1#!/usr/local/bin/lua 1#!/usr/local/bin/lua50
2 2
3local tmp = "/tmp" 3local tmp = "/tmp"
4local sep = "/" 4local sep = "/"
@@ -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..'/'..file 12 local f = path..sep..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")
@@ -31,34 +31,45 @@ assert (lfs.chdir (upper), "could not change to upper directory")
31assert (lfs.chdir (reldir), "could not change back to current directory") 31assert (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
34-- Changing creating and removing directories 35-- Changing creating and removing directories
35local tmpdir = tmp.."/lfs_tmp_dir" 36local tmpdir = tmp..sep.."lfs_tmp_dir"
37local tmpfile = tmpdir..sep.."tmp_file"
36assert (lfs.mkdir (tmpdir), "could not make a new directory") 38assert (lfs.mkdir (tmpdir), "could not make a new directory")
37local attrib, errmsg = lfs.attributes (tmpdir) 39local attrib, errmsg = lfs.attributes (tmpdir)
38if not attrib then 40if not attrib then
39 error ("could not get attributes of file `"..tmpdir.."':\n"..errmsg) 41 error ("could not get attributes of file `"..tmpdir.."':\n"..errmsg)
40end 42end
43local f = io.open(tmpfile, "w")
44f:close()
45
41-- Change access time 46-- Change access time
42assert (lfs.touch (tmpdir, 11)) 47assert (lfs.touch (tmpfile, 11))
43local new_att = assert (lfs.attributes (tmpdir)) 48local new_att = assert (lfs.attributes (tmpfile))
44assert (new_att.access == 11, "could not set access time") 49assert (new_att.access == 11, "could not set access time")
45assert (new_att.modification == 11, "could not set modification time") 50assert (new_att.modification == 11, "could not set modification time")
51
46-- Change access and modification time 52-- Change access and modification time
47assert (lfs.touch (tmpdir, 33, 22)) 53assert (lfs.touch (tmpfile, 33, 22))
48local new_att = assert (lfs.attributes (tmpdir)) 54local new_att = assert (lfs.attributes (tmpfile))
49assert (new_att.access == 33, "could not set access time") 55assert (new_att.access == 33, "could not set access time")
50assert (new_att.modification == 22, "could not set modification time") 56assert (new_att.modification == 22, "could not set modification time")
57
51-- Restore access time to current value 58-- Restore access time to current value
52assert (lfs.touch (tmpdir)) 59assert (lfs.touch (tmpfile))
53new_att = assert (lfs.attributes (tmpdir)) 60new_att = assert (lfs.attributes (tmpfile))
54assert (new_att.access == attrib.access) 61assert (new_att.access == attrib.access)
55assert (new_att.modification == attrib.modification) 62assert (new_att.modification == attrib.modification)
56-- Remove new directory 63
64-- Remove new file and directory
65assert (os.remove (tmpfile), "could not remove new file")
57assert (lfs.rmdir (tmpdir), "could not remove new directory") 66assert (lfs.rmdir (tmpdir), "could not remove new directory")
58assert (lfs.mkdir (tmpdir.."/lfs_tmp_dir") == false, "could create a directory inside a non-existent one") 67assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == false, "could create a directory inside a non-existent one")
68
59-- Trying to get attributes of a non-existent file 69-- Trying to 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") 70assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file")
61assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") 71assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory")
72
62-- Stressing directory iterator 73-- Stressing directory iterator
63count = 0 74count = 0
64for i = 1, 4000 do 75for i = 1, 4000 do