2008-10-31 18:38:05 +00:00
|
|
|
--
|
2010-01-13 23:29:21 +00:00
|
|
|
-- tests/base/test_os.lua
|
2008-10-31 18:38:05 +00:00
|
|
|
-- Automated test suite for the new OS functions.
|
2010-01-13 23:29:21 +00:00
|
|
|
-- Copyright (c) 2008-2010 Jason Perkins and the Premake project
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
|
|
|
|
T.os = { }
|
2009-12-22 16:07:55 +00:00
|
|
|
local suite = T.os
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2008-11-13 00:54:41 +00:00
|
|
|
|
2008-12-22 19:59:34 +00:00
|
|
|
--
|
|
|
|
-- os.findlib() tests
|
|
|
|
--
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.findlib_FindSystemLib()
|
2008-12-22 19:59:34 +00:00
|
|
|
local libname = iif(os.is("windows"), "user32", "m")
|
|
|
|
test.istrue(os.findlib(libname))
|
|
|
|
end
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.findlib_FailsOnBadLibName()
|
2008-12-22 20:03:43 +00:00
|
|
|
test.isfalse(os.findlib("NoSuchLibraryAsThisOneHere"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- os.isfile() tests
|
|
|
|
--
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.isfile_ReturnsTrue_OnExistingFile()
|
2010-01-13 23:29:21 +00:00
|
|
|
test.istrue(os.isfile("premake4.lua"))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.isfile_ReturnsFalse_OnNonexistantFile()
|
2008-10-31 18:38:05 +00:00
|
|
|
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
|
|
|
|
--
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.matchfiles_OnNonRecursive()
|
|
|
|
local result = os.matchfiles("*.lua")
|
|
|
|
test.istrue(table.contains(result, "testfx.lua"))
|
|
|
|
test.isfalse(table.contains(result, "folder/ok.lua"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.matchfiles_Recursive()
|
2008-12-22 19:21:06 +00:00
|
|
|
local result = os.matchfiles("**.lua")
|
|
|
|
test.istrue(table.contains(result, "folder/ok.lua"))
|
|
|
|
end
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.matchfiles_SkipsDotDirs_OnRecursive()
|
|
|
|
local result = os.matchfiles("**.lua")
|
|
|
|
test.isfalse(table.contains(result, ".svn/text-base/testfx.lua.svn-base"))
|
2008-12-22 19:21:06 +00:00
|
|
|
end
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.matchfiles_OnSubfolderMatch()
|
|
|
|
local result = os.matchfiles("**/xcode/*")
|
|
|
|
test.istrue(table.contains(result, "actions/xcode/test_xcode_project.lua"))
|
|
|
|
test.isfalse(table.contains(result, "premake4.lua"))
|
|
|
|
end
|
2010-01-13 23:29:21 +00:00
|
|
|
|
|
|
|
function suite.matchfiles_OnDotSlashPrefix()
|
|
|
|
local result = os.matchfiles("./**.lua")
|
|
|
|
test.istrue(table.contains(result, "folder/ok.lua"))
|
|
|
|
end
|
|
|
|
|
2008-12-22 19:21:06 +00:00
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- os.pathsearch() tests
|
|
|
|
--
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.pathsearch_ReturnsNil_OnNotFound()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.istrue( os.pathsearch("nosuchfile", "aaa;bbb;ccc") == nil )
|
|
|
|
end
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.pathsearch_ReturnsPath_OnFound()
|
2010-01-13 23:29:21 +00:00
|
|
|
test.isequal(os.getcwd(), os.pathsearch("premake4.lua", os.getcwd()))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.pathsearch_FindsFile_OnComplexPath()
|
2010-01-13 23:29:21 +00:00
|
|
|
test.isequal(os.getcwd(), os.pathsearch("premake4.lua", "aaa;"..os.getcwd()..";bbb"))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.pathsearch_NilPathsAllowed()
|
2010-01-13 23:29:21 +00:00
|
|
|
test.isequal(os.getcwd(), os.pathsearch("premake4.lua", nil, os.getcwd(), nil))
|
2008-11-13 00:54:41 +00:00
|
|
|
end
|
2009-12-22 16:07:55 +00:00
|
|
|
|
2008-11-13 00:54:41 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- os.uuid() tests
|
|
|
|
--
|
|
|
|
|
2009-12-22 16:07:55 +00:00
|
|
|
function suite.guid_ReturnsValidUUID()
|
2008-11-13 00:54:41 +00:00
|
|
|
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
|
|
|
|