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.
|
|
|
|
-- Copyright (c) 2008,2009 Jason Perkins and the Premake project
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
T.path = { }
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- path.getabsolute() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.getabsolute_ReturnsCorrectPath_OnMissingSubdir()
|
|
|
|
local expected = path.translate(os.getcwd(), "/") .. "/a/b/c"
|
|
|
|
test.isequal(expected, path.getabsolute("a/b/c"))
|
|
|
|
end
|
|
|
|
|
2008-12-05 21:18:47 +00:00
|
|
|
function T.path.getabsolute_RemovesDotDots_OnWindowsAbsolute()
|
|
|
|
test.isequal("c:/ProjectB/bin", path.getabsolute("c:/ProjectA/../ProjectB/bin"))
|
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2008-12-05 21:18:47 +00:00
|
|
|
function T.path.getabsolute_RemovesDotDots_OnPosixAbsolute()
|
|
|
|
test.isequal("/ProjectB/bin", path.getabsolute("/ProjectA/../ProjectB/bin"))
|
|
|
|
end
|
|
|
|
|
2009-05-29 19:07:35 +00:00
|
|
|
function T.path.getabsolute_OnTrailingSlash()
|
|
|
|
local expected = path.translate(os.getcwd(), "/") .. "/a/b/c"
|
|
|
|
test.isequal(expected, path.getabsolute("a/b/c/"))
|
|
|
|
end
|
|
|
|
|
2008-12-05 21:18:47 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- path.getbasename() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.getbasename_ReturnsCorrectName_OnDirAndExtension()
|
|
|
|
test.isequal("filename", path.getbasename("folder/filename.ext"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- path.getdirectory() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.getdirectory_ReturnsEmptyString_OnNoDirectory()
|
|
|
|
test.isequal(".", path.getdirectory("filename.ext"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.getdirectory_ReturnsDirectory_OnSingleLevelPath()
|
|
|
|
test.isequal("dir0", path.getdirectory("dir0/filename.ext"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.getdirectory_ReturnsDirectory_OnMultiLeveLPath()
|
|
|
|
test.isequal("dir0/dir1/dir2", path.getdirectory("dir0/dir1/dir2/filename.ext"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.getdirectory_ReturnsRootPath_OnRootPathOnly()
|
|
|
|
test.isequal("/", path.getdirectory("/filename.ext"))
|
|
|
|
end
|
2008-12-05 21:18:47 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
|
2009-01-05 15:40:05 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- path.getdrive() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.getdrive_ReturnsNil_OnNotWindows()
|
|
|
|
test.isnil(path.getdrive("/hello"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.getdrive_ReturnsLetter_OnWindowsAbsolute()
|
|
|
|
test.isequal("x", path.getdrive("x:/hello"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- path.getextension() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.getextension_ReturnsEmptyString_OnNoExtension()
|
|
|
|
test.isequal("", path.getextension("filename"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.getextension_ReturnsExtension()
|
|
|
|
test.isequal(".txt", path.getextension("filename.txt"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.getextension_OnMultipleDots()
|
|
|
|
test.isequal(".txt", path.getextension("filename.mod.txt"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- path.getrelative() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.getrelative_ReturnsDot_OnMatchingPaths()
|
|
|
|
test.isequal(".", path.getrelative("/a/b/c", "/a/b/c"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.getrelative_ReturnsDoubleDot_OnChildToParent()
|
|
|
|
test.isequal("..", path.getrelative("/a/b/c", "/a/b"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.getrelative_ReturnsDoubleDot_OnSiblingToSibling()
|
|
|
|
test.isequal("../d", path.getrelative("/a/b/c", "/a/b/d"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.getrelative_ReturnsChildPath_OnParentToChild()
|
|
|
|
test.isequal("d", path.getrelative("/a/b/c", "/a/b/c/d"))
|
|
|
|
end
|
|
|
|
|
2008-12-15 15:00:35 +00:00
|
|
|
function T.path.getrelative_ReturnsChildPath_OnWindowsAbsolute()
|
|
|
|
test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug"))
|
|
|
|
end
|
|
|
|
|
2009-01-05 15:40:05 +00:00
|
|
|
function T.path.getrelative_ReturnsAbsPath_OnDifferentDriveLetters()
|
|
|
|
test.isequal("D:/Files", path.getrelative("C:/Code/Premake4", "D:/Files"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- path.isabsolute() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.isabsolute_ReturnsTrue_OnAbsolutePosixPath()
|
|
|
|
test.istrue(path.isabsolute("/a/b/c"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.isabsolute_ReturnsTrue_OnAbsoluteWindowsPathWithDrive()
|
|
|
|
test.istrue(path.isabsolute("C:/a/b/c"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.isabsolute_ReturnsFalse_OnRelativePath()
|
|
|
|
test.isfalse(path.isabsolute("a/b/c"))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- path.join() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.join_OnValidParts()
|
|
|
|
test.isequal("leading/trailing", path.join("leading", "trailing"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.join_OnAbsoluteUnixPath()
|
|
|
|
test.isequal("/trailing", path.join("leading", "/trailing"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.join_OnAbsoluteWindowsPath()
|
|
|
|
test.isequal("C:/trailing", path.join("leading", "C:/trailing"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.join_OnCurrentDirectory()
|
|
|
|
test.isequal("trailing", path.join(".", "trailing"))
|
|
|
|
end
|
|
|
|
|
2009-09-29 19:27:33 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- path.rebase() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.rebase_WithEndingSlashOnPath()
|
|
|
|
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
|
|
|
|
--
|
|
|
|
|
|
|
|
function T.path.translate_ReturnsTranslatedPath_OnValidPath()
|
|
|
|
test.isequal("dir/dir/file", path.translate("dir\\dir\\file", "/"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function T.path.translate_ReturnsCorrectSeparator_OnMixedPath()
|
|
|
|
local actual = path.translate("dir\\dir/file")
|
2008-11-13 00:54:41 +00:00
|
|
|
if (os.is("windows")) then
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal("dir\\dir\\file", actual)
|
|
|
|
else
|
|
|
|
test.isequal("dir/dir/file", actual)
|
|
|
|
end
|
|
|
|
end
|