2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- tests/test_os.lua
|
|
|
|
-- Automated test suite for the new OS functions.
|
|
|
|
-- Copyright (c) 2008 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
|
|
|
|
|
|
|
T.os = { }
|
|
|
|
|
2008-11-13 00:54:41 +00:00
|
|
|
|
2008-12-22 19:59:34 +00:00
|
|
|
--
|
|
|
|
-- os.findlib() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.os.findlib_FindSystemLib()
|
|
|
|
local libname = iif(os.is("windows"), "user32", "m")
|
|
|
|
test.istrue(os.findlib(libname))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- os.isfile() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.os.isfile_ReturnsTrue_OnExistingFile()
|
2008-11-13 00:54:41 +00:00
|
|
|
test.istrue(os.isfile("test_os.lua"))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function T.os.isfile_ReturnsFalse_OnNonexistantFile()
|
|
|
|
test.isfalse(os.isfile("no_such_file.lua"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-11-13 00:54:41 +00:00
|
|
|
|
2008-12-22 19:21:06 +00:00
|
|
|
--
|
|
|
|
-- os.matchfiles() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.os.matchfiles_Recursive()
|
|
|
|
local result = os.matchfiles("**.lua")
|
|
|
|
test.istrue(table.contains(result, "folder/ok.lua"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.os.matchfiles_NonRecursive()
|
|
|
|
local result = os.matchfiles("*.lua")
|
|
|
|
test.isfalse(table.contains(result, "folder/ok.lua"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- os.pathsearch() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.os.pathsearch_ReturnsNil_OnNotFound()
|
|
|
|
test.istrue( os.pathsearch("nosuchfile", "aaa;bbb;ccc") == nil )
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.os.pathsearch_ReturnsPath_OnFound()
|
2008-11-13 00:54:41 +00:00
|
|
|
test.isequal(os.getcwd(), os.pathsearch("test_os.lua", os.getcwd()))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function T.os.pathsearch_FindsFile_OnComplexPath()
|
2008-11-13 00:54:41 +00:00
|
|
|
test.isequal(os.getcwd(), os.pathsearch("test_os.lua", "aaa;"..os.getcwd()..";bbb"))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function T.os.pathsearch_NilPathsAllowed()
|
2008-11-13 00:54:41 +00:00
|
|
|
test.isequal(os.getcwd(), os.pathsearch("test_os.lua", nil, os.getcwd(), nil))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- os.uuid() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.os.guid_ReturnsValidUUID()
|
|
|
|
local g = os.uuid()
|
|
|
|
test.istrue(#g == 36)
|
|
|
|
for i=1,36 do
|
|
|
|
local ch = g:sub(i,i)
|
|
|
|
test.istrue(ch:find("[ABCDEF0123456789-]"))
|
|
|
|
end
|
|
|
|
test.isequal("-", g:sub(9,9))
|
|
|
|
test.isequal("-", g:sub(14,14))
|
|
|
|
test.isequal("-", g:sub(19,19))
|
|
|
|
test.isequal("-", g:sub(24,24))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
2008-11-13 00:54:41 +00:00
|
|
|
|