Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt1
-rw-r--r--src/base/path.lua45
-rw-r--r--tests/actions/test_clean.lua1
-rw-r--r--tests/base/test_path.lua30
4 files changed, 52 insertions, 25 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 0c30308..1bae7bd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -52,6 +52,7 @@
* Patch 3451212: Fix Visual Studio MFC with StaticRuntime
* Patch 3463020: Add windres environment variable for makefiles (icebreaker)
* Bug 3413866: Incorrect VS200x .csproj relative source paths
+* Patch 3111264: Allow path.join() to accept any number of args
-------
diff --git a/src/base/path.lua b/src/base/path.lua
index 95a1102..14d00f6 100644
--- a/src/base/path.lua
+++ b/src/base/path.lua
@@ -217,34 +217,41 @@
return table.contains(extensions, ext)
end
-
--
--- Join two pieces of a path together into a single path.
+-- Join one or more pieces of a path together into a single path.
+--
+-- @param ...
+-- One or more path strings.
+-- @return
+-- The joined path.
--
- function path.join(leading, trailing)
- leading = leading or ""
-
- if (not trailing) then
- return leading
- end
-
- if (path.isabsolute(trailing)) then
- return trailing
- end
-
- if (leading == ".") then
- leading = ""
+ function path.join(...)
+ local numargs = select("#", ...)
+ if numargs == 0 then
+ return "";
end
- if (leading:len() > 0 and not leading:endswith("/")) then
- leading = leading .. "/"
+ local allparts = {}
+ for i = numargs, 1, -1 do
+ local part = select(i, ...)
+ if part and #part > 0 and part ~= "." then
+ -- trim off trailing slashes
+ while part:endswith("/") do
+ part = part:sub(1, -2)
+ end
+
+ table.insert(allparts, 1, part)
+ if path.isabsolute(part) then
+ break
+ end
+ end
end
- return leading .. trailing
+ return table.concat(allparts, "/")
end
-
+
--
-- Takes a path which is relative to one location and makes it relative
diff --git a/tests/actions/test_clean.lua b/tests/actions/test_clean.lua
index bcea777..f0badbc 100644
--- a/tests/actions/test_clean.lua
+++ b/tests/actions/test_clean.lua
@@ -106,7 +106,6 @@
language "C++"
kind "ConsoleApp"
prepare()
- test.contains(removed, "obj")
test.contains(removed, "obj/Debug")
test.contains(removed, "obj/Release")
end
diff --git a/tests/base/test_path.lua b/tests/base/test_path.lua
index c2b153f..2332dce 100644
--- a/tests/base/test_path.lua
+++ b/tests/base/test_path.lua
@@ -182,23 +182,43 @@
--
function suite.join_OnValidParts()
- test.isequal("leading/trailing", path.join("leading", "trailing"))
+ test.isequal("p1/p2", path.join("p1", "p2"))
end
function suite.join_OnAbsoluteUnixPath()
- test.isequal("/trailing", path.join("leading", "/trailing"))
+ test.isequal("/p2", path.join("p1", "/p2"))
end
function suite.join_OnAbsoluteWindowsPath()
- test.isequal("C:/trailing", path.join("leading", "C:/trailing"))
+ test.isequal("C:/p2", path.join("p1", "C:/p2"))
end
function suite.join_OnCurrentDirectory()
- test.isequal("trailing", path.join(".", "trailing"))
+ test.isequal("p2", path.join(".", "p2"))
end
function suite.join_OnNilSecondPart()
- test.isequal("leading", path.join("leading", nil))
+ test.isequal("p1", path.join("p1", nil))
+ end
+
+ 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", ""))
end