diff options
| author | Fabio Mascarenhas <mascarenhas@acm.org> | 2012-10-01 11:11:48 -0300 |
|---|---|---|
| committer | Fabio Mascarenhas <mascarenhas@acm.org> | 2012-10-01 11:11:48 -0300 |
| commit | d71c63cdb776f7d25313f8fcd14f07512ba1f83e (patch) | |
| tree | 41111619a268eb4d05667807baf54b6c867801d9 /tests | |
| parent | 4a299c53b68cc9a9bf728f46c915e5b43280d896 (diff) | |
| download | luafilesystem-d71c63cdb776f7d25313f8fcd14f07512ba1f83e.tar.gz luafilesystem-d71c63cdb776f7d25313f8fcd14f07512ba1f83e.tar.bz2 luafilesystem-d71c63cdb776f7d25313f8fcd14f07512ba1f83e.zip | |
luafilesystem 1.6.0
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test.lua | 81 |
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 = ".." | |||
| 7 | local lfs = require"lfs" | 7 | local lfs = require"lfs" |
| 8 | print (lfs._VERSION) | 8 | print (lfs._VERSION) |
| 9 | 9 | ||
| 10 | io.write(".") | ||
| 11 | io.flush() | ||
| 12 | |||
| 10 | function attrdir (path) | 13 | function 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 |
| 26 | end | 29 | end |
| 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") | |||
| 33 | assert (lfs.currentdir() == current, "error trying to change directories") | 36 | assert (lfs.currentdir() == current, "error trying to change directories") |
| 34 | assert (lfs.chdir ("this couldn't be an actual directory") == nil, "could change to a non-existent directory") | 37 | assert (lfs.chdir ("this couldn't be an actual directory") == nil, "could change to a non-existent directory") |
| 35 | 38 | ||
| 39 | io.write(".") | ||
| 40 | io.flush() | ||
| 41 | |||
| 36 | -- Changing creating and removing directories | 42 | -- Changing creating and removing directories |
| 37 | local tmpdir = current..sep.."lfs_tmp_dir" | 43 | local tmpdir = current..sep.."lfs_tmp_dir" |
| 38 | local tmpfile = tmpdir..sep.."tmp_file" | 44 | local 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 |
| 41 | if lfs.chdir (tmpdir) then | 47 | if 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") |
| 45 | end | 51 | end |
| 46 | 52 | ||
| 53 | io.write(".") | ||
| 54 | io.flush() | ||
| 55 | |||
| 47 | -- tries to create a directory | 56 | -- tries to create a directory |
| 48 | assert (lfs.mkdir (tmpdir), "could not make a new directory") | 57 | assert (lfs.mkdir (tmpdir), "could not make a new directory") |
| 49 | local attrib, errmsg = lfs.attributes (tmpdir) | 58 | local attrib, errmsg = lfs.attributes (tmpdir) |
| 50 | if not attrib then | 59 | if 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) |
| 52 | end | 61 | end |
| 53 | local f = io.open(tmpfile, "w") | 62 | local f = io.open(tmpfile, "w") |
| 54 | f:close() | 63 | f:close() |
| 55 | 64 | ||
| 65 | io.write(".") | ||
| 66 | io.flush() | ||
| 67 | |||
| 56 | -- Change access time | 68 | -- Change access time |
| 57 | local testdate = os.time({ year = 2007, day = 10, month = 2, hour=0}) | 69 | local testdate = os.time({ year = 2007, day = 10, month = 2, hour=0}) |
| 58 | assert (lfs.touch (tmpfile, testdate)) | 70 | assert (lfs.touch (tmpfile, testdate)) |
| @@ -60,6 +72,9 @@ local new_att = assert (lfs.attributes (tmpfile)) | |||
| 60 | assert (new_att.access == testdate, "could not set access time") | 72 | assert (new_att.access == testdate, "could not set access time") |
| 61 | assert (new_att.modification == testdate, "could not set modification time") | 73 | assert (new_att.modification == testdate, "could not set modification time") |
| 62 | 74 | ||
| 75 | io.write(".") | ||
| 76 | io.flush() | ||
| 77 | |||
| 63 | -- Change access and modification time | 78 | -- Change access and modification time |
| 64 | local testdate1 = os.time({ year = 2007, day = 10, month = 2, hour=0}) | 79 | local testdate1 = os.time({ year = 2007, day = 10, month = 2, hour=0}) |
| 65 | local testdate2 = os.time({ year = 2007, day = 11, month = 2, hour=0}) | 80 | local testdate2 = os.time({ year = 2007, day = 11, month = 2, hour=0}) |
| @@ -69,6 +84,9 @@ local new_att = assert (lfs.attributes (tmpfile)) | |||
| 69 | assert (new_att.access == testdate2, "could not set access time") | 84 | assert (new_att.access == testdate2, "could not set access time") |
| 70 | assert (new_att.modification == testdate1, "could not set modification time") | 85 | assert (new_att.modification == testdate1, "could not set modification time") |
| 71 | 86 | ||
| 87 | io.write(".") | ||
| 88 | io.flush() | ||
| 89 | |||
| 72 | -- Checking link (does not work on Windows) | 90 | -- Checking link (does not work on Windows) |
| 73 | if lfs.link (tmpfile, "_a_link_for_test_", true) then | 91 | if 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_") |
| 80 | end | 98 | end |
| 81 | 99 | ||
| 100 | io.write(".") | ||
| 101 | io.flush() | ||
| 102 | |||
| 82 | -- Checking text/binary modes (only has an effect in Windows) | 103 | -- Checking text/binary modes (only has an effect in Windows) |
| 83 | local f = io.open(tmpfile, "w") | 104 | local f = io.open(tmpfile, "w") |
| 84 | local result, mode = lfs.setmode(f, "binary") | 105 | local result, mode = lfs.setmode(f, "binary") |
| @@ -86,30 +107,45 @@ assert(result) -- on non-Windows platforms, mode is always returned as "binary" | |||
| 86 | result, mode = lfs.setmode(f, "text") | 107 | result, mode = lfs.setmode(f, "text") |
| 87 | assert(result and mode == "binary") | 108 | assert(result and mode == "binary") |
| 88 | f:close() | 109 | f:close() |
| 89 | 110 | ||
| 111 | io.write(".") | ||
| 112 | io.flush() | ||
| 113 | |||
| 90 | -- Restore access time to current value | 114 | -- Restore access time to current value |
| 91 | assert (lfs.touch (tmpfile, attrib.access, attrib.modification)) | 115 | assert (lfs.touch (tmpfile, attrib.access, attrib.modification)) |
| 92 | new_att = assert (lfs.attributes (tmpfile)) | 116 | new_att = assert (lfs.attributes (tmpfile)) |
| 93 | assert (new_att.access == attrib.access) | 117 | assert (new_att.access == attrib.access) |
| 94 | assert (new_att.modification == attrib.modification) | 118 | assert (new_att.modification == attrib.modification) |
| 95 | 119 | ||
| 120 | io.write(".") | ||
| 121 | io.flush() | ||
| 122 | |||
| 96 | -- Remove new file and directory | 123 | -- Remove new file and directory |
| 97 | assert (os.remove (tmpfile), "could not remove new file") | 124 | assert (os.remove (tmpfile), "could not remove new file") |
| 98 | assert (lfs.rmdir (tmpdir), "could not remove new directory") | 125 | assert (lfs.rmdir (tmpdir), "could not remove new directory") |
| 99 | assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == nil, "could create a directory inside a non-existent one") | 126 | assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == nil, "could create a directory inside a non-existent one") |
| 100 | 127 | ||
| 128 | io.write(".") | ||
| 129 | io.flush() | ||
| 130 | |||
| 101 | -- Trying to get attributes of a non-existent file | 131 | -- Trying to get attributes of a non-existent file |
| 102 | assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file") | 132 | assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file") |
| 103 | assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") | 133 | assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") |
| 104 | 134 | ||
| 135 | io.write(".") | ||
| 136 | io.flush() | ||
| 137 | |||
| 105 | -- Stressing directory iterator | 138 | -- Stressing directory iterator |
| 106 | count = 0 | 139 | count = 0 |
| 107 | for i = 1, 4000 do | 140 | for 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 |
| 111 | end | 144 | end |
| 112 | 145 | ||
| 146 | io.write(".") | ||
| 147 | io.flush() | ||
| 148 | |||
| 113 | -- Stressing directory iterator, explicit version | 149 | -- Stressing directory iterator, explicit version |
| 114 | count = 0 | 150 | count = 0 |
| 115 | for i = 1, 4000 do | 151 | for 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)) |
| 123 | end | 159 | end |
| 124 | 160 | ||
| 161 | io.write(".") | ||
| 162 | io.flush() | ||
| 163 | |||
| 125 | -- directory explicit close | 164 | -- directory explicit close |
| 126 | local iter, dir = lfs.dir(tmp) | 165 | local iter, dir = lfs.dir(tmp) |
| 127 | dir:close() | 166 | dir:close() |
