2011-02-10 17:24:51 +00:00
|
|
|
--
|
|
|
|
-- tests/base/test_os.lua
|
|
|
|
-- Automated test suite for the new OS functions.
|
2014-04-24 14:49:06 +00:00
|
|
|
-- Copyright (c) 2008-2014 Jason Perkins and the Premake project
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
|
|
|
|
2012-12-29 18:26:41 +00:00
|
|
|
local suite = test.declare("base_os")
|
2011-02-10 17:24:51 +00:00
|
|
|
|
2014-09-17 23:19:47 +00:00
|
|
|
local cwd
|
|
|
|
|
|
|
|
function suite.setup()
|
|
|
|
cwd = os.getcwd()
|
|
|
|
os.chdir(_TESTS_DIR)
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.teardown()
|
|
|
|
os.chdir(cwd)
|
|
|
|
end
|
|
|
|
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
|
|
|
-- os.findlib() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.findlib_FindSystemLib()
|
|
|
|
if os.is("windows") then
|
|
|
|
test.istrue(os.findlib("user32"))
|
|
|
|
elseif os.is("haiku") then
|
2013-01-12 16:52:59 +00:00
|
|
|
test.istrue(os.findlib("root"))
|
2011-02-10 17:24:51 +00:00
|
|
|
else
|
2013-01-12 16:52:59 +00:00
|
|
|
test.istrue(os.findlib("m"))
|
2011-02-10 17:24:51 +00:00
|
|
|
end
|
|
|
|
end
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
function suite.findlib_FailsOnBadLibName()
|
|
|
|
test.isfalse(os.findlib("NoSuchLibraryAsThisOneHere"))
|
|
|
|
end
|
2013-01-12 16:52:59 +00:00
|
|
|
|
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
|
|
|
-- os.isfile() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.isfile_ReturnsTrue_OnExistingFile()
|
2013-09-10 20:24:39 +00:00
|
|
|
test.istrue(os.isfile("premake5.lua"))
|
2011-02-10 17:24:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function suite.isfile_ReturnsFalse_OnNonexistantFile()
|
|
|
|
test.isfalse(os.isfile("no_such_file.lua"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-29 19:45:15 +00:00
|
|
|
--
|
|
|
|
-- os.matchdirs() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.matchdirs_skipsDottedDirs()
|
|
|
|
local result = os.matchdirs("*")
|
|
|
|
test.isfalse(table.contains(result, ".."))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
|
|
|
-- os.matchfiles() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.matchfiles_OnNonRecursive()
|
|
|
|
local result = os.matchfiles("*.lua")
|
|
|
|
test.istrue(table.contains(result, "testfx.lua"))
|
2013-01-12 16:52:59 +00:00
|
|
|
test.isfalse(table.contains(result, "folder/ok.lua"))
|
2011-02-10 17:24:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function suite.matchfiles_Recursive()
|
|
|
|
local result = os.matchfiles("**.lua")
|
|
|
|
test.istrue(table.contains(result, "folder/ok.lua"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.matchfiles_SkipsDotDirs_OnRecursive()
|
|
|
|
local result = os.matchfiles("**.lua")
|
|
|
|
test.isfalse(table.contains(result, ".svn/text-base/testfx.lua.svn-base"))
|
|
|
|
end
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
function suite.matchfiles_OnSubfolderMatch()
|
2013-01-12 16:52:59 +00:00
|
|
|
local result = os.matchfiles("**/vc2010/*")
|
|
|
|
test.istrue(table.contains(result, "actions/vstudio/vc2010/test_globals.lua"))
|
2011-02-10 17:24:51 +00:00
|
|
|
test.isfalse(table.contains(result, "premake4.lua"))
|
|
|
|
end
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
function suite.matchfiles_OnDotSlashPrefix()
|
|
|
|
local result = os.matchfiles("./**.lua")
|
|
|
|
test.istrue(table.contains(result, "folder/ok.lua"))
|
|
|
|
end
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
function suite.matchfiles_OnImplicitEndOfString()
|
|
|
|
local result = os.matchfiles("folder/*.lua")
|
|
|
|
test.istrue(table.contains(result, "folder/ok.lua"))
|
|
|
|
test.isfalse(table.contains(result, "folder/ok.lua.2"))
|
|
|
|
end
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
function suite.matchfiles_OnLeadingDotSlashWithPath()
|
|
|
|
local result = os.matchfiles("./folder/*.lua")
|
|
|
|
test.istrue(table.contains(result, "folder/ok.lua"))
|
|
|
|
end
|
|
|
|
|
2014-04-24 14:49:06 +00:00
|
|
|
function suite.matchfiles_OnDottedFile()
|
|
|
|
local result = os.matchfiles("../.*")
|
|
|
|
test.istrue(table.contains(result, "../.hgignore"))
|
|
|
|
end
|
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
|
|
|
-- os.pathsearch() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.pathsearch_ReturnsNil_OnNotFound()
|
|
|
|
test.istrue( os.pathsearch("nosuchfile", "aaa;bbb;ccc") == nil )
|
|
|
|
end
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
function suite.pathsearch_ReturnsPath_OnFound()
|
2013-09-10 20:24:39 +00:00
|
|
|
test.isequal(os.getcwd(), os.pathsearch("premake5.lua", os.getcwd()))
|
2011-02-10 17:24:51 +00:00
|
|
|
end
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
function suite.pathsearch_FindsFile_OnComplexPath()
|
2013-09-10 20:24:39 +00:00
|
|
|
test.isequal(os.getcwd(), os.pathsearch("premake5.lua", "aaa;"..os.getcwd()..";bbb"))
|
2011-02-10 17:24:51 +00:00
|
|
|
end
|
2013-01-12 16:52:59 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
function suite.pathsearch_NilPathsAllowed()
|
2013-09-10 20:24:39 +00:00
|
|
|
test.isequal(os.getcwd(), os.pathsearch("premake5.lua", nil, os.getcwd(), nil))
|
2011-02-10 17:24:51 +00:00
|
|
|
end
|