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()
|
2014-09-26 13:25:14 +00:00
|
|
|
test.istrue(os.isfile("_tests.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()
|
2014-09-18 20:19:08 +00:00
|
|
|
test.istrue(os.pathsearch("nosuchfile", "aaa;bbb;ccc") == nil)
|
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_ReturnsPath_OnFound()
|
2014-09-26 13:25:14 +00:00
|
|
|
test.isequal(_TESTS_DIR, os.pathsearch("_tests.lua", _TESTS_DIR))
|
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()
|
2014-09-26 13:25:14 +00:00
|
|
|
test.isequal(_TESTS_DIR, os.pathsearch("_tests.lua", "aaa;" .. _TESTS_DIR .. ";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()
|
2014-09-26 13:25:14 +00:00
|
|
|
test.isequal(_TESTS_DIR, os.pathsearch("_tests.lua", nil, _TESTS_DIR, nil))
|
2011-02-10 17:24:51 +00:00
|
|
|
end
|
2014-11-27 17:56:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- os.translateCommand() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.translateCommand_onNoToken()
|
|
|
|
test.isequal("cp a b", os.translateCommand("cp a b"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.translateCommand_callsProcessor()
|
|
|
|
os.commandTokens.copy.test = function(value)
|
|
|
|
return "test " .. value
|
|
|
|
end
|
|
|
|
test.isequal("test a b", os.translateCommand("{COPY} a b"))
|
|
|
|
end
|