2008-10-31 18:38:05 +00:00
|
|
|
--
|
2009-09-29 19:27:33 +00:00
|
|
|
-- tests/base/test_path.lua
|
|
|
|
-- Automated test suite for the action list.
|
2013-01-04 15:18:47 +00:00
|
|
|
-- Copyright (c) 2008-2013 Jason Perkins and the Premake project
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
|
2013-01-03 16:11:31 +00:00
|
|
|
local suite = test.declare("path")
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- path.getabsolute() tests
|
|
|
|
--
|
|
|
|
|
2013-01-04 15:18:47 +00:00
|
|
|
function suite.getabsolute_worksWithMissingSubdirs()
|
|
|
|
local expected = os.getcwd() .. "/a/b/c"
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal(expected, path.getabsolute("a/b/c"))
|
|
|
|
end
|
|
|
|
|
2013-01-04 15:18:47 +00:00
|
|
|
function suite.getabsolute_removesDotDots_onWindows()
|
2008-12-05 21:18:47 +00:00
|
|
|
test.isequal("c:/ProjectB/bin", path.getabsolute("c:/ProjectA/../ProjectB/bin"))
|
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2013-01-04 15:18:47 +00:00
|
|
|
function suite.getabsolute_removesDotDots_OnPosix()
|
2008-12-05 21:18:47 +00:00
|
|
|
test.isequal("/ProjectB/bin", path.getabsolute("/ProjectA/../ProjectB/bin"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2013-01-04 15:18:47 +00:00
|
|
|
function suite.getabsolute_limitsDotDots_onWindows()
|
|
|
|
test.isequal("c:/ProjectB/bin", path.getabsolute("c:/ProjectA/../../ProjectB/bin"))
|
2009-05-29 19:07:35 +00:00
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2013-01-04 15:18:47 +00:00
|
|
|
function suite.getabsolute_limitsDotDots_OnPosix()
|
|
|
|
test.isequal("/ProjectB/bin", path.getabsolute("/ProjectA/../../ProjectB/bin"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.getabsolute_removesDot()
|
|
|
|
test.isequal("/ProjectA/ProjectB/bin", path.getabsolute("/ProjectA/./ProjectB/bin"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.getabsolute_removesTrailingSlash()
|
|
|
|
test.isequal("/a/b/c", path.getabsolute("/a/b/c/"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.getabsolute_onLeadingEnvVar()
|
2011-03-23 20:38:40 +00:00
|
|
|
test.isequal("$(HOME)/user", path.getabsolute("$(HOME)/user"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2013-01-04 15:18:47 +00:00
|
|
|
function suite.getabsolute_onMultipleEnvVar()
|
2011-03-23 20:38:40 +00:00
|
|
|
test.isequal("$(HOME)/$(USER)", path.getabsolute("$(HOME)/$(USER)"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2013-01-04 15:18:47 +00:00
|
|
|
function suite.getabsolute_onTrailingEnvVar()
|
|
|
|
test.isequal("/home/$(USER)", path.getabsolute("/home/$(USER)"))
|
2011-03-23 20:38:40 +00:00
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2013-01-04 15:18:47 +00:00
|
|
|
function suite.getabsolute_onLeadingEnvVarQuoted()
|
2012-03-19 22:57:45 +00:00
|
|
|
test.isequal('"$(HOME)/user"', path.getabsolute('"$(HOME)/user"'))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2013-01-04 15:18:47 +00:00
|
|
|
function suite.getabsolute_normalizesPaths()
|
|
|
|
test.isequal("c:/ProjectB/bin", path.getabsolute("c:\\ProjectB\\bin"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.getabsolute_acceptsTables()
|
|
|
|
test.isequal({ "/a/b", "/c/d" }, path.getabsolute({ "/a/b", "/c/d" }))
|
|
|
|
end
|
|
|
|
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- path.getbasename() tests
|
|
|
|
--
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getbasename_ReturnsCorrectName_OnDirAndExtension()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("filename", path.getbasename("folder/filename.ext"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- path.getdirectory() tests
|
|
|
|
--
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getdirectory_ReturnsEmptyString_OnNoDirectory()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal(".", path.getdirectory("filename.ext"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getdirectory_ReturnsDirectory_OnSingleLevelPath()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("dir0", path.getdirectory("dir0/filename.ext"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getdirectory_ReturnsDirectory_OnMultiLeveLPath()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("dir0/dir1/dir2", path.getdirectory("dir0/dir1/dir2/filename.ext"))
|
|
|
|
end
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getdirectory_ReturnsRootPath_OnRootPathOnly()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("/", path.getdirectory("/filename.ext"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2009-01-05 15:40:05 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- path.getdrive() tests
|
|
|
|
--
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getdrive_ReturnsNil_OnNotWindows()
|
2009-01-05 15:40:05 +00:00
|
|
|
test.isnil(path.getdrive("/hello"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getdrive_ReturnsLetter_OnWindowsAbsolute()
|
2009-01-05 15:40:05 +00:00
|
|
|
test.isequal("x", path.getdrive("x:/hello"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- path.getextension() tests
|
|
|
|
--
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getextension_ReturnsEmptyString_OnNoExtension()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("", path.getextension("filename"))
|
|
|
|
end
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getextension_ReturnsExtension()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal(".txt", path.getextension("filename.txt"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getextension_OnMultipleDots()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal(".txt", path.getextension("filename.mod.txt"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2011-07-12 20:55:27 +00:00
|
|
|
function suite.getextension_OnLeadingNumeric()
|
|
|
|
test.isequal(".7z", path.getextension("filename.7z"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2011-07-12 20:55:27 +00:00
|
|
|
function suite.getextension_OnUnderscore()
|
|
|
|
test.isequal(".a_c", path.getextension("filename.a_c"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2011-07-12 20:55:27 +00:00
|
|
|
function suite.getextension_OnHyphen()
|
|
|
|
test.isequal(".a-c", path.getextension("filename.a-c"))
|
|
|
|
end
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- path.getrelative() tests
|
|
|
|
--
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getrelative_ReturnsDot_OnMatchingPaths()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal(".", path.getrelative("/a/b/c", "/a/b/c"))
|
|
|
|
end
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getrelative_ReturnsDoubleDot_OnChildToParent()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("..", path.getrelative("/a/b/c", "/a/b"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getrelative_ReturnsDoubleDot_OnSiblingToSibling()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("../d", path.getrelative("/a/b/c", "/a/b/d"))
|
|
|
|
end
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getrelative_ReturnsChildPath_OnParentToChild()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("d", path.getrelative("/a/b/c", "/a/b/c/d"))
|
|
|
|
end
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getrelative_ReturnsChildPath_OnWindowsAbsolute()
|
2008-12-15 15:00:35 +00:00
|
|
|
test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getrelative_ReturnsAbsPath_OnDifferentDriveLetters()
|
2009-01-05 15:40:05 +00:00
|
|
|
test.isequal("D:/Files", path.getrelative("C:/Code/Premake4", "D:/Files"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.getrelative_ReturnsAbsPath_OnDollarMacro()
|
|
|
|
test.isequal("$(SDK_HOME)/include", path.getrelative("C:/Code/Premake4", "$(SDK_HOME)/include"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2010-02-27 02:50:55 +00:00
|
|
|
function suite.getrelative_ReturnsAbsPath_OnRootedPath()
|
|
|
|
test.isequal("/opt/include", path.getrelative("/home/me/src/project", "/opt/include"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- path.isabsolute() tests
|
|
|
|
--
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.isabsolute_ReturnsTrue_OnAbsolutePosixPath()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.istrue(path.isabsolute("/a/b/c"))
|
|
|
|
end
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.isabsolute_ReturnsTrue_OnAbsoluteWindowsPathWithDrive()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.istrue(path.isabsolute("C:/a/b/c"))
|
|
|
|
end
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.isabsolute_ReturnsFalse_OnRelativePath()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isfalse(path.isabsolute("a/b/c"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.isabsolute_ReturnsTrue_OnDollarSign()
|
2009-11-25 19:40:23 +00:00
|
|
|
test.istrue(path.isabsolute("$(SDK_HOME)/include"))
|
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- path.join() tests
|
|
|
|
--
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.join_OnValidParts()
|
2012-01-19 20:28:24 +00:00
|
|
|
test.isequal("p1/p2", path.join("p1", "p2"))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.join_OnAbsoluteUnixPath()
|
2012-01-19 20:28:24 +00:00
|
|
|
test.isequal("/p2", path.join("p1", "/p2"))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.join_OnAbsoluteWindowsPath()
|
2012-01-19 20:28:24 +00:00
|
|
|
test.isequal("C:/p2", path.join("p1", "C:/p2"))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.join_OnCurrentDirectory()
|
2012-01-19 20:28:24 +00:00
|
|
|
test.isequal("p2", path.join(".", "p2"))
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2011-01-18 17:25:43 +00:00
|
|
|
function suite.join_OnNilSecondPart()
|
2012-01-19 20:28:24 +00:00
|
|
|
test.isequal("p1", path.join("p1", nil))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2012-01-19 20:28:24 +00:00
|
|
|
function suite.join_onMoreThanTwoParts()
|
|
|
|
test.isequal("p1/p2/p3", path.join("p1", "p2", "p3"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.join_removesExtraInternalSlashes()
|
|
|
|
test.isequal("p1/p2", path.join("p1/", "p2"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.join_removesTrailingSlash()
|
|
|
|
test.isequal("p1/p2", path.join("p1", "p2/"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.join_ignoresNilParts()
|
|
|
|
test.isequal("p2", path.join(nil, "p2", nil))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.join_ignoresEmptyParts()
|
|
|
|
test.isequal("p2", path.join("", "p2", ""))
|
2011-01-18 17:25:43 +00:00
|
|
|
end
|
|
|
|
|
2013-01-03 16:11:31 +00:00
|
|
|
function suite.join_canJoinBareSlash()
|
|
|
|
test.isequal("/Users", path.join("/", "Users"))
|
|
|
|
end
|
|
|
|
|
2009-09-29 19:27:33 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- path.rebase() tests
|
|
|
|
--
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.rebase_WithEndingSlashOnPath()
|
2009-09-29 19:27:33 +00:00
|
|
|
local cwd = os.getcwd()
|
|
|
|
test.isequal("src", path.rebase("../src/", cwd, path.getdirectory(cwd)))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- path.translate() tests
|
|
|
|
--
|
|
|
|
|
2009-12-08 20:25:35 +00:00
|
|
|
function suite.translate_ReturnsTranslatedPath_OnValidPath()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("dir/dir/file", path.translate("dir\\dir\\file", "/"))
|
|
|
|
end
|
|
|
|
|
2012-01-25 20:58:21 +00:00
|
|
|
function suite.translate_returnsCorrectSeparator_onMixedPath()
|
|
|
|
local actual = path.translate("dir\\dir/file", "/")
|
|
|
|
test.isequal("dir/dir/file", actual)
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
2010-02-27 02:00:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- path.wildcards tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.wildcards_MatchesTrailingStar()
|
|
|
|
local p = path.wildcards("**/xcode/*")
|
|
|
|
test.isequal(".*/xcode/[^/]*", p)
|
|
|
|
end
|
|
|
|
|
2010-03-08 14:57:21 +00:00
|
|
|
function suite.wildcards_MatchPlusSign()
|
|
|
|
local patt = path.wildcards("file+name.*")
|
|
|
|
local name = "file+name.c"
|
|
|
|
test.isequal(name, name:match(patt))
|
|
|
|
end
|
2012-01-20 00:14:18 +00:00
|
|
|
|
|
|
|
function suite.wildcards_escapeSpecialChars()
|
|
|
|
test.isequal("%.%-", path.wildcards(".-"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.wildcards_escapeStar()
|
|
|
|
test.isequal("vs[^/]*", path.wildcards("vs*"))
|
|
|
|
end
|
2013-01-03 16:11:31 +00:00
|
|
|
|
2012-01-20 00:14:18 +00:00
|
|
|
function suite.wildcards_escapeStarStar()
|
|
|
|
test.isequal("Images/.*%.bmp", path.wildcards("Images/**.bmp"))
|
|
|
|
end
|