From 4d5d1e75fa5950b39873b46b3ab21fd39028e4f1 Mon Sep 17 00:00:00 2001 From: tomas Date: Mon, 1 Nov 2004 15:27:13 +0000 Subject: Pequenas correcoes nos valores de retorno de algumas funcoes. Acrescimo do arquivo de testes. --- tests/test.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test.lua (limited to 'tests') diff --git a/tests/test.lua b/tests/test.lua new file mode 100644 index 0000000..5703bfb --- /dev/null +++ b/tests/test.lua @@ -0,0 +1,40 @@ +#!/usr/local/bin/lua + +local tmp = "/tmp" +local sep = "/" +local upper = ".." + +require"lfs" + +function attrdir (path) + for file in lfs.dir(path) do + if file ~= "." and file ~= ".." then + local f = path..'/'..file + print ("\t=> "..f.." <=") + local attr = lfs.attributes (f) + assert (type(attr) == "table") + if attr.mode == "directory" then + attrdir (f) + else + for name, value in pairs(attr) do + print (name, value) + end + end + end + end +end + +-- Checking changing directories +local current = assert (lfs.currentdir()) +local reldir = string.gsub (current, "^.*%"..sep.."([^"..sep.."])$", "%1") +assert (lfs.chdir (upper), "could not change to upper directory") +assert (lfs.chdir (reldir), "could not change back to current directory") +assert (lfs.currentdir() == current, "error trying to change directories") +assert (lfs.chdir ("this couldn't be an actual directory") == false, "could change to a non-existent directory") +-- Changing creating and removing directories +assert (lfs.mkdir (tmp.."/lfs_tmp_dir"), "could not make a new directory") +assert (os.remove (tmp.."/lfs_tmp_dir"), "could not remove new directory") +assert (lfs.mkdir (tmp.."/lfs_tmp_dir/lfs_tmp_dir") == false, "could create a directory inside a non-existent one") +-- +assert (lfs.attributes ("this couldn't be an actual file") == false, "could get attributes of a non-existent file") +assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") -- cgit v1.2.3-55-g6feb