aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test.lua81
1 files changed, 60 insertions, 21 deletions
diff --git a/tests/test.lua b/tests/test.lua
index 20948df..4990aec 100644
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -7,22 +7,25 @@ local upper = ".."
7local lfs = require"lfs" 7local lfs = require"lfs"
8print (lfs._VERSION) 8print (lfs._VERSION)
9 9
10io.write(".")
11io.flush()
12
10function attrdir (path) 13function attrdir (path)
11 for file in lfs.dir(path) do 14 for file in lfs.dir(path) do
12 if file ~= "." and file ~= ".." then 15 if file ~= "." and file ~= ".." then
13 local f = path..sep..file 16 local f = path..sep..file
14 print ("\t=> "..f.." <=") 17 print ("\t=> "..f.." <=")
15 local attr = lfs.attributes (f) 18 local attr = lfs.attributes (f)
16 assert (type(attr) == "table") 19 assert (type(attr) == "table")
17 if attr.mode == "directory" then 20 if attr.mode == "directory" then
18 attrdir (f) 21 attrdir (f)
19 else 22 else
20 for name, value in pairs(attr) do 23 for name, value in pairs(attr) do
21 print (name, value) 24 print (name, value)
22 end 25 end
23 end 26 end
24 end 27 end
25 end 28 end
26end 29end
27 30
28-- Checking changing directories 31-- Checking changing directories
@@ -33,6 +36,9 @@ assert (lfs.chdir (reldir), "could not change back to current directory")
33assert (lfs.currentdir() == current, "error trying to change directories") 36assert (lfs.currentdir() == current, "error trying to change directories")
34assert (lfs.chdir ("this couldn't be an actual directory") == nil, "could change to a non-existent directory") 37assert (lfs.chdir ("this couldn't be an actual directory") == nil, "could change to a non-existent directory")
35 38
39io.write(".")
40io.flush()
41
36-- Changing creating and removing directories 42-- Changing creating and removing directories
37local tmpdir = current..sep.."lfs_tmp_dir" 43local tmpdir = current..sep.."lfs_tmp_dir"
38local tmpfile = tmpdir..sep.."tmp_file" 44local tmpfile = tmpdir..sep.."tmp_file"
@@ -40,19 +46,25 @@ local tmpfile = tmpdir..sep.."tmp_file"
40-- that may have resulted from an interrupted test execution and remove it 46-- that may have resulted from an interrupted test execution and remove it
41if lfs.chdir (tmpdir) then 47if lfs.chdir (tmpdir) then
42 assert (lfs.chdir (upper), "could not change to upper directory") 48 assert (lfs.chdir (upper), "could not change to upper directory")
43 assert (os.remove (tmpfile), "could not remove file from previous test") 49 assert (os.remove (tmpfile), "could not remove file from previous test")
44 assert (lfs.rmdir (tmpdir), "could not remove directory from previous test") 50 assert (lfs.rmdir (tmpdir), "could not remove directory from previous test")
45end 51end
46 52
53io.write(".")
54io.flush()
55
47-- tries to create a directory 56-- tries to create a directory
48assert (lfs.mkdir (tmpdir), "could not make a new directory") 57assert (lfs.mkdir (tmpdir), "could not make a new directory")
49local attrib, errmsg = lfs.attributes (tmpdir) 58local attrib, errmsg = lfs.attributes (tmpdir)
50if not attrib then 59if not attrib then
51 error ("could not get attributes of file `"..tmpdir.."':\n"..errmsg) 60 error ("could not get attributes of file `"..tmpdir.."':\n"..errmsg)
52end 61end
53local f = io.open(tmpfile, "w") 62local f = io.open(tmpfile, "w")
54f:close() 63f:close()
55 64
65io.write(".")
66io.flush()
67
56-- Change access time 68-- Change access time
57local testdate = os.time({ year = 2007, day = 10, month = 2, hour=0}) 69local testdate = os.time({ year = 2007, day = 10, month = 2, hour=0})
58assert (lfs.touch (tmpfile, testdate)) 70assert (lfs.touch (tmpfile, testdate))
@@ -60,6 +72,9 @@ local new_att = assert (lfs.attributes (tmpfile))
60assert (new_att.access == testdate, "could not set access time") 72assert (new_att.access == testdate, "could not set access time")
61assert (new_att.modification == testdate, "could not set modification time") 73assert (new_att.modification == testdate, "could not set modification time")
62 74
75io.write(".")
76io.flush()
77
63-- Change access and modification time 78-- Change access and modification time
64local testdate1 = os.time({ year = 2007, day = 10, month = 2, hour=0}) 79local testdate1 = os.time({ year = 2007, day = 10, month = 2, hour=0})
65local testdate2 = os.time({ year = 2007, day = 11, month = 2, hour=0}) 80local testdate2 = os.time({ year = 2007, day = 11, month = 2, hour=0})
@@ -69,6 +84,9 @@ local new_att = assert (lfs.attributes (tmpfile))
69assert (new_att.access == testdate2, "could not set access time") 84assert (new_att.access == testdate2, "could not set access time")
70assert (new_att.modification == testdate1, "could not set modification time") 85assert (new_att.modification == testdate1, "could not set modification time")
71 86
87io.write(".")
88io.flush()
89
72-- Checking link (does not work on Windows) 90-- Checking link (does not work on Windows)
73if lfs.link (tmpfile, "_a_link_for_test_", true) then 91if lfs.link (tmpfile, "_a_link_for_test_", true) then
74 assert (lfs.attributes"_a_link_for_test_".mode == "file") 92 assert (lfs.attributes"_a_link_for_test_".mode == "file")
@@ -79,6 +97,9 @@ if lfs.link (tmpfile, "_a_link_for_test_", true) then
79 assert (os.remove"_a_hard_link_for_test_") 97 assert (os.remove"_a_hard_link_for_test_")
80end 98end
81 99
100io.write(".")
101io.flush()
102
82-- Checking text/binary modes (only has an effect in Windows) 103-- Checking text/binary modes (only has an effect in Windows)
83local f = io.open(tmpfile, "w") 104local f = io.open(tmpfile, "w")
84local result, mode = lfs.setmode(f, "binary") 105local result, mode = lfs.setmode(f, "binary")
@@ -86,30 +107,45 @@ assert(result) -- on non-Windows platforms, mode is always returned as "binary"
86result, mode = lfs.setmode(f, "text") 107result, mode = lfs.setmode(f, "text")
87assert(result and mode == "binary") 108assert(result and mode == "binary")
88f:close() 109f:close()
89 110
111io.write(".")
112io.flush()
113
90-- Restore access time to current value 114-- Restore access time to current value
91assert (lfs.touch (tmpfile, attrib.access, attrib.modification)) 115assert (lfs.touch (tmpfile, attrib.access, attrib.modification))
92new_att = assert (lfs.attributes (tmpfile)) 116new_att = assert (lfs.attributes (tmpfile))
93assert (new_att.access == attrib.access) 117assert (new_att.access == attrib.access)
94assert (new_att.modification == attrib.modification) 118assert (new_att.modification == attrib.modification)
95 119
120io.write(".")
121io.flush()
122
96-- Remove new file and directory 123-- Remove new file and directory
97assert (os.remove (tmpfile), "could not remove new file") 124assert (os.remove (tmpfile), "could not remove new file")
98assert (lfs.rmdir (tmpdir), "could not remove new directory") 125assert (lfs.rmdir (tmpdir), "could not remove new directory")
99assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == nil, "could create a directory inside a non-existent one") 126assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == nil, "could create a directory inside a non-existent one")
100 127
128io.write(".")
129io.flush()
130
101-- Trying to get attributes of a non-existent file 131-- Trying to get attributes of a non-existent file
102assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file") 132assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file")
103assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") 133assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory")
104 134
135io.write(".")
136io.flush()
137
105-- Stressing directory iterator 138-- Stressing directory iterator
106count = 0 139count = 0
107for i = 1, 4000 do 140for i = 1, 4000 do
108 for file in lfs.dir (tmp) do 141 for file in lfs.dir (tmp) do
109 count = count + 1 142 count = count + 1
110 end 143 end
111end 144end
112 145
146io.write(".")
147io.flush()
148
113-- Stressing directory iterator, explicit version 149-- Stressing directory iterator, explicit version
114count = 0 150count = 0
115for i = 1, 4000 do 151for i = 1, 4000 do
@@ -122,6 +158,9 @@ for i = 1, 4000 do
122 assert(not pcall(dir.next, dir)) 158 assert(not pcall(dir.next, dir))
123end 159end
124 160
161io.write(".")
162io.flush()
163
125-- directory explicit close 164-- directory explicit close
126local iter, dir = lfs.dir(tmp) 165local iter, dir = lfs.dir(tmp)
127dir:close() 166dir:close()