From 098fe3c52f1d400301124f5084b1972d57fd62d7 Mon Sep 17 00:00:00 2001 From: George Roman <george.roman.99@gmail.com> Date: Thu, 19 Jul 2018 13:11:11 +0300 Subject: Tests: use more fixtures in the build tests --- spec/build_spec.lua | 130 ++++++++++++++++++++++++++-------- spec/fixtures/with_dep-0.1-1.rockspec | 18 ----- spec/fixtures/with_dep.lua | 6 -- 3 files changed, 101 insertions(+), 53 deletions(-) delete mode 100644 spec/fixtures/with_dep-0.1-1.rockspec delete mode 100644 spec/fixtures/with_dep.lua diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 0aaa6d63..707ab145 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -19,12 +19,9 @@ local extra_rocks = { "/lpeg-1.0.0-1.rockspec", "/lpeg-1.0.0-1.src.rock", "/luafilesystem-1.6.3-1.src.rock", - "/lualogging-1.3.0-1.src.rock", "/luasec-0.6-1.rockspec", "/luasocket-3.0rc1-2.src.rock", "/luasocket-3.0rc1-2.rockspec", - "/lxsh-0.8.6-2.src.rock", - "/lxsh-0.8.6-2.rockspec", "/stdlib-41.0.0-1.src.rock", "/validate-args-1.5.4-1.rockspec" } @@ -135,17 +132,17 @@ describe("LuaRocks build tests #integration", function() assert.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) end) - it("LuaRocks build lpeg only-sources example", function() - assert.is_true(run.luarocks_bool("download --rockspec lpeg")) - assert.is_false(run.luarocks_bool("build --only-sources=\"http://example.com\" lpeg-1.0.0-1.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) + it("LuaRocks build with --only-sources", function() + assert.is_true(run.luarocks_bool("download --server=" .. testing_paths.fixtures_dir .. "/a_repo --rockspec a_rock")) + assert.is_false(run.luarocks_bool("build --only-sources=\"http://example.com\" a_rock-1.0-1.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) - assert.is_true(run.luarocks_bool("download --source lpeg")) - assert.is_true(run.luarocks_bool("build --only-sources=\"http://example.com\" lpeg-1.0.0-1.src.rock")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) + assert.is_true(run.luarocks_bool("download --server=" .. testing_paths.fixtures_dir .. "/a_repo --source a_rock")) + assert.is_true(run.luarocks_bool("build --only-sources=\"http://example.com\" a_rock-1.0-1.src.rock")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) - assert.is_true(os.remove("lpeg-1.0.0-1.rockspec")) - assert.is_true(os.remove("lpeg-1.0.0-1.src.rock")) + assert.is_true(os.remove("a_rock-1.0-1.rockspec")) + assert.is_true(os.remove("a_rock-1.0-1.src.rock")) end) it("LuaRocks build fails if an empty tree is given", function() @@ -201,9 +198,35 @@ describe("LuaRocks build tests #integration", function() lfs.rmdir(tmpdir) end) - it("LuaRocks build luasec with skipping dependency checks", function() - assert.is_true(run.luarocks_bool("build luasec 0.6-1 " .. test_env.openssl_dirs .. " --nodeps")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasec/0.6-1/luasec-0.6-1.rockspec")) + it("LuaRocks build with skipping dependency checks", function() + local olddir = lfs.currentdir() + local tmpdir = get_tmp_path() + lfs.mkdir(tmpdir) + lfs.chdir(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_true(run.luarocks_bool("build test-1.0-1.rockspec --deps-mode=none")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) + + lfs.chdir(olddir) + lfs.rmdir(tmpdir) end) it("LuaRocks build lmathx deps partial match", function() @@ -267,22 +290,71 @@ describe("LuaRocks build tests #integration", function() assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasec/0.6-1/luasec-0.6-1.rockspec")) end) - it("LuaRocks build only deps of downloaded rockspec of lxsh", function() - assert.is_true(run.luarocks_bool("download --rockspec lxsh 0.8.6-2")) - assert.is.truthy(run.luarocks("build lxsh-0.8.6-2.rockspec --only-deps")) - assert.is_false(run.luarocks_bool("show lxsh")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is_true(os.remove("lxsh-0.8.6-2.rockspec")) + it("LuaRocks build only deps of a given rockspec", function() + local olddir = lfs.currentdir() + local tmpdir = get_tmp_path() + lfs.mkdir(tmpdir) + lfs.chdir(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("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --only-deps")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) + + lfs.chdir(olddir) + lfs.rmdir(tmpdir) end) - it("LuaRocks build only deps of downloaded rock of lxsh", function() - assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6-2")) - assert.is.truthy(run.luarocks("build lxsh-0.8.6-2.src.rock --only-deps")) - assert.is_false(run.luarocks_bool("show lxsh")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) + pending("LuaRocks build only deps of a given rock", function() + local olddir = lfs.currentdir() + local tmpdir = get_tmp_path() + lfs.mkdir(tmpdir) + lfs.chdir(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("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.src.rock --only-deps")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) + + lfs.chdir(olddir) + lfs.rmdir(tmpdir) end) it("LuaRocks build with https", function() diff --git a/spec/fixtures/with_dep-0.1-1.rockspec b/spec/fixtures/with_dep-0.1-1.rockspec deleted file mode 100644 index 53b26c9d..00000000 --- a/spec/fixtures/with_dep-0.1-1.rockspec +++ /dev/null @@ -1,18 +0,0 @@ -package = "with_dep" -version = "0.1-1" -source = { - url = "http://localhost:8080/file/with_dep.lua" -} -description = { - summary = "An example rockspec", -} -dependencies = { - "lua >= 5.1", - "with_external_dep 0.1", -} -build = { - type = "builtin", - modules = { - with_dep = "with_dep.lua" - } -} diff --git a/spec/fixtures/with_dep.lua b/spec/fixtures/with_dep.lua deleted file mode 100644 index ad7e462a..00000000 --- a/spec/fixtures/with_dep.lua +++ /dev/null @@ -1,6 +0,0 @@ -local pok, with_external_dep = pcall(require, "with_external_dep") -if pok then - print(with_external_dep.foo) -else - print(100) -end -- cgit v1.2.3-55-g6feb