From 129ebf34efa945b2b56a29c80b161414a98757a8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 2 Dec 2019 17:21:20 -0300 Subject: win32: fix split root for quoted absolute path handling --- spec/fs_spec.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'spec') diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua index e3643f78..5d8926c4 100644 --- a/spec/fs_spec.lua +++ b/spec/fs_spec.lua @@ -88,6 +88,40 @@ describe("Luarocks fs test #unit", function() assert.are.same(is_win and [["\\"%" \\\\" \\\\\\"]] or [['\% \\" \\\']], fs.Q([[\% \\" \\\]])) end) end) + + describe("fs.absolute_name", function() + it("unchanged if already absolute", function() + if is_win then + assert.are.same("c:\\foo\\bar", fs.absolute_name("\"c:\\foo\\bar\"")) + assert.are.same("c:\\foo\\bar", fs.absolute_name("c:\\foo\\bar")) + assert.are.same("d:\\foo\\bar", fs.absolute_name("d:\\foo\\bar")) + assert.are.same("\\foo\\bar", fs.absolute_name("\\foo\\bar")) + else + assert.are.same("/foo/bar", fs.absolute_name("/foo/bar")) + end + end) + + it("converts to absolute if relative", function() + local cur = fs.current_dir() + if is_win then + assert.are.same(cur .. "/foo\\bar", fs.absolute_name("\"foo\\bar\"")) + assert.are.same(cur .. "/foo\\bar", fs.absolute_name("foo\\bar")) + else + assert.are.same(cur .. "/foo/bar", fs.absolute_name("foo/bar")) + end + end) + + it("converts a relative to specified base if given", function() + if is_win then + assert.are.same("c:\\bla/foo\\bar", fs.absolute_name("\"foo\\bar\"", "c:\\bla")) + assert.are.same("c:\\bla/foo\\bar", fs.absolute_name("foo\\bar", "c:\\bla")) + assert.are.same("c:\\bla/foo\\bar", fs.absolute_name("foo\\bar", "c:\\bla\\")) + else + assert.are.same("/bla/foo/bar", fs.absolute_name("foo/bar", "/bla")) + assert.are.same("/bla/foo/bar", fs.absolute_name("foo/bar", "/bla/")) + end + end) + end) describe("fs.execute_string", function() local tmpdir -- cgit v1.2.3-55-g6feb