From 0e3a09b6ed727533b0a6d545c61fcab5f02b6145 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 24 Jan 2020 19:38:42 -0300 Subject: tests: drop LuaSec dependency on tests, use fixtures instead --- spec/build_spec.lua | 44 ++++++++++++--------------- spec/fixtures/build_only_deps-0.1-1.rockspec | 18 +++++++++++ spec/fixtures/build_only_deps-0.1-1.src.rock | Bin 0 -> 547 bytes spec/fixtures/fixturedep.c | 4 +++ spec/install_spec.lua | 21 ++++++------- spec/pack_spec.lua | 1 - spec/util/test_env.lua | 42 ++++++++++++++----------- 7 files changed, 77 insertions(+), 53 deletions(-) create mode 100644 spec/fixtures/build_only_deps-0.1-1.rockspec create mode 100644 spec/fixtures/build_only_deps-0.1-1.src.rock create mode 100644 spec/fixtures/fixturedep.c (limited to 'spec') diff --git a/spec/build_spec.lua b/spec/build_spec.lua index d64ace4d..14837d89 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -20,11 +20,11 @@ local extra_rocks = { "/lpeg-1.0.0-1.rockspec", "/lpeg-1.0.0-1.src.rock", "/luafilesystem-1.6.3-1.src.rock", - "/luasec-0.6-1.rockspec", "/luasocket-3.0rc1-2.src.rock", "/luasocket-3.0rc1-2.rockspec", "/stdlib-41.0.0-1.src.rock", - "/validate-args-1.5.4-1.rockspec" + "/validate-args-1.5.4-1.rockspec", + "spec/fixtures/a_rock-1.0-1.src.rock", } local c_module_source = [[ @@ -290,10 +290,13 @@ describe("LuaRocks build #integration", function() end) end - it("luasec only deps", function() - assert.is_true(run.luarocks_bool("build luasec " .. test_env.openssl_dirs .. " --only-deps")) - assert.is_false(run.luarocks_bool("show luasec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasec/0.6-1/luasec-0.6-1.rockspec")) + it("only deps", function() + local rockspec = testing_paths.fixtures_dir .. "/build_only_deps-0.1-1.rockspec" + + assert.is_true(run.luarocks_bool("build " .. rockspec .. " --only-deps")) + assert.is_false(run.luarocks_bool("show build_only_deps")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/build_only_deps/0.1-1/build_only_deps-0.1-1.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) end) it("only deps of a given rockspec", function() @@ -351,16 +354,6 @@ describe("LuaRocks build #integration", function() end, finally) end) - it("with https", function() - assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) - assert.is_true(run.luarocks_bool("install luasec " .. test_env.openssl_dirs)) - - assert.is_true(run.luarocks_bool("build validate-args-1.5.4-1.rockspec")) - assert.is.truthy(run.luarocks("show validate-args")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/validate-args/1.5.4-1/validate-args-1.5.4-1.rockspec")) - assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) - end) - it("fails if given an argument with an invalid patch", function() assert.is_false(run.luarocks_bool("build " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec")) end) @@ -899,15 +892,19 @@ describe("LuaRocks build #unit", function() end) it("automatically extracts the modules and libraries if they are not given and builds against any external dependencies", function() - local ssllib = "ssl" + local fdir = testing_paths.fixtures_dir if test_env.TEST_TARGET_OS == "windows" then if test_env.MINGW then - ssllib = "eay32" + os.execute("gcc -shared -o " .. fdir .. "/libfixturedep.dll -Wl,--out-implib," .. fdir .."/libfixturedep.a " .. fdir .. "/fixturedep.c") else - ssllib = "ssleay32" + os.execute("cl " .. fdir .. "\\fixturedep.c /link /export:fixturedep_fn /out:" .. fdir .. "\\fixturedep.dll /implib:" .. fdir .. "\\fixturedep.lib") end + elseif test_env.TEST_TARGET_OS == "linux" then + os.execute("gcc -shared -o " .. fdir .. "/libfixturedep.so " .. fdir .. "/fixturedep.c") + elseif test_env.TEST_TARGET_OS == "osx" then + os.execute("cc -dynamiclib -o " .. fdir .. "/libfixturedep.dylib " .. fdir .. "/fixturedep.c") end - + local rockspec = { rockspec_format = "3.0", package = "c_module", @@ -916,8 +913,8 @@ describe("LuaRocks build #unit", function() url = "http://example.com/c_module" }, external_dependencies = { - OPENSSL = { - library = ssllib -- Use OpenSSL since it is available on all testing platforms + FIXTUREDEP = { + library = "fixturedep" } }, build = { @@ -927,8 +924,7 @@ describe("LuaRocks build #unit", function() write_file("c_module.c", c_module_source, finally) rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) - rockspec.variables["OPENSSL_INCDIR"] = test_env.OPENSSL_INCDIR - rockspec.variables["OPENSSL_LIBDIR"] = test_env.OPENSSL_LIBDIR + rockspec.variables["FIXTUREDEP_LIBDIR"] = testing_paths.fixtures_dir assert.truthy(build_builtin.run(rockspec)) end) diff --git a/spec/fixtures/build_only_deps-0.1-1.rockspec b/spec/fixtures/build_only_deps-0.1-1.rockspec new file mode 100644 index 00000000..02d2b47e --- /dev/null +++ b/spec/fixtures/build_only_deps-0.1-1.rockspec @@ -0,0 +1,18 @@ +package = "build_only_deps" +version = "0.1-1" +source = { + url = "file://./a_rock.lua" +} +description = { + summary = "Fixture to test --only-deps", +} +dependencies = { + "lua >= 5.1", + "a_rock 1.0", +} +build = { + type = "builtin", + modules = { + dummy = "a_rock.lua", + } +} diff --git a/spec/fixtures/build_only_deps-0.1-1.src.rock b/spec/fixtures/build_only_deps-0.1-1.src.rock new file mode 100644 index 00000000..74b2d1e6 Binary files /dev/null and b/spec/fixtures/build_only_deps-0.1-1.src.rock differ diff --git a/spec/fixtures/fixturedep.c b/spec/fixtures/fixturedep.c new file mode 100644 index 00000000..e3fcdd51 --- /dev/null +++ b/spec/fixtures/fixturedep.c @@ -0,0 +1,4 @@ + +int fixturedep_fn() { + return 0; +} diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 7370fef5..5ee913f0 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -12,7 +12,6 @@ local extra_rocks = { "/cprint-0.1-2.src.rock", "/cprint-0.1-2.rockspec", "/lpeg-0.12-1.src.rock", - "/luasec-0.6-1.rockspec", "/luassert-1.7.0-1.src.rock", "/luasocket-3.0rc1-2.src.rock", "/luasocket-3.0rc1-2.rockspec", @@ -25,6 +24,9 @@ local extra_rocks = { "/luafilesystem-1.6.3-1.src.rock", "/sailor-0.5-3.src.rock", "/sailor-0.5-4.src.rock", + "spec/fixtures/a_repo/has_build_dep-1.0-1.all.rock", + "spec/fixtures/a_repo/a_build_dep-1.0-1.all.rock", + "spec/fixtures/a_repo/a_rock-1.0-1.src.rock", } describe("luarocks install #integration", function() @@ -77,8 +79,8 @@ describe("luarocks install #integration", function() end) it("installs a package with a dependency", function() - assert.is_true(run.luarocks_bool("install luasec " .. test_env.openssl_dirs)) - assert.is_true(run.luarocks_bool("show luasocket")) + assert.is_true(run.luarocks_bool("install has_build_dep")) + assert.is_true(run.luarocks_bool("show a_rock")) end) it("installs a package without its documentation", function() @@ -135,14 +137,11 @@ describe("luarocks install #integration", function() end) describe("more complex tests", function() - it('luasec with skipping dependency checks', function() - assert.is_true(run.luarocks_bool("install luasec " .. test_env.openssl_dirs .. " --nodeps")) - assert.is_true(run.luarocks_bool("show luasec")) - if env_variables.TYPE_TEST_ENV == "minimal" then - assert.is_false(run.luarocks_bool(test_env.quiet("show luasocket"))) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasocket")) - end - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasec")) + it('skipping dependency checks', function() + assert.is_true(run.luarocks_bool("install has_build_dep --nodeps")) + assert.is_true(run.luarocks_bool("show has_build_dep")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/has_build_dep")) end) it('handle relative path in --tree #632', function() diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index bea47811..f0c128a3 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -6,7 +6,6 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() local extra_rocks = { - "/luasec-0.6-1.rockspec", "/luassert-1.7.0-1.src.rock", "/luasocket-3.0rc1-2.src.rock", "/luasocket-3.0rc1-2.rockspec", diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index e3aad1b1..d4591c91 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua @@ -263,10 +263,10 @@ function test_env.set_args() if package.config:sub(1,1) == "\\" then test_env.TEST_TARGET_OS = "windows" if test_env.APPVEYOR then - test_env.OPENSSL_INCDIR = "C:\\OpenSSL-Win32\\include" - test_env.OPENSSL_LIBDIR = "C:\\OpenSSL-Win32\\lib" + test_env.OPENSSL_INCDIR = "C:\\OpenSSL-v111-Win32\\include" + test_env.OPENSSL_LIBDIR = "C:\\OpenSSL-v111-Win32\\lib" if test_env.MINGW then - test_env.OPENSSL_LIBDIR = "C:\\OpenSSL-Win32\\bin" + test_env.OPENSSL_LIBDIR = "C:\\OpenSSL-v111-Win32\\bin" end end else @@ -374,27 +374,35 @@ end -- @return make_manifest boolean: true if new rocks downloaded local function download_rocks(urls, save_path) local luarocks_repo = "https://luarocks.org/" - local any_downloads = false local to_download = {} + local fixtures = {} for _, url in ipairs(urls) do - -- check if already downloaded - if not test_env.exists(save_path .. "/" .. url) then - table.insert(to_download, luarocks_repo .. url) - any_downloads = true + if url:match("^spec/fixtures") then + table.insert(fixtures, (url:gsub("^spec/fixtures", test_env.testing_paths.fixtures_dir))) + else + -- check if already downloaded + if not test_env.exists(save_path .. "/" .. url) then + table.insert(to_download, luarocks_repo .. url) + end end end - if not any_downloads then - return false + + if #fixtures > 0 then + os.execute("cp " .. table.concat(fixtures, " ") .. " " .. save_path) end - local cmd - if test_env.TEST_TARGET_OS == "windows" then - cmd = test_env.testing_paths.win_tools .. "/wget --no-check-certificate -cP " .. save_path - else - cmd = "wget -cP " .. save_path + + if #to_download > 0 then + local cmd + if test_env.TEST_TARGET_OS == "windows" then + cmd = test_env.testing_paths.win_tools .. "/wget --no-check-certificate -cP " .. save_path + else + cmd = "wget -cP " .. save_path + end + assert(execute_bool(cmd.." "..table.concat(to_download, " "))) end - assert(execute_bool(cmd.." "..table.concat(to_download, " "))) - return true + + return (#fixtures > 0) or (#to_download > 0) end --- Create a file containing a string. -- cgit v1.2.3-55-g6feb