From dcaca50d670b3f5654c109339b6f37c766558eb1 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 20 Mar 2021 23:44:27 -0300 Subject: fix: pack: rockspec with a bare file in the url --- spec/dir_spec.lua | 10 ++++++++++ spec/fetch_spec.lua | 21 ++++++++++++++++++-- spec/make_spec.lua | 5 +++-- spec/pack_spec.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 87 insertions(+), 5 deletions(-) (limited to 'spec') 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() describe("dir.normalize", function() it("converts backslashes and removes trailing slashes", function() assert.are.same("/foo/ovo", dir.normalize("\\foo\\ovo\\")) + assert.are.same("c:/some/dir", dir.normalize("c:\\..\\some\\foo\\..\\dir")) assert.are.same("http://example.com/foo/ovo", dir.normalize("http://example.com/foo\\ovo\\")) end) + it("strips unneeded /../ and /./", function() + assert.are.same("/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt")) + assert.are.same("/some/dir/file.txt", dir.normalize("/../../../some/./foo/bar/.././../dir/bla/../file.txt")) + end) + it("respects relative paths", function() + assert.are.same("boo", dir.normalize("./boo")) + assert.are.same("/boo", dir.normalize("/./boo")) + assert.are.same("../../../../boo", dir.normalize("../../../hello/world/../../../boo")) + end) end) 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() end) it("returns the absolute path of the filename argument if the url represents a file", function() - local file = fetch.fetch_url("file://a_rock.lua") - assert.truthy(are_same_files(file, lfs.currentdir() .. "/a_rock.lua")) + test_env.run_in_tmp(function(tmpdir) + write_file("test.lua", "return {}", finally) + + fs.change_dir(tmpdir) + local file, err = fetch.fetch_url("file://test.lua") + assert.truthy(file, err) + assert.truthy(are_same_files(file, lfs.currentdir() .. "/test.lua")) + fs.pop_dir() + end, finally) + end) + + it("fails if local path is invalid and returns a helpful hint for relative paths", function() + test_env.run_in_tmp(function(tmpdir) + write_file("test.lua", "return {}", finally) + + local ok, err = fetch.fetch_url("file://boo.lua") + assert.falsy(ok) + assert.match("note that given path in rockspec is not absolute: file://boo.lua", err) + end, finally) end) 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() end) it("--only-deps", function() - local rockspec = testing_paths.fixtures_dir .. "/build_only_deps-0.1-1.rockspec" + local rockspec = "build_only_deps-0.1-1.rockspec" + local src_rock = testing_paths.fixtures_dir .. "/build_only_deps-0.1-1.src.rock" test_env.remove_dir("build_only_deps-0.1-1/") - assert.is_true(run.luarocks_bool("unpack " .. rockspec)) + assert.is_true(run.luarocks_bool("unpack " .. src_rock)) lfs.chdir("build_only_deps-0.1-1/") assert.is_true(run.luarocks_bool("make " .. rockspec .. " --only-deps")) 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") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths +local write_file = test_env.write_file test_env.unload_luarocks() @@ -80,7 +81,60 @@ describe("luarocks pack #integration", function() assert.is_truthy(lfs.attributes("a_rock-1.0-1.src.rock")) end) - it("fails packing a rockspec into a .src.rock dir if doesn't exist", function() + it("can pack a rockspec with a bare file:// in the url", function() + test_env.run_in_tmp(function(tmpdir) + write_file("test-1.0-1.rockspec", [[ + package = "test" + version = "1.0-1" + source = { + url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" + } + dependencies = { + "a_rock 1.0" + } + build = { + type = "builtin", + modules = { + test = "test.lua" + } + } + ]], finally) + write_file("test.lua", "return {}", finally) + + assert.is.truthy(run.luarocks_bool("pack test-1.0-1.rockspec")) + assert.is.truthy(lfs.attributes("test-1.0-1.src.rock")) + + assert.is.truthy(run.luarocks_bool("unpack test-1.0-1.src.rock")) + assert.is.truthy(lfs.attributes("test-1.0-1/test.lua")) + end, finally) + end) + + it("can pack a rockspec with a bare file:// fails if doesn't exist", function() + test_env.run_in_tmp(function(tmpdir) + write_file("test-1.0-1.rockspec", [[ + package = "test" + version = "1.0-1" + source = { + url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test_doesnt_exist.lua" + } + dependencies = { + "a_rock 1.0" + } + build = { + type = "builtin", + modules = { + test = "test.lua" + } + } + ]], finally) + + assert.is.falsy(run.luarocks_bool("pack test-1.0-1.rockspec")) + assert.is.falsy(lfs.attributes("test-1.0-1.src.rock")) + end, finally) + end) + + + it("fails packing a rockspec into a .src.rock if dir doesn't exist", function() local output = run.luarocks("pack " .. testing_paths.fixtures_dir .. "/bad_pack-0.1-1.rockspec") assert.match("Directory invalid_dir not found", output) assert.is_falsy(lfs.attributes("bad_pack-0.1-1.src.rock")) -- cgit v1.2.3-55-g6feb