diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2021-03-20 23:44:27 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2021-03-22 10:33:10 -0300 |
commit | dcaca50d670b3f5654c109339b6f37c766558eb1 (patch) | |
tree | 638faf5df7570aa874bafdb4179d00f18f410bac /spec | |
parent | fbd857e1a0b2aae5beb3875427612e41bf67b35e (diff) | |
download | luarocks-dcaca50d670b3f5654c109339b6f37c766558eb1.tar.gz luarocks-dcaca50d670b3f5654c109339b6f37c766558eb1.tar.bz2 luarocks-dcaca50d670b3f5654c109339b6f37c766558eb1.zip |
fix: pack: rockspec with a bare file in the url
Diffstat (limited to 'spec')
-rw-r--r-- | spec/dir_spec.lua | 10 | ||||
-rw-r--r-- | spec/fetch_spec.lua | 21 | ||||
-rw-r--r-- | spec/make_spec.lua | 5 | ||||
-rw-r--r-- | spec/pack_spec.lua | 56 |
4 files changed, 87 insertions, 5 deletions
diff --git a/spec/dir_spec.lua b/spec/dir_spec.lua index 1b568c8f..9f05c664 100644 --- a/spec/dir_spec.lua +++ b/spec/dir_spec.lua | |||
@@ -46,8 +46,18 @@ describe("luarocks.dir #unit", function() | |||
46 | describe("dir.normalize", function() | 46 | describe("dir.normalize", function() |
47 | it("converts backslashes and removes trailing slashes", function() | 47 | it("converts backslashes and removes trailing slashes", function() |
48 | assert.are.same("/foo/ovo", dir.normalize("\\foo\\ovo\\")) | 48 | assert.are.same("/foo/ovo", dir.normalize("\\foo\\ovo\\")) |
49 | assert.are.same("c:/some/dir", dir.normalize("c:\\..\\some\\foo\\..\\dir")) | ||
49 | assert.are.same("http://example.com/foo/ovo", dir.normalize("http://example.com/foo\\ovo\\")) | 50 | assert.are.same("http://example.com/foo/ovo", dir.normalize("http://example.com/foo\\ovo\\")) |
50 | end) | 51 | end) |
52 | it("strips unneeded /../ and /./", function() | ||
53 | assert.are.same("/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt")) | ||
54 | assert.are.same("/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt")) | ||
55 | end) | ||
56 | it("respects relative paths", function() | ||
57 | assert.are.same("boo", dir.normalize("./boo")) | ||
58 | assert.are.same("/boo", dir.normalize("/./boo")) | ||
59 | assert.are.same("../../../../boo", dir.normalize("../../../hello/world/../../../boo")) | ||
60 | end) | ||
51 | end) | 61 | end) |
52 | 62 | ||
53 | end) | 63 | end) |
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index 8194a298..008a91c8 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua | |||
@@ -52,8 +52,25 @@ describe("luarocks fetch #unit #mock", function() | |||
52 | end) | 52 | end) |
53 | 53 | ||
54 | it("returns the absolute path of the filename argument if the url represents a file", function() | 54 | it("returns the absolute path of the filename argument if the url represents a file", function() |
55 | local file = fetch.fetch_url("file://a_rock.lua") | 55 | test_env.run_in_tmp(function(tmpdir) |
56 | assert.truthy(are_same_files(file, lfs.currentdir() .. "/a_rock.lua")) | 56 | write_file("test.lua", "return {}", finally) |
57 | |||
58 | fs.change_dir(tmpdir) | ||
59 | local file, err = fetch.fetch_url("file://test.lua") | ||
60 | assert.truthy(file, err) | ||
61 | assert.truthy(are_same_files(file, lfs.currentdir() .. "/test.lua")) | ||
62 | fs.pop_dir() | ||
63 | end, finally) | ||
64 | end) | ||
65 | |||
66 | it("fails if local path is invalid and returns a helpful hint for relative paths", function() | ||
67 | test_env.run_in_tmp(function(tmpdir) | ||
68 | write_file("test.lua", "return {}", finally) | ||
69 | |||
70 | local ok, err = fetch.fetch_url("file://boo.lua") | ||
71 | assert.falsy(ok) | ||
72 | assert.match("note that given path in rockspec is not absolute: file://boo.lua", err) | ||
73 | end, finally) | ||
57 | end) | 74 | end) |
58 | 75 | ||
59 | it("returns false and does nothing if the url argument contains a nonexistent file", function() | 76 | it("returns false and does nothing if the url argument contains a nonexistent file", function() |
diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 791eeb89..e14eb66b 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua | |||
@@ -67,10 +67,11 @@ describe("luarocks make #integration", function() | |||
67 | end) | 67 | end) |
68 | 68 | ||
69 | it("--only-deps", function() | 69 | it("--only-deps", function() |
70 | local rockspec = testing_paths.fixtures_dir .. "/build_only_deps-0.1-1.rockspec" | 70 | local rockspec = "build_only_deps-0.1-1.rockspec" |
71 | local src_rock = testing_paths.fixtures_dir .. "/build_only_deps-0.1-1.src.rock" | ||
71 | 72 | ||
72 | test_env.remove_dir("build_only_deps-0.1-1/") | 73 | test_env.remove_dir("build_only_deps-0.1-1/") |
73 | assert.is_true(run.luarocks_bool("unpack " .. rockspec)) | 74 | assert.is_true(run.luarocks_bool("unpack " .. src_rock)) |
74 | lfs.chdir("build_only_deps-0.1-1/") | 75 | lfs.chdir("build_only_deps-0.1-1/") |
75 | assert.is_true(run.luarocks_bool("make " .. rockspec .. " --only-deps")) | 76 | assert.is_true(run.luarocks_bool("make " .. rockspec .. " --only-deps")) |
76 | assert.is_false(run.luarocks_bool("show build_only_deps")) | 77 | assert.is_false(run.luarocks_bool("show build_only_deps")) |
diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 55071839..beab7e8a 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua | |||
@@ -2,6 +2,7 @@ local test_env = require("spec.util.test_env") | |||
2 | local lfs = require("lfs") | 2 | local lfs = require("lfs") |
3 | local run = test_env.run | 3 | local run = test_env.run |
4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
5 | local write_file = test_env.write_file | ||
5 | 6 | ||
6 | test_env.unload_luarocks() | 7 | test_env.unload_luarocks() |
7 | 8 | ||
@@ -80,7 +81,60 @@ describe("luarocks pack #integration", function() | |||
80 | assert.is_truthy(lfs.attributes("a_rock-1.0-1.src.rock")) | 81 | assert.is_truthy(lfs.attributes("a_rock-1.0-1.src.rock")) |
81 | end) | 82 | end) |
82 | 83 | ||
83 | it("fails packing a rockspec into a .src.rock dir if doesn't exist", function() | 84 | it("can pack a rockspec with a bare file:// in the url", function() |
85 | test_env.run_in_tmp(function(tmpdir) | ||
86 | write_file("test-1.0-1.rockspec", [[ | ||
87 | package = "test" | ||
88 | version = "1.0-1" | ||
89 | source = { | ||
90 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
91 | } | ||
92 | dependencies = { | ||
93 | "a_rock 1.0" | ||
94 | } | ||
95 | build = { | ||
96 | type = "builtin", | ||
97 | modules = { | ||
98 | test = "test.lua" | ||
99 | } | ||
100 | } | ||
101 | ]], finally) | ||
102 | write_file("test.lua", "return {}", finally) | ||
103 | |||
104 | assert.is.truthy(run.luarocks_bool("pack test-1.0-1.rockspec")) | ||
105 | assert.is.truthy(lfs.attributes("test-1.0-1.src.rock")) | ||
106 | |||
107 | assert.is.truthy(run.luarocks_bool("unpack test-1.0-1.src.rock")) | ||
108 | assert.is.truthy(lfs.attributes("test-1.0-1/test.lua")) | ||
109 | end, finally) | ||
110 | end) | ||
111 | |||
112 | it("can pack a rockspec with a bare file:// fails if doesn't exist", function() | ||
113 | test_env.run_in_tmp(function(tmpdir) | ||
114 | write_file("test-1.0-1.rockspec", [[ | ||
115 | package = "test" | ||
116 | version = "1.0-1" | ||
117 | source = { | ||
118 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test_doesnt_exist.lua" | ||
119 | } | ||
120 | dependencies = { | ||
121 | "a_rock 1.0" | ||
122 | } | ||
123 | build = { | ||
124 | type = "builtin", | ||
125 | modules = { | ||
126 | test = "test.lua" | ||
127 | } | ||
128 | } | ||
129 | ]], finally) | ||
130 | |||
131 | assert.is.falsy(run.luarocks_bool("pack test-1.0-1.rockspec")) | ||
132 | assert.is.falsy(lfs.attributes("test-1.0-1.src.rock")) | ||
133 | end, finally) | ||
134 | end) | ||
135 | |||
136 | |||
137 | it("fails packing a rockspec into a .src.rock if dir doesn't exist", function() | ||
84 | local output = run.luarocks("pack " .. testing_paths.fixtures_dir .. "/bad_pack-0.1-1.rockspec") | 138 | local output = run.luarocks("pack " .. testing_paths.fixtures_dir .. "/bad_pack-0.1-1.rockspec") |
85 | assert.match("Directory invalid_dir not found", output) | 139 | assert.match("Directory invalid_dir not found", output) |
86 | assert.is_falsy(lfs.attributes("bad_pack-0.1-1.src.rock")) | 140 | assert.is_falsy(lfs.attributes("bad_pack-0.1-1.src.rock")) |