aboutsummaryrefslogtreecommitdiff
path: root/spec/fs_spec.lua
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2024-02-20 13:43:44 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-02-23 20:47:09 -0300
commit2c4ff5240bf298fec07749f5984de2f08b8736ec (patch)
treef0b4dfec401fa1a132fc5786467fb8683d17bdcb /spec/fs_spec.lua
parent79bd1739d8ca004ddd0b2fa5e24da4a6f4b776fa (diff)
downloadluarocks-2c4ff5240bf298fec07749f5984de2f08b8736ec.tar.gz
luarocks-2c4ff5240bf298fec07749f5984de2f08b8736ec.tar.bz2
luarocks-2c4ff5240bf298fec07749f5984de2f08b8736ec.zip
fix: better normalization for paths and slashes
Fixes #1195.
Diffstat (limited to 'spec/fs_spec.lua')
-rw-r--r--spec/fs_spec.lua31
1 files changed, 16 insertions, 15 deletions
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua
index cd6e5c13..aea86af3 100644
--- a/spec/fs_spec.lua
+++ b/spec/fs_spec.lua
@@ -11,6 +11,7 @@ local posix_ok = pcall(require, "posix")
11local testing_paths = test_env.testing_paths 11local testing_paths = test_env.testing_paths
12local get_tmp_path = test_env.get_tmp_path 12local get_tmp_path = test_env.get_tmp_path
13local write_file = test_env.write_file 13local write_file = test_env.write_file
14local P = test_env.P
14 15
15-- A chdir that works in both full and minimal mode, setting 16-- A chdir that works in both full and minimal mode, setting
16-- both the real process current dir and the LuaRocks internal stack in minimal mode 17-- both the real process current dir and the LuaRocks internal stack in minimal mode
@@ -92,33 +93,33 @@ describe("luarocks.fs #unit", function()
92 describe("fs.absolute_name", function() 93 describe("fs.absolute_name", function()
93 it("unchanged if already absolute", function() 94 it("unchanged if already absolute", function()
94 if is_win then 95 if is_win then
95 assert.are.same("c:\\foo\\bar", fs.absolute_name("\"c:\\foo\\bar\"")) 96 assert.are.same(P"c:\\foo\\bar", fs.absolute_name("\"c:\\foo\\bar\""))
96 assert.are.same("c:\\foo\\bar", fs.absolute_name("c:\\foo\\bar")) 97 assert.are.same(P"c:\\foo\\bar", fs.absolute_name("c:\\foo\\bar"))
97 assert.are.same("d:\\foo\\bar", fs.absolute_name("d:\\foo\\bar")) 98 assert.are.same(P"d:\\foo\\bar", fs.absolute_name("d:\\foo\\bar"))
98 assert.are.same("\\foo\\bar", fs.absolute_name("\\foo\\bar")) 99 assert.are.same(P"\\foo\\bar", fs.absolute_name("\\foo\\bar"))
99 else 100 else
100 assert.are.same("/foo/bar", fs.absolute_name("/foo/bar")) 101 assert.are.same(P"/foo/bar", fs.absolute_name("/foo/bar"))
101 end 102 end
102 end) 103 end)
103 104
104 it("converts to absolute if relative", function() 105 it("converts to absolute if relative", function()
105 local cur = fs.current_dir() 106 local cur = fs.current_dir()
106 if is_win then 107 if is_win then
107 assert.are.same(cur .. "/foo\\bar", fs.absolute_name("\"foo\\bar\"")) 108 assert.are.same(P(cur .. "/foo\\bar"), fs.absolute_name("\"foo\\bar\""))
108 assert.are.same(cur .. "/foo\\bar", fs.absolute_name("foo\\bar")) 109 assert.are.same(P(cur .. "/foo\\bar"), fs.absolute_name("foo\\bar"))
109 else 110 else
110 assert.are.same(cur .. "/foo/bar", fs.absolute_name("foo/bar")) 111 assert.are.same(P(cur .. "/foo/bar"), fs.absolute_name("foo/bar"))
111 end 112 end
112 end) 113 end)
113 114
114 it("converts a relative to specified base if given", function() 115 it("converts a relative to specified base if given", function()
115 if is_win then 116 if is_win then
116 assert.are.same("c:\\bla/foo\\bar", fs.absolute_name("\"foo\\bar\"", "c:\\bla")) 117 assert.are.same(P"c:\\bla/foo\\bar", fs.absolute_name("\"foo\\bar\"", "c:\\bla"))
117 assert.are.same("c:\\bla/foo\\bar", fs.absolute_name("foo\\bar", "c:\\bla")) 118 assert.are.same(P"c:\\bla/foo\\bar", fs.absolute_name("foo/bar", "c:\\bla"))
118 assert.are.same("c:\\bla/foo\\bar", fs.absolute_name("foo\\bar", "c:\\bla\\")) 119 assert.are.same(P"c:\\bla/foo\\bar", fs.absolute_name("foo\\bar", "c:\\bla\\"))
119 else 120 else
120 assert.are.same("/bla/foo/bar", fs.absolute_name("foo/bar", "/bla")) 121 assert.are.same(P"/bla/foo/bar", fs.absolute_name("foo/bar", "/bla"))
121 assert.are.same("/bla/foo/bar", fs.absolute_name("foo/bar", "/bla/")) 122 assert.are.same(P"/bla/foo/bar", fs.absolute_name("foo/bar", "/bla/"))
122 end 123 end
123 end) 124 end)
124 end) 125 end)
@@ -619,9 +620,9 @@ describe("luarocks.fs #unit", function()
619 assert.truthy(fs.change_dir_to_root()) 620 assert.truthy(fs.change_dir_to_root())
620 if is_win then 621 if is_win then
621 local curr_dir = fs.current_dir() 622 local curr_dir = fs.current_dir()
622 assert.truthy(curr_dir == "C:\\" or curr_dir == "/") 623 assert.truthy(curr_dir == "C:\\" or curr_dir == P"/")
623 else 624 else
624 assert.same("/", fs.current_dir()) 625 assert.same(P"/", fs.current_dir())
625 end 626 end
626 end) 627 end)
627 628