From 96b6b9ca9cf77922863d440247850b6b7c4bb9ae Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 2 Sep 2019 14:32:54 -0300 Subject: build: fix --branch flag The `--branch` flag is optional and takes a string argument. The `--branch` flag does not make sense for `luarocks make` because it does not fetch sources, it builds/installs based on whatever is in the current directory. This also adds tests that verify the behavior, but these don't run in Travis CI because of issues running a Git daemon there. They were verified locally. --- spec/build_spec.lua | 35 +++++++++++++++++++++++++++++------ spec/install_spec.lua | 29 ++++++++++++++++++++++++++++- spec/util/git_repo.lua | 1 + 3 files changed, 58 insertions(+), 7 deletions(-) (limited to 'spec') diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 41c169d9..f0377b5f 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -4,6 +4,7 @@ local get_tmp_path = test_env.get_tmp_path local run = test_env.run local testing_paths = test_env.testing_paths local write_file = test_env.write_file +local git_repo = require("spec.util.git_repo") test_env.unload_luarocks() local cfg = require("luarocks.core.cfg") @@ -109,12 +110,6 @@ describe("LuaRocks build tests #integration", function() end, finally) end) - it("LuaRocks build lpeg branch=master", function() - -- FIXME should use dev package - assert.is_true(run.luarocks_bool("build --branch=master lpeg")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - end) - it("LuaRocks build fails if the deps-mode argument is invalid", function() assert.is_false(run.luarocks_bool("build --deps-mode=123 " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec")) assert.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) @@ -928,5 +923,33 @@ describe("LuaRocks build tests #unit", function() end) end) end) + + describe("#unix build from #git", function() + local git + + setup(function() + git = git_repo.start() + end) + + teardown(function() + if git then + git:stop() + end + end) + + it("using --branch", function() + write_file("my_branch-1.0-1.rockspec", [[ + rockspec_format = "3.0" + package = "my_branch" + version = "1.0-1" + source = { + url = "git://localhost/testrock" + } + ]], finally) + assert.is_false(run.luarocks_bool("build --branch unknown-branch ./my_branch-1.0-1.rockspec")) + assert.is_true(run.luarocks_bool("build --branch test-branch ./my_branch-1.0-1.rockspec")) + end) + end) + end) diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 77ac6225..3b0b22fb 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -3,8 +3,8 @@ local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths local env_variables = test_env.env_variables -local get_tmp_path = test_env.get_tmp_path local write_file = test_env.write_file +local git_repo = require("spec.util.git_repo") test_env.unload_luarocks() @@ -234,4 +234,31 @@ describe("luarocks install #integration", function() end) end) + describe("#unix install runs build from #git", function() + local git + + setup(function() + git = git_repo.start() + end) + + teardown(function() + if git then + git:stop() + end + end) + + it("using --branch", function() + write_file("my_branch-1.0-1.rockspec", [[ + rockspec_format = "3.0" + package = "my_branch" + version = "1.0-1" + source = { + url = "git://localhost/testrock" + } + ]], finally) + assert.is_false(run.luarocks_bool("install --branch unknown-branch ./my_branch-1.0-1.rockspec")) + assert.is_true(run.luarocks_bool("install --branch test-branch ./my_branch-1.0-1.rockspec")) + end) + end) + end) diff --git a/spec/util/git_repo.lua b/spec/util/git_repo.lua index 6cccfcc4..b3ddd9ef 100644 --- a/spec/util/git_repo.lua +++ b/spec/util/git_repo.lua @@ -82,6 +82,7 @@ function git_repo.start() test_env.execute("git add " .. name) end assert(test_env.execute("git commit -a -m 'initial commit'")) + assert(test_env.execute("git branch test-branch")) print("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &") assert(test_env.execute("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &")) assert(test_env.execute("sleep 0.1; netstat -ln | grep '0.0.0.0:9418 .* LISTEN'")) -- cgit v1.2.3-55-g6feb