From d80124af9cd929b395b4d4c353b51ccc902a3f9e Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 8 Jan 2018 16:26:48 -0200 Subject: Reorganize test suite files --- .busted | 2 +- spec/add_spec.lua | 4 +- spec/build_spec.lua | 12 +- spec/config_spec.lua | 2 +- spec/deps_spec.lua | 2 +- spec/doc_spec.lua | 2 +- spec/download_spec.lua | 2 +- spec/fetch_spec.lua | 2 +- spec/fixtures/a_rock-1.0-1.rockspec | 17 + spec/fixtures/a_rock.lua | 1 + spec/fixtures/invalid_patch-0.1-1.rockspec | 29 + .../invalid_validate-args-1.5.4-1.rockspec | 35 + spec/fixtures/luajit-fail-1.0-1.rockspec | 22 + spec/fixtures/luajit-success-1.0-1.rockspec | 23 + spec/fixtures/missing_external-0.1-1.rockspec | 24 + spec/fixtures/mixed_deploy_type/mdt.c | 6 + spec/fixtures/mixed_deploy_type/mdt.lua | 1 + spec/fixtures/mixed_deploy_type/mdt_file | 1 + .../mixed_deploy_type-0.1.0-1.rockspec | 21 + .../mixed_deploy_type-0.2.0-1.rockspec | 21 + spec/fixtures/no_build_table-0.1-1.rockspec | 12 + spec/fixtures/not_a_zipfile-1.0-1.src.rock | 1 + spec/fixtures/patch_create_delete-0.1-1.rockspec | 34 + spec/fixtures/patch_create_delete/a_file.txt | 1 + spec/fixtures/type_mismatch_string-1.0-1.rockspec | 4 + spec/fixtures/type_mismatch_table-1.0-1.rockspec | 5 + spec/fixtures/type_mismatch_version-1.0-1.rockspec | 4 + spec/fixtures/with_external_dep-0.1-1.rockspec | 25 + spec/fixtures/with_external_dep.c | 10 + spec/fixtures/with_external_dep/foo/foo.h | 1 + spec/fixtures/with_external_dep/foo/foo.h.gch | Bin 0 -> 1503664 bytes spec/fs_spec.lua | 2 +- spec/help_spec.lua | 2 +- spec/install_spec.lua | 6 +- spec/lint_spec.lua | 10 +- spec/list_spec.lua | 2 +- spec/make_manifest_spec.lua | 2 +- spec/make_spec.lua | 4 +- spec/new_version_spec.lua | 2 +- spec/pack_spec.lua | 4 +- spec/path_spec.lua | 2 +- spec/persist.lua | 2 +- spec/purge_spec.lua | 2 +- spec/refresh_cache_spec.lua | 2 +- spec/remove_spec.lua | 2 +- spec/search_spec.lua | 2 +- spec/show_spec.lua | 2 +- spec/unpack_spec.lua | 4 +- spec/upload_spec.lua | 6 +- spec/util/mock-server.lua | 97 +++ spec/util/test_env.lua | 795 +++++++++++++++++++++ spec/util_spec.lua | 2 +- spec/write_rockspec_spec.lua | 26 +- test/luarocks_site.lua | 6 - test/mock-server.lua | 97 --- test/test_environment.lua | 781 -------------------- test/testfiles/a_rock-1.0-1.rockspec | 17 - test/testfiles/a_rock.lua | 1 - test/testfiles/invalid_patch-0.1-1.rockspec | 29 - .../invalid_validate-args-1.5.4-1.rockspec | 35 - test/testfiles/luajit-fail-1.0-1.rockspec | 22 - test/testfiles/luajit-success-1.0-1.rockspec | 23 - test/testfiles/missing_external-0.1-1.rockspec | 24 - test/testfiles/mixed_deploy_type/mdt.c | 6 - test/testfiles/mixed_deploy_type/mdt.lua | 1 - test/testfiles/mixed_deploy_type/mdt_file | 1 - .../mixed_deploy_type-0.1.0-1.rockspec | 21 - .../mixed_deploy_type-0.2.0-1.rockspec | 21 - test/testfiles/no_build_table-0.1-1.rockspec | 12 - test/testfiles/not_a_zipfile-1.0-1.src.rock | 1 - test/testfiles/patch_create_delete-0.1-1.rockspec | 34 - test/testfiles/patch_create_delete/a_file.txt | 1 - test/testfiles/type_mismatch_string-1.0-1.rockspec | 4 - test/testfiles/type_mismatch_table-1.0-1.rockspec | 5 - .../testfiles/type_mismatch_version-1.0-1.rockspec | 4 - test/testfiles/with_external_dep-0.1-1.rockspec | 25 - test/testfiles/with_external_dep.c | 10 - test/testfiles/with_external_dep/foo/foo.h | 1 - test/testfiles/with_external_dep/foo/foo.h.gch | Bin 1503664 -> 0 bytes 79 files changed, 1247 insertions(+), 1239 deletions(-) create mode 100644 spec/fixtures/a_rock-1.0-1.rockspec create mode 100644 spec/fixtures/a_rock.lua create mode 100644 spec/fixtures/invalid_patch-0.1-1.rockspec create mode 100644 spec/fixtures/invalid_validate-args-1.5.4-1.rockspec create mode 100644 spec/fixtures/luajit-fail-1.0-1.rockspec create mode 100644 spec/fixtures/luajit-success-1.0-1.rockspec create mode 100644 spec/fixtures/missing_external-0.1-1.rockspec create mode 100644 spec/fixtures/mixed_deploy_type/mdt.c create mode 100644 spec/fixtures/mixed_deploy_type/mdt.lua create mode 100644 spec/fixtures/mixed_deploy_type/mdt_file create mode 100644 spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec create mode 100644 spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec create mode 100644 spec/fixtures/no_build_table-0.1-1.rockspec create mode 100644 spec/fixtures/not_a_zipfile-1.0-1.src.rock create mode 100644 spec/fixtures/patch_create_delete-0.1-1.rockspec create mode 100644 spec/fixtures/patch_create_delete/a_file.txt create mode 100644 spec/fixtures/type_mismatch_string-1.0-1.rockspec create mode 100644 spec/fixtures/type_mismatch_table-1.0-1.rockspec create mode 100644 spec/fixtures/type_mismatch_version-1.0-1.rockspec create mode 100644 spec/fixtures/with_external_dep-0.1-1.rockspec create mode 100644 spec/fixtures/with_external_dep.c create mode 100644 spec/fixtures/with_external_dep/foo/foo.h create mode 100644 spec/fixtures/with_external_dep/foo/foo.h.gch create mode 100644 spec/util/mock-server.lua create mode 100644 spec/util/test_env.lua delete mode 100644 test/luarocks_site.lua delete mode 100644 test/mock-server.lua delete mode 100644 test/test_environment.lua delete mode 100644 test/testfiles/a_rock-1.0-1.rockspec delete mode 100644 test/testfiles/a_rock.lua delete mode 100644 test/testfiles/invalid_patch-0.1-1.rockspec delete mode 100644 test/testfiles/invalid_validate-args-1.5.4-1.rockspec delete mode 100644 test/testfiles/luajit-fail-1.0-1.rockspec delete mode 100644 test/testfiles/luajit-success-1.0-1.rockspec delete mode 100644 test/testfiles/missing_external-0.1-1.rockspec delete mode 100644 test/testfiles/mixed_deploy_type/mdt.c delete mode 100644 test/testfiles/mixed_deploy_type/mdt.lua delete mode 100644 test/testfiles/mixed_deploy_type/mdt_file delete mode 100644 test/testfiles/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec delete mode 100644 test/testfiles/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec delete mode 100644 test/testfiles/no_build_table-0.1-1.rockspec delete mode 100644 test/testfiles/not_a_zipfile-1.0-1.src.rock delete mode 100644 test/testfiles/patch_create_delete-0.1-1.rockspec delete mode 100644 test/testfiles/patch_create_delete/a_file.txt delete mode 100644 test/testfiles/type_mismatch_string-1.0-1.rockspec delete mode 100644 test/testfiles/type_mismatch_table-1.0-1.rockspec delete mode 100644 test/testfiles/type_mismatch_version-1.0-1.rockspec delete mode 100644 test/testfiles/with_external_dep-0.1-1.rockspec delete mode 100644 test/testfiles/with_external_dep.c delete mode 100644 test/testfiles/with_external_dep/foo/foo.h delete mode 100644 test/testfiles/with_external_dep/foo/foo.h.gch diff --git a/.busted b/.busted index 29a8137b..8b246f0c 100644 --- a/.busted +++ b/.busted @@ -1,6 +1,6 @@ return { default = { - helper = "test/test_environment", + helper = "spec.util.test_env", ["auto-insulate"] = false } } diff --git a/spec/add_spec.lua b/spec/add_spec.lua index d42a97d0..1bc9e2a3 100644 --- a/spec/add_spec.lua +++ b/spec/add_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run local testing_paths = test_env.testing_paths @@ -34,7 +34,7 @@ describe("LuaRocks add tests #blackbox #b_add", function() --TODO This test fails, sftp support not yet implemented it("LuaRocks-admin add invalid server", function() - assert.is_false(run.luarocks_admin_bool("--server=testing add luasocket-3.0rc1-2.src.rock", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_sftp.lua" } )) + assert.is_false(run.luarocks_admin_bool("--server=testing add luasocket-3.0rc1-2.src.rock", { LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config_sftp.lua" } )) end) it("LuaRocks-admin add, split server url", function() diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 459a7292..2de05879 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths @@ -140,7 +140,7 @@ describe("LuaRocks build tests #blackbox #b_build", function() describe("LuaRocks build - more complex tests", function() if test_env.TYPE_TEST_ENV == "full" then it("LuaRocks build luacheck show downloads test_config", function() - local output = run.luarocks("build luacheck", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_show_downloads.lua"} ) + local output = run.luarocks("build luacheck", { LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config_show_downloads.lua"} ) assert.is.truthy(output:match("%.%.%.")) end) end @@ -190,7 +190,7 @@ describe("LuaRocks build tests #blackbox #b_build", function() end) it("LuaRocks build invalid patch", function() - assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) + assert.is_false(run.luarocks_bool("build " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec")) end) end) @@ -204,12 +204,12 @@ describe("LuaRocks build tests #blackbox #b_build", function() end) it("fails when missing external dependency", function() - assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) + assert.is_false(run.luarocks_bool("build " .. testing_paths.fixtures_dir .. "/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) end) it("builds with external dependency", function() - local rockspec = testing_paths.testing_dir .. "/testfiles/with_external_dep-0.1-1.rockspec" - local foo_incdir = testing_paths.testing_dir .. "/testfiles/with_external_dep" + local rockspec = testing_paths.fixtures_dir .. "/with_external_dep-0.1-1.rockspec" + local foo_incdir = testing_paths.fixtures_dir .. "/with_external_dep" assert.is_truthy(run.luarocks_bool("build " .. rockspec .. " FOO_INCDIR=\"" .. foo_incdir .. "\"")) assert.is.truthy(run.luarocks("show with_external_dep")) end) diff --git a/spec/config_spec.lua b/spec/config_spec.lua index 6be586c2..fae68474 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua index 8c4effcd..76ee68a7 100644 --- a/spec/deps_spec.lua +++ b/spec/deps_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index ea42cd6b..5f503af2 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run local testing_paths = test_env.testing_paths diff --git a/spec/download_spec.lua b/spec/download_spec.lua index 320d9304..64443922 100644 --- a/spec/download_spec.lua +++ b/spec/download_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index ab2cd54e..59f73b57 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") test_env.unload_luarocks() local fetch = require("luarocks.fetch") diff --git a/spec/fixtures/a_rock-1.0-1.rockspec b/spec/fixtures/a_rock-1.0-1.rockspec new file mode 100644 index 00000000..9f15e87a --- /dev/null +++ b/spec/fixtures/a_rock-1.0-1.rockspec @@ -0,0 +1,17 @@ +package = "a_rock" +version = "1.0-1" +source = { + url = "http://localhost:8080/file/a_rock.lua" +} +description = { + summary = "An example rockspec", +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "builtin", + modules = { + build = "a_rock.lua" + }, +} diff --git a/spec/fixtures/a_rock.lua b/spec/fixtures/a_rock.lua new file mode 100644 index 00000000..a5647075 --- /dev/null +++ b/spec/fixtures/a_rock.lua @@ -0,0 +1 @@ +return {} diff --git a/spec/fixtures/invalid_patch-0.1-1.rockspec b/spec/fixtures/invalid_patch-0.1-1.rockspec new file mode 100644 index 00000000..c2ecd160 --- /dev/null +++ b/spec/fixtures/invalid_patch-0.1-1.rockspec @@ -0,0 +1,29 @@ +package = "invalid_patch" +version = "0.1-1" +source = { + -- any valid URL + url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua" +} +description = { + summary = "A rockspec with an invalid patch", +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "builtin", + modules = { + build = "build.lua" + }, + patches = { + ["I_am_an_invalid_patch.patch"] = +[[ +diff -Naur luadoc-3.0.1/src/luadoc/doclet/html.lua luadoc-3.0.1-new/src/luadoc/doclet/html.lua +--- luadoc-3.0.1/src/luadoc/doclet/html.lua2007-12-21 15:50:48.000000000 -0200 ++++ luadoc-3.0.1-new/src/luadoc/doclet/html.lua2008-02-28 01:59:53.000000000 -0300 +@@ -18,6 +18,7 @@ +- gabba gabba gabba ++ gobo gobo gobo +]] + } +} diff --git a/spec/fixtures/invalid_validate-args-1.5.4-1.rockspec b/spec/fixtures/invalid_validate-args-1.5.4-1.rockspec new file mode 100644 index 00000000..0b4d807d --- /dev/null +++ b/spec/fixtures/invalid_validate-args-1.5.4-1.rockspec @@ -0,0 +1,35 @@ +package = 'validate-args' +version = '1.5.4-1' +source = {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{++{ + url = "https://bitbucket.org/djerius/validate.args/downloads/validate-args-1.5.4.tar.gz" +} + +description = { + summary = "Function argument validation", + detailed = [[ + validate.args is a Lua module that provides a framework for + validation of arguments to Lua functions as well as complex data + structures. The included validate.inplace module provides "live" + validation during assignment of values to elements in tables. ]], + license = "GPL-3", + +} + +dependencies = { + "lua >= 5.1" +} + +build = { + + type = "builtin", + + modules = { + ["validate.args"] = "validate/args.lua", + ["validate.inplace"] = "validate/inplace.lua", + }, + + copy_directories = { + "doc", "tests" + } + +} diff --git a/spec/fixtures/luajit-fail-1.0-1.rockspec b/spec/fixtures/luajit-fail-1.0-1.rockspec new file mode 100644 index 00000000..f8204600 --- /dev/null +++ b/spec/fixtures/luajit-fail-1.0-1.rockspec @@ -0,0 +1,22 @@ +package = "luajit-fail" +version = "1.0-1" +source = { + url = "https://raw.githubusercontent.com/keplerproject/luarocks/master/test/testing.lua", +} +description = { + summary = "Test luajit dependency fail", + detailed = [[ +Fail luajit dependency when running with rockspec_format < 3.0. +]], + homepage = "http://luarocks.org/", + license = "MIT/X license" +} +dependencies = { + "luajit >= 2.0" +} +build = { + type = "builtin", + modules = { + testing = "testing.lua" + } +} diff --git a/spec/fixtures/luajit-success-1.0-1.rockspec b/spec/fixtures/luajit-success-1.0-1.rockspec new file mode 100644 index 00000000..31c930c3 --- /dev/null +++ b/spec/fixtures/luajit-success-1.0-1.rockspec @@ -0,0 +1,23 @@ +rockspec_format = "3.0" +package = "luajit-success" +version = "1.0-1" +source = { + url = "https://raw.githubusercontent.com/keplerproject/luarocks/master/test/testing.lua", +} +description = { + summary = "Test luajit dependency fail", + detailed = [[ +Use luajit dependency when running with rockspec_format >= 3.0. +]], + homepage = "http://luarocks.org/", + license = "MIT/X license" +} +dependencies = { + "luajit >= 2.0" +} +build = { + type = "builtin", + modules = { + testing = "testing.lua" + } +} diff --git a/spec/fixtures/missing_external-0.1-1.rockspec b/spec/fixtures/missing_external-0.1-1.rockspec new file mode 100644 index 00000000..5f8e6219 --- /dev/null +++ b/spec/fixtures/missing_external-0.1-1.rockspec @@ -0,0 +1,24 @@ +package = "missing_external" +version = "0.1-1" +source = { + -- any valid URL + url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua" +} +description = { + summary = "Missing external dependency", +} +external_dependencies = { + INEXISTENT = { + library = "inexistentlib*", + header = "inexistentheader*.h", + } +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "builtin", + modules = { + build = "build.lua" + } +} diff --git a/spec/fixtures/mixed_deploy_type/mdt.c b/spec/fixtures/mixed_deploy_type/mdt.c new file mode 100644 index 00000000..a162ce23 --- /dev/null +++ b/spec/fixtures/mixed_deploy_type/mdt.c @@ -0,0 +1,6 @@ +#include "lua.h" + +int luaopen_mdt(lua_State *L) { + lua_pushstring(L, "mdt.c"); + return 1; +} diff --git a/spec/fixtures/mixed_deploy_type/mdt.lua b/spec/fixtures/mixed_deploy_type/mdt.lua new file mode 100644 index 00000000..c9ca9c68 --- /dev/null +++ b/spec/fixtures/mixed_deploy_type/mdt.lua @@ -0,0 +1 @@ +return "mdt.lua" diff --git a/spec/fixtures/mixed_deploy_type/mdt_file b/spec/fixtures/mixed_deploy_type/mdt_file new file mode 100644 index 00000000..1a15f7d7 --- /dev/null +++ b/spec/fixtures/mixed_deploy_type/mdt_file @@ -0,0 +1 @@ +return "mdt_file" diff --git a/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec b/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec new file mode 100644 index 00000000..91b725da --- /dev/null +++ b/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec @@ -0,0 +1,21 @@ +package = "mixed_deploy_type" +version = "0.1.0-1" +source = { + url = "http://example.com" +} +description = { + homepage = "http://example.com", + license = "*** please specify a license ***" +} +dependencies = {} +build = { + type = "builtin", + modules = { + mdt = "mdt/mdt.lua" + }, + install = { + lua = { + mdt_file = "mdt/mdt_file" + } + } +} diff --git a/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec b/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec new file mode 100644 index 00000000..9ca03180 --- /dev/null +++ b/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec @@ -0,0 +1,21 @@ +package = "mixed_deploy_type" +version = "0.2.0-1" +source = { + url = "http://example.com" +} +description = { + homepage = "http://example.com", + license = "*** please specify a license ***" +} +dependencies = {} +build = { + type = "builtin", + modules = { + mdt = "mdt/mdt.c" + }, + install = { + lib = { + mdt_file = "mdt/mdt_file" + } + } +} diff --git a/spec/fixtures/no_build_table-0.1-1.rockspec b/spec/fixtures/no_build_table-0.1-1.rockspec new file mode 100644 index 00000000..5d79e9a0 --- /dev/null +++ b/spec/fixtures/no_build_table-0.1-1.rockspec @@ -0,0 +1,12 @@ +package = "no_build_table" +version = "0.1-1" +source = { + -- any valid URL + url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua" +} +description = { + summary = "A rockspec with no build field", +} +dependencies = { + "lua >= 5.1" +} diff --git a/spec/fixtures/not_a_zipfile-1.0-1.src.rock b/spec/fixtures/not_a_zipfile-1.0-1.src.rock new file mode 100644 index 00000000..e36f8bbe --- /dev/null +++ b/spec/fixtures/not_a_zipfile-1.0-1.src.rock @@ -0,0 +1 @@ +I am not a .zip file! diff --git a/spec/fixtures/patch_create_delete-0.1-1.rockspec b/spec/fixtures/patch_create_delete-0.1-1.rockspec new file mode 100644 index 00000000..3d55da58 --- /dev/null +++ b/spec/fixtures/patch_create_delete-0.1-1.rockspec @@ -0,0 +1,34 @@ +rockspec_format = "3.0" +package = "patch_create_delete" +version = "0.1-1" +source = { + -- any valid URL + url = "git://github.com/luarocks/luarocks" +} +description = { + summary = "A rockspec with a patch that creates and deletes files", +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "builtin", + modules = { + ["luarocks.loader"] = "src/luarocks/loader.lua" + }, + patches = { + ["create_delete.patch"] = +[[ +diff -Naur luarocks/spec/fixtures/patch_create_delete/a_file.txt luarocks-patch/spec/fixtures/patch_create_delete/a_file.txt +--- luarocks/spec/fixtures/patch_create_delete/a_file.txt 2017-10-04 15:39:44.179306674 -0300 ++++ luarocks-patch/spec/fixtures/patch_create_delete/a_file.txt 1969-12-31 21:00:00.000000000 -0300 +@@ -1 +0,0 @@ +-I am a file. +diff -Naur luarocks/spec/fixtures/patch_create_delete/another_file.txt luarocks-patch/spec/fixtures/patch_create_delete/another_file.txt +--- luarocks/spec/fixtures/patch_create_delete/another_file.txt 1969-12-31 21:00:00.000000000 -0300 ++++ luarocks-patch/spec/fixtures/patch_create_delete/another_file.txt 2017-10-04 15:40:12.836306564 -0300 +@@ -0,0 +1 @@ ++I am another file. +]] + } +} diff --git a/spec/fixtures/patch_create_delete/a_file.txt b/spec/fixtures/patch_create_delete/a_file.txt new file mode 100644 index 00000000..6539c24e --- /dev/null +++ b/spec/fixtures/patch_create_delete/a_file.txt @@ -0,0 +1 @@ +I am a file. diff --git a/spec/fixtures/type_mismatch_string-1.0-1.rockspec b/spec/fixtures/type_mismatch_string-1.0-1.rockspec new file mode 100644 index 00000000..7a607cfd --- /dev/null +++ b/spec/fixtures/type_mismatch_string-1.0-1.rockspec @@ -0,0 +1,4 @@ + +package="type_mismatch_version" +version=1.0 + diff --git a/spec/fixtures/type_mismatch_table-1.0-1.rockspec b/spec/fixtures/type_mismatch_table-1.0-1.rockspec new file mode 100644 index 00000000..f348b798 --- /dev/null +++ b/spec/fixtures/type_mismatch_table-1.0-1.rockspec @@ -0,0 +1,5 @@ + +package="type_mismatch_table" +version="1.0-1" + +source = "not a table" diff --git a/spec/fixtures/type_mismatch_version-1.0-1.rockspec b/spec/fixtures/type_mismatch_version-1.0-1.rockspec new file mode 100644 index 00000000..5e30dae6 --- /dev/null +++ b/spec/fixtures/type_mismatch_version-1.0-1.rockspec @@ -0,0 +1,4 @@ + +package="type_mismatch_version" +version="1.0" + diff --git a/spec/fixtures/with_external_dep-0.1-1.rockspec b/spec/fixtures/with_external_dep-0.1-1.rockspec new file mode 100644 index 00000000..45fea4bd --- /dev/null +++ b/spec/fixtures/with_external_dep-0.1-1.rockspec @@ -0,0 +1,25 @@ +package = "with_external_dep" +version = "0.1-1" +source = { + url = "http://localhost:8080/file/with_external_dep.c" +} +description = { + summary = "An example rockspec", +} +external_dependencies = { + FOO = { + header = "foo/foo.h" + } +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "builtin", + modules = { + with_external_dep = { + sources = "with_external_dep.c", + incdirs = "$(FOO_INCDIR)", + } + } +} diff --git a/spec/fixtures/with_external_dep.c b/spec/fixtures/with_external_dep.c new file mode 100644 index 00000000..16435d8f --- /dev/null +++ b/spec/fixtures/with_external_dep.c @@ -0,0 +1,10 @@ +#include +#include +#include + +int luaopen_with_external_dep(lua_State* L) { + lua_newtable(L); + lua_pushinteger(L, FOO); + lua_setfield(L, -2, "foo"); + return 1; +} diff --git a/spec/fixtures/with_external_dep/foo/foo.h b/spec/fixtures/with_external_dep/foo/foo.h new file mode 100644 index 00000000..eedd558f --- /dev/null +++ b/spec/fixtures/with_external_dep/foo/foo.h @@ -0,0 +1 @@ +#define FOO 42 diff --git a/spec/fixtures/with_external_dep/foo/foo.h.gch b/spec/fixtures/with_external_dep/foo/foo.h.gch new file mode 100644 index 00000000..66165c9e Binary files /dev/null and b/spec/fixtures/with_external_dep/foo/foo.h.gch differ diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua index c76f47a4..17ac90ab 100644 --- a/spec/fs_spec.lua +++ b/spec/fs_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") test_env.unload_luarocks() local fs = require("luarocks.fs") diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 71b1b9f6..f7bb79b3 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run test_env.unload_luarocks() diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 92b780d3..d72d88ba 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths @@ -43,7 +43,7 @@ describe("LuaRocks install tests #blackbox #b_install", function() end) it("LuaRocks install invalid patch", function() - assert.is_false(run.luarocks_bool("install " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) + assert.is_false(run.luarocks_bool("install " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec")) end) it("LuaRocks install invalid rock", function() @@ -55,7 +55,7 @@ describe("LuaRocks install tests #blackbox #b_install", function() end) it("LuaRocks install not a zip file", function() - assert.is_false(run.luarocks_bool("install " .. testing_paths.testing_dir .. "/testfiles/not_a_zipfile-1.0-1.src.rock")) + assert.is_false(run.luarocks_bool("install " .. testing_paths.fixtures_dir .. "/not_a_zipfile-1.0-1.src.rock")) end) it("LuaRocks install only-deps of lxsh show there is no lxsh", function() diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua index f7496037..1c082b2a 100644 --- a/spec/lint_spec.lua +++ b/spec/lint_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run local testing_paths = test_env.testing_paths @@ -31,19 +31,19 @@ describe("LuaRocks lint tests #blackbox #b_lint", function() describe("LuaRocks lint mismatch set", function() it("LuaRocks lint mismatch string", function() - assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/type_mismatch_string-1.0-1.rockspec")) + assert.is_false(run.luarocks_bool("lint " .. testing_paths.fixtures_dir .. "/type_mismatch_string-1.0-1.rockspec")) end) it("LuaRocks lint mismatch version", function() - assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/type_mismatch_version-1.0-1.rockspec")) + assert.is_false(run.luarocks_bool("lint " .. testing_paths.fixtures_dir .. "/type_mismatch_version-1.0-1.rockspec")) end) it("LuaRocks lint mismatch table", function() - assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/type_mismatch_table-1.0-1.rockspec")) + assert.is_false(run.luarocks_bool("lint " .. testing_paths.fixtures_dir .. "/type_mismatch_table-1.0-1.rockspec")) end) it("LuaRocks lint mismatch no build table", function() - assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/no_build_table-1.0-1.rockspec")) + assert.is_false(run.luarocks_bool("lint " .. testing_paths.fixtures_dir .. "/no_build_table-1.0-1.rockspec")) end) end) end) diff --git a/spec/list_spec.lua b/spec/list_spec.lua index b9a8e4c4..9f221b90 100644 --- a/spec/list_spec.lua +++ b/spec/list_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run local testing_paths = test_env.testing_paths diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua index 3e998cbf..2b109fa7 100644 --- a/spec/make_manifest_spec.lua +++ b/spec/make_manifest_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run test_env.unload_luarocks() diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 4c406c68..88b35b22 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths @@ -102,7 +102,7 @@ describe("LuaRocks make tests #blackbox #b_make", function() describe("LuaRocks make upgrading rockspecs with mixed deploy types", function() before_each(function() - test_env.copy_dir(testing_paths.testing_dir .. "/testfiles/mixed_deploy_type", "mdt") + test_env.copy_dir(testing_paths.fixtures_dir .. "/mixed_deploy_type", "mdt") end) after_each(function() diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 2f67141d..65f60dd6 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 0c6dd8f2..966195c5 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths @@ -30,7 +30,7 @@ describe("LuaRocks pack tests #blackbox #b_pack", function() end) it("LuaRocks pack invalid rockspec", function() - assert.is_false(run.luarocks_bool("pack " .. testing_paths.testing_dir .. "/testfiles/invaild_validate-args-1.5.4-1.rockspec")) + assert.is_false(run.luarocks_bool("pack " .. testing_paths.fixtures_dir .. "/invaild_validate-args-1.5.4-1.rockspec")) end) it("LuaRocks pack not installed rock", function() diff --git a/spec/path_spec.lua b/spec/path_spec.lua index 536233b1..bbc0cfc8 100644 --- a/spec/path_spec.lua +++ b/spec/path_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run test_env.unload_luarocks() diff --git a/spec/persist.lua b/spec/persist.lua index 6b69dab4..00a9b75d 100644 --- a/spec/persist.lua +++ b/spec/persist.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") test_env.unload_luarocks() local persist = require("luarocks.persist") diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua index 20cee5f0..79ad0dfd 100644 --- a/spec/purge_spec.lua +++ b/spec/purge_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run local testing_paths = test_env.testing_paths diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua index 09f5645e..51c1572f 100644 --- a/spec/refresh_cache_spec.lua +++ b/spec/refresh_cache_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run test_env.unload_luarocks() diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua index 4d3f5cdc..c0e9beb0 100644 --- a/spec/remove_spec.lua +++ b/spec/remove_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths diff --git a/spec/search_spec.lua b/spec/search_spec.lua index 04f84eeb..952458dd 100644 --- a/spec/search_spec.lua +++ b/spec/search_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run test_env.unload_luarocks() diff --git a/spec/show_spec.lua b/spec/show_spec.lua index 0b046de0..d572be9b 100644 --- a/spec/show_spec.lua +++ b/spec/show_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run test_env.unload_luarocks() diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua index d629e225..fc02d853 100644 --- a/spec/unpack_spec.lua +++ b/spec/unpack_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run local testing_paths = test_env.testing_paths @@ -26,7 +26,7 @@ describe("LuaRocks unpack tests #blackbox #b_unpack", function() end) it("LuaRocks unpack with invalid patch", function() - assert.is_false(run.luarocks_bool("unpack " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) + assert.is_false(run.luarocks_bool("unpack " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec")) end) end) diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index b8e147e0..3adfa2dd 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local run = test_env.run local testing_paths = test_env.testing_paths @@ -39,10 +39,10 @@ describe("LuaRocks upload tests #blackbox #b_upload", function() after_each(test_env.mock_server_done) it("LuaRocks upload rockspec with api-key", function() - assert.is_true(run.luarocks_bool("upload " .. testing_paths.testing_dir .. "/testfiles/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) + assert.is_true(run.luarocks_bool("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})) end) it("LuaRocks upload rockspec with api-key and skip-pack", function() - assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.testing_dir .. "/testfiles/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) + assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})) end) end) end) diff --git a/spec/util/mock-server.lua b/spec/util/mock-server.lua new file mode 100644 index 00000000..244aceae --- /dev/null +++ b/spec/util/mock-server.lua @@ -0,0 +1,97 @@ +#!/usr/bin/env lua + +--- A simple LuaRocks mock-server for testing. +local restserver = require("restserver") +local server = restserver:new():port(8080) + +server:add_resource("api/tool_version", { + { + method = "GET", + path = "/", + produces = "application/json", + handler = function(query) + local json = { version = query.current } + return restserver.response():status(200):entity(json) + end + } +}) + +server:add_resource("api/1/{id:[0-9]+}/status", { + { + method = "GET", + path = "/", + produces = "application/json", + handler = function(query) + local json = { user_id = "123", created_at = "29.1.1993" } + return restserver.response():status(200):entity(json) + end + } +}) + +server:add_resource("/api/1/{id:[0-9]+}/check_rockspec", { + { + method = "GET", + path = "/", + produces = "application/json", + handler = function(query) + local json = {} + return restserver.response():status(200):entity(json) + end + } +}) + +server:add_resource("/api/1/{id:[0-9]+}/upload", { + { + method = "POST", + path = "/", + produces = "application/json", + handler = function(query) + local json = {module = "luasocket", version = {id = "1.0"}, module_url = "http://localhost/luasocket", manifests = "root", is_new = "is_new"} + return restserver.response():status(200):entity(json) + end + } +}) + +server:add_resource("/api/1/{id:[0-9]+}/upload_rock/{id:[0-9]+}", { + { + method = "POST", + path = "/", + produces = "application/json", + handler = function(query) + local json = {"rock","module_url"} + return restserver.response():status(200):entity(json) + end + } +}) + +server:add_resource("/file/{name:[^/]+}", { + { + method = "GET", + path = "/", + produces = "text/plain", + handler = function(query, name) + local fd = io.open("spec/fixtures/"..name, "r") + if not fd then + return restserver.response():status(404) + end + local data = fd:read("*a") + fd:close() + return restserver.response():status(200):entity(data) + end + } +}) + +-- SHUTDOWN this mock-server +server:add_resource("/shutdown", { + { + method = "GET", + path = "/", + handler = function(query) + os.exit() + return restserver.response():status(200):entity() + end + } +}) + +-- This loads the restserver.xavante plugin +server:enable("restserver.xavante"):start() \ No newline at end of file diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua new file mode 100644 index 00000000..9d9ae843 --- /dev/null +++ b/spec/util/test_env.lua @@ -0,0 +1,795 @@ +local lfs = require("lfs") +local test_env = {} + +local help_message = [[ +LuaRocks test-suite + +INFORMATION + New test-suite for LuaRocks project, using unit testing framework Busted. +REQUIREMENTS + Be sure sshd is running on your system, or use '--exclude-tags=ssh', + to not execute tests which require sshd. +USAGE + busted [-Xhelper ] +ARGUMENTS + env= Set type of environment to use ("minimal" or "full", + default: "minimal"). + noreset Don't reset environment after each test + clean Remove existing testing environment. + travis Add if running on TravisCI. + appveyor Add if running on Appveyor. + os= Set OS ("linux", "osx", or "windows"). + lua_dir= Path of Lua installation (default "/usr/local") + lua_interpreter= Name of the interpreter (default "lua") +]] + +local function help() + print(help_message) + os.exit(1) +end + +local function title(str) + print() + print(("-"):rep(#str)) + print(str) + print(("-"):rep(#str)) +end + +function test_env.exists(path) + return lfs.attributes(path, "mode") ~= nil +end + +--- Quote argument for shell processing. Fixes paths on Windows. +-- Adds double quotes and escapes. Based on function in fs/win32.lua. +-- @param arg string: Unquoted argument. +-- @return string: Quoted argument. +local function Q(arg) + if test_env.TEST_TARGET_OS == "windows" then + local drive_letter = "[%.a-zA-Z]?:?[\\/]" + -- Quote DIR for Windows + if arg:match("^"..drive_letter) then + arg = arg:gsub("/", "\\") + end + + if arg == "\\" then + return '\\' -- CHDIR needs special handling for root dir + end + + return '"' .. arg .. '"' + else + return "'" .. arg:gsub("'", "'\\''") .. "'" + end +end + +function test_env.quiet(command) + if not test_env.VERBOSE then + if test_env.TEST_TARGET_OS == "windows" then + return command .. " 1> NUL 2> NUL" + else + return command .. " 1> /dev/null 2> /dev/null" + end + else + return command + end +end + +function test_env.copy(source, destination) + local r_source, err = io.open(source, "r") + local r_destination, err = io.open(destination, "w") + + while true do + local block = r_source:read(8192) + if not block then break end + r_destination:write(block) + end + + r_source:close() + r_destination:close() +end + +--- Helper function for execute_bool and execute_output +-- @param command string: command to execute +-- @param print_command boolean: print command if 'true' +-- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"} +-- @return final_command string: concatenated command to execution +function test_env.execute_helper(command, print_command, env_variables) + local final_command = "" + + if print_command then + print("[EXECUTING]: " .. command) + end + + if env_variables then + if test_env.TEST_TARGET_OS == "windows" then + for k,v in pairs(env_variables) do + final_command = final_command .. "set " .. k .. "=" .. v .. "&" + end + final_command = final_command:sub(1, -2) .. "&" + else + final_command = "export " + for k,v in pairs(env_variables) do + final_command = final_command .. k .. "='" .. v .. "' " + end + -- remove last space and add ';' to separate exporting variables from command + final_command = final_command:sub(1, -2) .. "; " + end + end + + final_command = final_command .. command .. " 2>&1" + + return final_command +end + +--- Execute command and returns true/false +-- @return true/false boolean: status of the command execution +local function execute_bool(command, print_command, env_variables) + command = test_env.execute_helper(command, print_command, env_variables) + + local redirect_filename + local redirect = "" + if print_command ~= nil then + redirect_filename = test_env.testing_paths.luarocks_tmp.."/output.txt" + redirect = " > "..redirect_filename + os.remove(redirect_filename) + end + local ok = os.execute(command .. redirect) + ok = (ok == true or ok == 0) -- normalize Lua 5.1 output to boolean + if redirect ~= "" then + if not ok then + local fd = io.open(redirect_filename, "r") + if fd then + print(fd:read("*a")) + fd:close() + end + end + os.remove(redirect_filename) + end + return ok +end + +--- Execute command and returns output of command +-- @return output string: output the command execution +local function execute_output(command, print_command, env_variables) + command = test_env.execute_helper(command, print_command, env_variables) + + local file = assert(io.popen(command)) + local output = file:read('*all') + file:close() + return output:gsub("\n","") -- output adding new line, need to be removed +end + +--- Set test_env.LUA_V or test_env.LUAJIT_V based +-- on version of Lua used to run this script. +function test_env.set_lua_version() + if _G.jit then + test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d") + test_env.lua_version = "5.1" + else + test_env.LUA_V = _VERSION:match("5%.%d") + test_env.lua_version = test_env.LUA_V + end +end + +--- Set all arguments from input into global variables +function test_env.set_args() + -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables + test_env.TYPE_TEST_ENV = "minimal" + test_env.OPENSSL_DIRS = "" + test_env.RESET_ENV = true + + for _, argument in ipairs(arg) do + if argument:find("^env=") then + test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$") + elseif argument == "noreset" then + test_env.RESET_ENV = false + elseif argument == "clean" then + test_env.TEST_ENV_CLEAN = true + elseif argument == "verbose" then + test_env.VERBOSE = true + elseif argument == "travis" then + test_env.TRAVIS = true + elseif argument == "appveyor" then + test_env.APPVEYOR = true + test_env.OPENSSL_DIRS = "OPENSSL_LIBDIR=C:\\OpenSSL-Win32\\lib OPENSSL_INCDIR=C:\\OpenSSL-Win32\\include" + elseif argument:find("^os=") then + test_env.TEST_TARGET_OS = argument:match("^os=(.*)$") + elseif argument == "mingw" then + test_env.MINGW = true + elseif argument == "vs" then + test_env.MINGW = false + elseif argument:find("^lua_dir=") then + test_env.LUA_DIR = argument:match("^lua_dir=(.*)$") + elseif argument:find("^lua_interpreter=") then + test_env.LUA_INTERPRETER = argument:match("^lua_interpreter=(.*)$") + else + help() + end + end + + if not test_env.TEST_TARGET_OS then + title("OS CHECK") + + if execute_bool("sw_vers") then + test_env.TEST_TARGET_OS = "osx" + if test_env.TRAVIS then + test_env.OPENSSL_DIRS = "OPENSSL_LIBDIR=/usr/local/opt/openssl/lib OPENSSL_INCDIR=/usr/local/opt/openssl/include" + end + elseif execute_output("uname -s") == "Linux" then + test_env.TEST_TARGET_OS = "linux" + else + test_env.TEST_TARGET_OS = "windows" + end + end + return true +end + +function test_env.copy_dir(source_path, target_path) + local testing_paths = test_env.testing_paths + if test_env.TEST_TARGET_OS == "windows" then + execute_bool(testing_paths.win_tools .. "/cp -R ".. source_path .. "/. " .. target_path) + else + execute_bool("cp -a ".. source_path .. "/. " .. target_path) + end +end + +--- Remove directory recursively +-- @param path string: directory path to delete +function test_env.remove_dir(path) + if test_env.exists(path) then + for file in lfs.dir(path) do + if file ~= "." and file ~= ".." then + local full_path = path..'/'..file + + if lfs.attributes(full_path, "mode") == "directory" then + test_env.remove_dir(full_path) + else + os.remove(full_path) + end + end + end + end + lfs.rmdir(path) +end + +--- Remove subdirectories of a directory that match a pattern +-- @param path string: path to directory +-- @param pattern string: pattern matching basenames of subdirectories to be removed +function test_env.remove_subdirs(path, pattern) + if test_env.exists(path) then + for file in lfs.dir(path) do + if file ~= "." and file ~= ".." then + local full_path = path..'/'..file + + if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then + test_env.remove_dir(full_path) + end + end + end + end +end + +--- Remove files matching a pattern +-- @param path string: directory where to delete files +-- @param pattern string: pattern matching basenames of files to be deleted +-- @return result_check boolean: true if one or more files deleted +function test_env.remove_files(path, pattern) + local result_check = false + if test_env.exists(path) then + for file in lfs.dir(path) do + if file ~= "." and file ~= ".." then + if file:find(pattern) then + if os.remove(path .. "/" .. file) then + result_check = true + end + end + end + end + end + return result_check +end + + +--- Function for downloading rocks and rockspecs +-- @param urls table: array of full names of rocks/rockspecs to download +-- @param save_path string: path to directory, where to download rocks/rockspecs +-- @return make_manifest boolean: true if new rocks downloaded +local function download_rocks(urls, save_path) + local luarocks_repo = "https://luarocks.org" + local make_manifest = false + + for _, url in ipairs(urls) do + -- check if already downloaded + if not test_env.exists(save_path .. url) then + if test_env.TEST_TARGET_OS == "windows" then + execute_bool(test_env.testing_paths.win_tools .. "/wget -cP " .. save_path .. " " .. luarocks_repo .. url .. " --no-check-certificate") + else + execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) + end + make_manifest = true + end + end + return make_manifest +end + +--- Create a file containing a string. +-- @param path string: path to file. +-- @param str string: content of the file. +local function write_file(path, str) + local file = assert(io.open(path, "w")) + file:write(str) + file:close() +end + +--- Create md5sum of directory structure recursively, based on filename and size +-- @param path string: path to directory for generate md5sum +-- @return md5sum string: md5sum of directory +local function hash_environment(path) + if test_env.TEST_TARGET_OS == "linux" then + return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") + elseif test_env.TEST_TARGET_OS == "osx" then + return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") + elseif test_env.TEST_TARGET_OS == "windows" then + return execute_output("\"" .. Q(test_env.testing_paths.win_tools .. "/find") .. " " .. Q(path) + .. " -printf \"%s %p\"\" > temp_sum.txt && certUtil -hashfile temp_sum.txt && del temp_sum.txt") + end +end + +--- Create environment variables needed for tests +-- @param testing_paths table: table with paths to testing directory +-- @return env_variables table: table with created environment variables +local function create_env(testing_paths) + local luaversion_short = _VERSION:gsub("Lua ", "") + + if test_env.LUAJIT_V then + luaversion_short="5.1" + end + + local env_variables = {} + env_variables.LUA_VERSION = luaversion_short + env_variables.LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config.lua" + if test_env.TEST_TARGET_OS == "windows" then + env_variables.LUA_PATH = testing_paths.testing_lrprefix .. "\\lua\\?.lua;" + else + env_variables.LUA_PATH = testing_paths.testing_lrprefix .. "/share/lua/" .. luaversion_short .. "/?.lua;" + end + env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" + env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" + env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" + env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" + env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" + env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" + .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" + env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;" + + return env_variables +end + +--- Create md5sums of origin system and system-copy testing directory +-- @param testing_paths table: table with paths to testing directory +-- @return md5sums table: table of md5sums of system and system-copy testing directory +local function create_md5sums(testing_paths) + local md5sums = {} + md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy) + md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy) + + return md5sums +end + +local function make_run_function(cmd_name, exec_function, with_coverage, do_print) + local cmd_prefix = Q(test_env.testing_paths.lua) .. " " + + if with_coverage then + cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testrun_dir .. "/luacov.config')\" " + end + + if test_env.TEST_TARGET_OS == "windows" then + cmd_prefix = cmd_prefix .. Q(test_env.testing_paths.testing_lrprefix .. "/" .. cmd_name .. ".lua") .. " " + else + cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " + end + + return function(cmd, new_vars) + local temp_vars = {} + for k, v in pairs(test_env.env_variables) do + temp_vars[k] = v + end + if new_vars then + for k, v in pairs(new_vars) do + temp_vars[k] = v + end + end + return exec_function(cmd_prefix .. cmd, do_print, temp_vars) + end +end + +local function make_run_functions() + return { + luarocks = make_run_function("luarocks", execute_output, true, true), + luarocks_bool = make_run_function("luarocks", execute_bool, true, true), + luarocks_noprint = make_run_function("luarocks", execute_bool, true, false), + luarocks_nocov = make_run_function("luarocks", execute_bool, false, true), + luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false), + luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true), + luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true), + luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false) + } +end + +--- Rebuild environment. +-- Remove old installed rocks and install new ones, +-- updating manifests and tree copies. +local function build_environment(rocks, env_variables) + title("BUILDING ENVIRONMENT") + local testing_paths = test_env.testing_paths + test_env.remove_dir(testing_paths.testing_tree) + test_env.remove_dir(testing_paths.testing_sys_tree) + test_env.remove_dir(testing_paths.testing_tree_copy) + test_env.remove_dir(testing_paths.testing_sys_tree_copy) + + lfs.mkdir(testing_paths.testing_tree) + lfs.mkdir(testing_paths.testing_sys_tree) + + test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_server)) + test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_cache)) + + for _, rock in ipairs(rocks) do + if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. Q(rock), env_variables) then + test_env.run.luarocks_nocov("build --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock) .. "", env_variables) + test_env.run.luarocks_nocov("pack --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables) + if test_env.TEST_TARGET_OS == "windows" then + execute_bool(testing_paths.win_tools .. "/mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) + else + execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) + end + end + end + + test_env.copy_dir(testing_paths.testing_tree, testing_paths.testing_tree_copy) + test_env.copy_dir(testing_paths.testing_sys_tree, testing_paths.testing_sys_tree_copy) +end + +--- Reset testing environment +local function reset_environment(testing_paths, md5sums) + local testing_tree_md5 = hash_environment(testing_paths.testing_tree) + local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree) + + if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then + test_env.remove_dir(testing_paths.testing_tree) + test_env.copy_dir(testing_paths.testing_tree_copy, testing_paths.testing_tree) + end + + if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then + test_env.remove_dir(testing_paths.testing_sys_tree) + test_env.copy_dir(testing_paths.testing_sys_tree_copy, testing_paths.testing_sys_tree) + end +end + +local function create_paths(luaversion_full) + + local testing_paths = {} + testing_paths.luadir = (test_env.LUA_DIR or "/usr/local") + testing_paths.lua = testing_paths.luadir .. "/bin/" .. (test_env.LUA_INTERPRETER or "lua") + + if test_env.TEST_TARGET_OS == "windows" then + testing_paths.luarocks_tmp = os.getenv("TEMP") + else + testing_paths.luarocks_tmp = "/tmp/luarocks_testing" + end + + testing_paths.luarocks_dir = lfs.currentdir() + + if test_env.TEST_TARGET_OS == "windows" then + testing_paths.luarocks_dir = testing_paths.luarocks_dir:gsub("\\","/") + end + + testing_paths.fixtures_dir = testing_paths.luarocks_dir .. "/spec/fixtures" + testing_paths.util_dir = testing_paths.luarocks_dir .. "/spec/util" + testing_paths.testrun_dir = testing_paths.luarocks_dir .. "/testrun" + testing_paths.src_dir = testing_paths.luarocks_dir .. "/src" + testing_paths.testing_lrprefix = testing_paths.testrun_dir .. "/testing_lrprefix-" .. luaversion_full + testing_paths.testing_tree = testing_paths.testrun_dir .. "/testing-" .. luaversion_full + testing_paths.testing_tree_copy = testing_paths.testrun_dir .. "/testing_copy-" .. luaversion_full + testing_paths.testing_sys_tree = testing_paths.testrun_dir .. "/testing_sys-" .. luaversion_full + testing_paths.testing_sys_tree_copy = testing_paths.testrun_dir .. "/testing_sys_copy-" .. luaversion_full + testing_paths.testing_cache = testing_paths.testrun_dir .. "/testing_cache-" .. luaversion_full + testing_paths.testing_server = testing_paths.testrun_dir .. "/testing_server-" .. luaversion_full + + testing_paths.testing_rocks = testing_paths.testing_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version + testing_paths.testing_sys_rocks = testing_paths.testing_sys_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version + + if test_env.TEST_TARGET_OS == "windows" then + testing_paths.win_tools = testing_paths.testing_lrprefix .. "/tools" + end + + return testing_paths +end + +--- Helper function to unload luarocks modules from global table package.loaded +-- Needed to load our local (testing) version of LuaRocks +function test_env.unload_luarocks() + for modname, _ in pairs(package.loaded) do + if modname:match("^luarocks%.") then + package.loaded[modname] = nil + end + end +end + +--- Function for initially setup of environment, variables, md5sums for spec files +function test_env.setup_specs(extra_rocks) + -- if global variable about successful creation of testing environment doesn't exist, build environment + if not test_env.setup_done then + if test_env.TRAVIS then + if not test_env.exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then + execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") + execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") + execute_bool("chmod og-wx ~/.ssh/authorized_keys") + execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts") + end + end + + test_env.main() + package.path = test_env.env_variables.LUA_PATH + + test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables) + test_env.lib_extension = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').lib_extension)\"", false, test_env.env_variables) + test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" + test_env.md5sums = create_md5sums(test_env.testing_paths) + test_env.setup_done = true + title("RUNNING TESTS") + end + + if extra_rocks then + local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) + if make_manifest then + test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) + end + end + + if test_env.RESET_ENV then + reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) + end +end + +--- Test if required rock is installed and if not, install it. +-- Return `true` if the rock is already installed or has been installed successfully, +-- `false` if installation failed. +function test_env.need_rock(rock) + print("Check if " .. rock .. " is installed") + if test_env.run.luarocks_noprint_nocov(test_env.quiet("show " .. rock)) then + return true + else + return test_env.run.luarocks_noprint_nocov(test_env.quiet("install " .. rock)) + end +end + +--- For each key-value pair in replacements table +-- replace %{key} in given string with value. +local function substitute(str, replacements) + return (str:gsub("%%%b{}", function(marker) + return replacements[marker:sub(3, -2)] + end)) +end + + +--- Create configs for luacov and several versions of Luarocks +-- configs needed for some tests. +local function create_configs() + -- testing_config.lua and testing_config_show_downloads.lua + local config_content = substitute([[ + rocks_trees = { + "%{testing_tree}", + { name = "system", root = "%{testing_sys_tree}" }, + } + rocks_servers = { + "%{testing_server}" + } + local_cache = "%{testing_cache}" + upload_server = "testing" + upload_user = "%{user}" + upload_servers = { + testing = { + rsync = "localhost/tmp/luarocks_testing", + }, + } + external_deps_dirs = { + "/usr/local", + "/usr", + -- These are used for a test that fails, so it + -- can point to invalid paths: + { + prefix = "/opt", + bin = "bin", + include = "include", + lib = { "lib", "lib64" }, + } + } + ]], { + user = os.getenv("USER"), + testing_sys_tree = test_env.testing_paths.testing_sys_tree, + testing_tree = test_env.testing_paths.testing_tree, + testing_server = test_env.testing_paths.testing_server, + testing_cache = test_env.testing_paths.testing_cache + }) + + write_file(test_env.testing_paths.testrun_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") + write_file(test_env.testing_paths.testrun_dir .. "/testing_config_show_downloads.lua", config_content + .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") + + -- testing_config_sftp.lua + config_content = substitute([[ + rocks_trees = { + "%{testing_tree}", + "%{testing_sys_tree}", + } + local_cache = "%{testing_cache}" + upload_server = "testing" + upload_user = "%{user}" + upload_servers = { + testing = { + sftp = "localhost/tmp/luarocks_testing", + }, + } + ]], { + user = os.getenv("USER"), + testing_sys_tree = test_env.testing_paths.testing_sys_tree, + testing_tree = test_env.testing_paths.testing_tree, + testing_cache = test_env.testing_paths.testing_cache + }) + + write_file(test_env.testing_paths.testrun_dir .. "/testing_config_sftp.lua", config_content) + + -- luacov.config + config_content = substitute([[ + return { + statsfile = "%{testrun_dir}/luacov.stats.out", + reportfile = "%{testrun_dir}/luacov.report.out", + modules = { + ["luarocks"] = "src/bin/luarocks", + ["luarocks-admin"] = "src/bin/luarocks-admin", + ["luarocks.*"] = "src", + ["luarocks.*.*"] = "src", + ["luarocks.*.*.*"] = "src" + } + } + ]], { + testrun_dir = test_env.testing_paths.testrun_dir + }) + + write_file(test_env.testing_paths.testrun_dir .. "/luacov.config", config_content) + + config_content = [[ + -- Config file of mock LuaRocks.org site for tests + upload = { + server = "http://localhost:8080", + tool_version = "1.0.0", + api_version = "1", + } + ]] + write_file(test_env.testing_paths.testrun_dir .. "/luarocks_site.lua", config_content) +end + +--- Remove testing directories. +local function clean() + print("Cleaning testing directory...") + test_env.remove_dir(test_env.testing_paths.luarocks_tmp) + test_env.remove_subdirs(test_env.testing_paths.testrun_dir, "testing[_%-]") + test_env.remove_files(test_env.testing_paths.testrun_dir, "testing_") + test_env.remove_files(test_env.testing_paths.testrun_dir, "luacov") + test_env.remove_files(test_env.testing_paths.testrun_dir, "upload_config") + test_env.remove_files(test_env.testing_paths.testrun_dir, "luarocks_site") + print("Cleaning done!") +end + +--- Install luarocks into testing prefix. +local function install_luarocks(install_env_vars) + local testing_paths = test_env.testing_paths + title("Installing LuaRocks") + if test_env.TEST_TARGET_OS == "windows" then + local compiler_flag = test_env.MINGW and "/MW" or "" + assert(execute_bool("install.bat /LUA " .. testing_paths.luadir .. " " .. compiler_flag .. " /P " .. testing_paths.testing_lrprefix .. " /NOREG /NOADMIN /F /Q /CONFIG " .. testing_paths.testing_lrprefix .. "/etc/luarocks", false, install_env_vars)) + assert(execute_bool(testing_paths.win_tools .. "/cp " .. testing_paths.testing_lrprefix .. "/lua/luarocks/core/site_config* " .. testing_paths.src_dir .. "/luarocks/core")) + else + local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix + assert(execute_bool(configure_cmd, false, install_env_vars)) + assert(execute_bool("make clean", false, install_env_vars)) + assert(execute_bool("make src/luarocks/core/site_config_"..test_env.lua_version:gsub("%.", "_")..".lua", false, install_env_vars)) + assert(execute_bool("make dev", false, install_env_vars)) + end + print("LuaRocks installed correctly!") +end + +function test_env.mock_server_extra_rocks(more) + local rocks = { + -- rocks needed for mock-server + "/copas-2.0.1-1.src.rock", + "/coxpcall-1.16.0-1.src.rock", + "/dkjson-2.5-2.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", + "/restserver-0.1-1.src.rock", + "/restserver-xavante-0.2-1.src.rock", + "/rings-1.3.0-1.src.rock", + "/wsapi-1.6.1-1.src.rock", + "/wsapi-xavante-1.6.1-1.src.rock", + "/xavante-2.4.0-1.src.rock" + } + if more then + for _, rock in ipairs(more) do + table.insert(rocks, rock) + end + end + return rocks +end + +function test_env.mock_server_init() + local assert = require("luassert") + local testing_paths = test_env.testing_paths + assert.is_true(test_env.need_rock("restserver-xavante")) + local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua &", true, test_env.env_variables) + os.execute(final_command) +end + +function test_env.mock_server_done() + os.execute("curl localhost:8080/shutdown") +end + +--- +-- Main function to create config files and testing environment +function test_env.main() + local testing_paths = test_env.testing_paths + + if test_env.TEST_ENV_CLEAN then + clean() + end + + lfs.mkdir(testing_paths.testrun_dir) + lfs.mkdir(testing_paths.testing_cache) + lfs.mkdir(testing_paths.luarocks_tmp) + + create_configs() + + local install_env_vars = { + LUAROCKS_CONFIG = test_env.testing_paths.testrun_dir .. "/testing_config.lua" + } + + install_luarocks(install_env_vars) + + -- Preparation of rocks for building environment + local rocks = {} -- names of rocks, required for building environment + local urls = {} -- names of rock and rockspec files to be downloaded + table.insert(urls, "/luacov-0.11.0-1.rockspec") + table.insert(urls, "/luacov-0.11.0-1.src.rock") + + if test_env.TYPE_TEST_ENV == "full" then + table.insert(urls, "/luafilesystem-1.6.3-1.src.rock") + table.insert(urls, "/luasocket-3.0rc1-1.src.rock") + table.insert(urls, "/luasocket-3.0rc1-1.rockspec") + table.insert(urls, "/luaposix-33.2.1-1.src.rock") + table.insert(urls, "/md5-1.2-1.src.rock") + table.insert(urls, "/lzlib-0.4.1.53-1.src.rock") + rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} + + if test_env.LUA_V ~= "5.1" then + table.insert(urls, "/luabitop-1.0.2-1.rockspec") + table.insert(urls, "/luabitop-1.0.2-1.src.rock") + table.insert(rocks, "luabitop") + end + end + + table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment + + -- Download rocks needed for LuaRocks testing environment + lfs.mkdir(testing_paths.testing_server) + download_rocks(urls, testing_paths.testing_server) + build_environment(rocks, install_env_vars) +end + +test_env.set_lua_version() +test_env.set_args() +test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) +test_env.env_variables = create_env(test_env.testing_paths) +test_env.run = make_run_functions() + +return test_env diff --git a/spec/util_spec.lua b/spec/util_spec.lua index 25cc51d8..3aa8fbf5 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index 0c860939..9ee86ada 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua @@ -1,4 +1,4 @@ -local test_env = require("test/test_environment") +local test_env = require("spec.util.test_env") local lfs = require("lfs") local run = test_env.run @@ -27,28 +27,28 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() describe("LuaRocks write_rockspec more complex tests", function() it("LuaRocks write_rockspec git luarocks", function() - assert.is_true(run.luarocks_bool("write_rockspec git://github.com/keplerproject/luarocks")) - assert.is.truthy(lfs.attributes("luarocks-dev-1.rockspec")) - assert.is_true(os.remove("luarocks-dev-1.rockspec")) + assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock")) + assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) + assert.is_true(os.remove("testrock-dev-1.rockspec")) end) it("LuaRocks write_rockspec git luarocks --tag=v2.3.0", function() - assert.is_true(run.luarocks_bool("write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0")) - assert.is.truthy(lfs.attributes("luarocks-2.3.0-1.rockspec")) - assert.is_true(os.remove("luarocks-2.3.0-1.rockspec")) + assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --tag=v2.3.0")) + assert.is.truthy(lfs.attributes("testrock-2.3.0-1.rockspec")) + assert.is_true(os.remove("testrock-2.3.0-1.rockspec")) end) it("LuaRocks write_rockspec git luarocks with format flag", function() - assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2")) - assert.is.truthy(lfs.attributes("luarocks-dev-1.rockspec")) - assert.is_true(os.remove("luarocks-dev-1.rockspec")) + assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --rockspec-format=1.1 --lua-version=5.1,5.2")) + assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) + assert.is_true(os.remove("testrock-dev-1.rockspec")) end) it("LuaRocks write_rockspec git luarocks with full flags", function() - assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/luarocks --lua-version=5.1,5.2 --license=\"MIT/X11\" " + assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --lua-version=5.1,5.2 --license=\"MIT/X11\" " .. " --homepage=\"http://www.luarocks.org\" --summary=\"A package manager for Lua modules\" ")) - assert.is.truthy(lfs.attributes("luarocks-dev-1.rockspec")) - assert.is_true(os.remove("luarocks-dev-1.rockspec")) + assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) + assert.is_true(os.remove("testrock-dev-1.rockspec")) end) it("LuaRocks write_rockspec rockspec via http", function() diff --git a/test/luarocks_site.lua b/test/luarocks_site.lua deleted file mode 100644 index cfa77dca..00000000 --- a/test/luarocks_site.lua +++ /dev/null @@ -1,6 +0,0 @@ --- Config file of LuaRocks site for tests -upload = { - server = "http://localhost:8080", - tool_version = "1.0.0", - api_version = "1", -} \ No newline at end of file diff --git a/test/mock-server.lua b/test/mock-server.lua deleted file mode 100644 index dbbdea2c..00000000 --- a/test/mock-server.lua +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env lua - ---- A simple LuaRocks mock-server for testing. -local restserver = require("restserver") -local server = restserver:new():port(8080) - -server:add_resource("api/tool_version", { - { - method = "GET", - path = "/", - produces = "application/json", - handler = function(query) - local json = { version = query.current } - return restserver.response():status(200):entity(json) - end - } -}) - -server:add_resource("api/1/{id:[0-9]+}/status", { - { - method = "GET", - path = "/", - produces = "application/json", - handler = function(query) - local json = { user_id = "123", created_at = "29.1.1993" } - return restserver.response():status(200):entity(json) - end - } -}) - -server:add_resource("/api/1/{id:[0-9]+}/check_rockspec", { - { - method = "GET", - path = "/", - produces = "application/json", - handler = function(query) - local json = {} - return restserver.response():status(200):entity(json) - end - } -}) - -server:add_resource("/api/1/{id:[0-9]+}/upload", { - { - method = "POST", - path = "/", - produces = "application/json", - handler = function(query) - local json = {module = "luasocket", version = {id = "1.0"}, module_url = "http://localhost/luasocket", manifests = "root", is_new = "is_new"} - return restserver.response():status(200):entity(json) - end - } -}) - -server:add_resource("/api/1/{id:[0-9]+}/upload_rock/{id:[0-9]+}", { - { - method = "POST", - path = "/", - produces = "application/json", - handler = function(query) - local json = {"rock","module_url"} - return restserver.response():status(200):entity(json) - end - } -}) - -server:add_resource("/file/{name:[^/]+}", { - { - method = "GET", - path = "/", - produces = "text/plain", - handler = function(query, name) - local fd = io.open("test/testfiles/"..name, "r") - if not fd then - return restserver.response():status(404) - end - local data = fd:read("*a") - fd:close() - return restserver.response():status(200):entity(data) - end - } -}) - --- SHUTDOWN this mock-server -server:add_resource("/shutdown", { - { - method = "GET", - path = "/", - handler = function(query) - os.exit() - return restserver.response():status(200):entity() - end - } -}) - --- This loads the restserver.xavante plugin -server:enable("restserver.xavante"):start() \ No newline at end of file diff --git a/test/test_environment.lua b/test/test_environment.lua deleted file mode 100644 index d347fa59..00000000 --- a/test/test_environment.lua +++ /dev/null @@ -1,781 +0,0 @@ -local lfs = require("lfs") -local test_env = {} - -local help_message = [[ -LuaRocks test-suite - -INFORMATION - New test-suite for LuaRocks project, using unit testing framework Busted. -REQUIREMENTS - Be sure sshd is running on your system, or use '--exclude-tags=ssh', - to not execute tests which require sshd. -USAGE - busted [-Xhelper ] -ARGUMENTS - env= Set type of environment to use ("minimal" or "full", - default: "minimal"). - noreset Don't reset environment after each test - clean Remove existing testing environment. - travis Add if running on TravisCI. - appveyor Add if running on Appveyor. - os= Set OS ("linux", "osx", or "windows"). - lua_dir= Path of Lua installation (default "/usr/local") - lua_interpreter= Name of the interpreter (default "lua") -]] - -local function help() - print(help_message) - os.exit(1) -end - -local function title(str) - print() - print(("-"):rep(#str)) - print(str) - print(("-"):rep(#str)) -end - -function test_env.exists(path) - return lfs.attributes(path, "mode") ~= nil -end - ---- Quote argument for shell processing. Fixes paths on Windows. --- Adds double quotes and escapes. Based on function in fs/win32.lua. --- @param arg string: Unquoted argument. --- @return string: Quoted argument. -local function Q(arg) - if test_env.TEST_TARGET_OS == "windows" then - local drive_letter = "[%.a-zA-Z]?:?[\\/]" - -- Quote DIR for Windows - if arg:match("^"..drive_letter) then - arg = arg:gsub("/", "\\") - end - - if arg == "\\" then - return '\\' -- CHDIR needs special handling for root dir - end - - return '"' .. arg .. '"' - else - return "'" .. arg:gsub("'", "'\\''") .. "'" - end -end - -function test_env.quiet(command) - if not test_env.VERBOSE then - if test_env.TEST_TARGET_OS == "windows" then - return command .. " 1> NUL 2> NUL" - else - return command .. " 1> /dev/null 2> /dev/null" - end - else - return command - end -end - -function test_env.copy(source, destination) - local r_source, err = io.open(source, "r") - local r_destination, err = io.open(destination, "w") - - while true do - local block = r_source:read(8192) - if not block then break end - r_destination:write(block) - end - - r_source:close() - r_destination:close() -end - ---- Helper function for execute_bool and execute_output --- @param command string: command to execute --- @param print_command boolean: print command if 'true' --- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"} --- @return final_command string: concatenated command to execution -function test_env.execute_helper(command, print_command, env_variables) - local final_command = "" - - if print_command then - print("[EXECUTING]: " .. command) - end - - if env_variables then - if test_env.TEST_TARGET_OS == "windows" then - for k,v in pairs(env_variables) do - final_command = final_command .. "set " .. k .. "=" .. v .. "&" - end - final_command = final_command:sub(1, -2) .. "&" - else - final_command = "export " - for k,v in pairs(env_variables) do - final_command = final_command .. k .. "='" .. v .. "' " - end - -- remove last space and add ';' to separate exporting variables from command - final_command = final_command:sub(1, -2) .. "; " - end - end - - final_command = final_command .. command .. " 2>&1" - - return final_command -end - ---- Execute command and returns true/false --- @return true/false boolean: status of the command execution -local function execute_bool(command, print_command, env_variables) - command = test_env.execute_helper(command, print_command, env_variables) - - local redirect_filename - local redirect = "" - if print_command ~= nil then - redirect_filename = test_env.testing_paths.luarocks_tmp.."/output.txt" - redirect = " > "..redirect_filename - os.remove(redirect_filename) - end - local ok = os.execute(command .. redirect) - ok = (ok == true or ok == 0) -- normalize Lua 5.1 output to boolean - if redirect ~= "" then - if not ok then - local fd = io.open(redirect_filename, "r") - if fd then - print(fd:read("*a")) - fd:close() - end - end - os.remove(redirect_filename) - end - return ok -end - ---- Execute command and returns output of command --- @return output string: output the command execution -local function execute_output(command, print_command, env_variables) - command = test_env.execute_helper(command, print_command, env_variables) - - local file = assert(io.popen(command)) - local output = file:read('*all') - file:close() - return output:gsub("\n","") -- output adding new line, need to be removed -end - ---- Set test_env.LUA_V or test_env.LUAJIT_V based --- on version of Lua used to run this script. -function test_env.set_lua_version() - if _G.jit then - test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d") - test_env.lua_version = "5.1" - else - test_env.LUA_V = _VERSION:match("5%.%d") - test_env.lua_version = test_env.LUA_V - end -end - ---- Set all arguments from input into global variables -function test_env.set_args() - -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables - test_env.TYPE_TEST_ENV = "minimal" - test_env.OPENSSL_DIRS = "" - test_env.RESET_ENV = true - - for _, argument in ipairs(arg) do - if argument:find("^env=") then - test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$") - elseif argument == "noreset" then - test_env.RESET_ENV = false - elseif argument == "clean" then - test_env.TEST_ENV_CLEAN = true - elseif argument == "verbose" then - test_env.VERBOSE = true - elseif argument == "travis" then - test_env.TRAVIS = true - elseif argument == "appveyor" then - test_env.APPVEYOR = true - test_env.OPENSSL_DIRS = "OPENSSL_LIBDIR=C:\\OpenSSL-Win32\\lib OPENSSL_INCDIR=C:\\OpenSSL-Win32\\include" - elseif argument:find("^os=") then - test_env.TEST_TARGET_OS = argument:match("^os=(.*)$") - elseif argument == "mingw" then - test_env.MINGW = true - elseif argument == "vs" then - test_env.MINGW = false - elseif argument:find("^lua_dir=") then - test_env.LUA_DIR = argument:match("^lua_dir=(.*)$") - elseif argument:find("^lua_interpreter=") then - test_env.LUA_INTERPRETER = argument:match("^lua_interpreter=(.*)$") - else - help() - end - end - - if not test_env.TEST_TARGET_OS then - title("OS CHECK") - - if execute_bool("sw_vers") then - test_env.TEST_TARGET_OS = "osx" - if test_env.TRAVIS then - test_env.OPENSSL_DIRS = "OPENSSL_LIBDIR=/usr/local/opt/openssl/lib OPENSSL_INCDIR=/usr/local/opt/openssl/include" - end - elseif execute_output("uname -s") == "Linux" then - test_env.TEST_TARGET_OS = "linux" - else - test_env.TEST_TARGET_OS = "windows" - end - end - return true -end - -function test_env.copy_dir(source_path, target_path) - local testing_paths = test_env.testing_paths - if test_env.TEST_TARGET_OS == "windows" then - execute_bool(testing_paths.win_tools .. "/cp -R ".. source_path .. "/. " .. target_path) - else - execute_bool("cp -a ".. source_path .. "/. " .. target_path) - end -end - ---- Remove directory recursively --- @param path string: directory path to delete -function test_env.remove_dir(path) - if test_env.exists(path) then - for file in lfs.dir(path) do - if file ~= "." and file ~= ".." then - local full_path = path..'/'..file - - if lfs.attributes(full_path, "mode") == "directory" then - test_env.remove_dir(full_path) - else - os.remove(full_path) - end - end - end - end - lfs.rmdir(path) -end - ---- Remove subdirectories of a directory that match a pattern --- @param path string: path to directory --- @param pattern string: pattern matching basenames of subdirectories to be removed -function test_env.remove_subdirs(path, pattern) - if test_env.exists(path) then - for file in lfs.dir(path) do - if file ~= "." and file ~= ".." then - local full_path = path..'/'..file - - if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then - test_env.remove_dir(full_path) - end - end - end - end -end - ---- Remove files matching a pattern --- @param path string: directory where to delete files --- @param pattern string: pattern matching basenames of files to be deleted --- @return result_check boolean: true if one or more files deleted -function test_env.remove_files(path, pattern) - local result_check = false - if test_env.exists(path) then - for file in lfs.dir(path) do - if file ~= "." and file ~= ".." then - if file:find(pattern) then - if os.remove(path .. "/" .. file) then - result_check = true - end - end - end - end - end - return result_check -end - - ---- Function for downloading rocks and rockspecs --- @param urls table: array of full names of rocks/rockspecs to download --- @param save_path string: path to directory, where to download rocks/rockspecs --- @return make_manifest boolean: true if new rocks downloaded -local function download_rocks(urls, save_path) - local luarocks_repo = "https://luarocks.org" - local make_manifest = false - - for _, url in ipairs(urls) do - -- check if already downloaded - if not test_env.exists(save_path .. url) then - if test_env.TEST_TARGET_OS == "windows" then - execute_bool(test_env.testing_paths.win_tools .. "/wget -cP " .. save_path .. " " .. luarocks_repo .. url .. " --no-check-certificate") - else - execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) - end - make_manifest = true - end - end - return make_manifest -end - ---- Create a file containing a string. --- @param path string: path to file. --- @param str string: content of the file. -local function write_file(path, str) - local file = assert(io.open(path, "w")) - file:write(str) - file:close() -end - ---- Create md5sum of directory structure recursively, based on filename and size --- @param path string: path to directory for generate md5sum --- @return md5sum string: md5sum of directory -local function hash_environment(path) - if test_env.TEST_TARGET_OS == "linux" then - return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") - elseif test_env.TEST_TARGET_OS == "osx" then - return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") - elseif test_env.TEST_TARGET_OS == "windows" then - return execute_output("\"" .. Q(test_env.testing_paths.win_tools .. "/find") .. " " .. Q(path) - .. " -printf \"%s %p\"\" > temp_sum.txt && certUtil -hashfile temp_sum.txt && del temp_sum.txt") - end -end - ---- Create environment variables needed for tests --- @param testing_paths table: table with paths to testing directory --- @return env_variables table: table with created environment variables -local function create_env(testing_paths) - local luaversion_short = _VERSION:gsub("Lua ", "") - - if test_env.LUAJIT_V then - luaversion_short="5.1" - end - - local env_variables = {} - env_variables.LUA_VERSION = luaversion_short - env_variables.LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua" - if test_env.TEST_TARGET_OS == "windows" then - env_variables.LUA_PATH = testing_paths.testing_lrprefix .. "\\lua\\?.lua;" - else - env_variables.LUA_PATH = testing_paths.testing_lrprefix .. "/share/lua/" .. luaversion_short .. "/?.lua;" - end - env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" - env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" - env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" - env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" - env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" - env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" - .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" - env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;" - - return env_variables -end - ---- Create md5sums of origin system and system-copy testing directory --- @param testing_paths table: table with paths to testing directory --- @return md5sums table: table of md5sums of system and system-copy testing directory -local function create_md5sums(testing_paths) - local md5sums = {} - md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy) - md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy) - - return md5sums -end - -local function make_run_function(cmd_name, exec_function, with_coverage, do_print) - local cmd_prefix = Q(test_env.testing_paths.lua) .. " " - - if with_coverage then - cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testing_dir .. "/luacov.config')\" " - end - - if test_env.TEST_TARGET_OS == "windows" then - cmd_prefix = cmd_prefix .. Q(test_env.testing_paths.testing_lrprefix .. "/" .. cmd_name .. ".lua") .. " " - else - cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " - end - - return function(cmd, new_vars) - local temp_vars = {} - for k, v in pairs(test_env.env_variables) do - temp_vars[k] = v - end - if new_vars then - for k, v in pairs(new_vars) do - temp_vars[k] = v - end - end - return exec_function(cmd_prefix .. cmd, do_print, temp_vars) - end -end - -local function make_run_functions() - return { - luarocks = make_run_function("luarocks", execute_output, true, true), - luarocks_bool = make_run_function("luarocks", execute_bool, true, true), - luarocks_noprint = make_run_function("luarocks", execute_bool, true, false), - luarocks_nocov = make_run_function("luarocks", execute_bool, false, true), - luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false), - luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true), - luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true), - luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false) - } -end - ---- Rebuild environment. --- Remove old installed rocks and install new ones, --- updating manifests and tree copies. -local function build_environment(rocks, env_variables) - title("BUILDING ENVIRONMENT") - local testing_paths = test_env.testing_paths - test_env.remove_dir(testing_paths.testing_tree) - test_env.remove_dir(testing_paths.testing_sys_tree) - test_env.remove_dir(testing_paths.testing_tree_copy) - test_env.remove_dir(testing_paths.testing_sys_tree_copy) - - lfs.mkdir(testing_paths.testing_tree) - lfs.mkdir(testing_paths.testing_sys_tree) - - test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_server)) - test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_cache)) - - for _, rock in ipairs(rocks) do - if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. Q(rock), env_variables) then - test_env.run.luarocks_nocov("build --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock) .. "", env_variables) - test_env.run.luarocks_nocov("pack --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables) - if test_env.TEST_TARGET_OS == "windows" then - execute_bool(testing_paths.win_tools .. "/mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) - else - execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) - end - end - end - - test_env.copy_dir(testing_paths.testing_tree, testing_paths.testing_tree_copy) - test_env.copy_dir(testing_paths.testing_sys_tree, testing_paths.testing_sys_tree_copy) -end - ---- Reset testing environment -local function reset_environment(testing_paths, md5sums) - local testing_tree_md5 = hash_environment(testing_paths.testing_tree) - local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree) - - if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then - test_env.remove_dir(testing_paths.testing_tree) - test_env.copy_dir(testing_paths.testing_tree_copy, testing_paths.testing_tree) - end - - if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then - test_env.remove_dir(testing_paths.testing_sys_tree) - test_env.copy_dir(testing_paths.testing_sys_tree_copy, testing_paths.testing_sys_tree) - end -end - -local function create_paths(luaversion_full) - - local testing_paths = {} - testing_paths.luadir = (test_env.LUA_DIR or "/usr/local") - testing_paths.lua = testing_paths.luadir .. "/bin/" .. (test_env.LUA_INTERPRETER or "lua") - - if test_env.TEST_TARGET_OS == "windows" then - testing_paths.luarocks_tmp = os.getenv("TEMP") - else - testing_paths.luarocks_tmp = "/tmp/luarocks_testing" - end - - testing_paths.luarocks_dir = lfs.currentdir() - - if test_env.TEST_TARGET_OS == "windows" then - testing_paths.luarocks_dir = testing_paths.luarocks_dir:gsub("\\","/") - end - - testing_paths.testing_dir = testing_paths.luarocks_dir .. "/test" - testing_paths.src_dir = testing_paths.luarocks_dir .. "/src" - testing_paths.testing_lrprefix = testing_paths.testing_dir .. "/testing_lrprefix-" .. luaversion_full - testing_paths.testing_tree = testing_paths.testing_dir .. "/testing-" .. luaversion_full - testing_paths.testing_tree_copy = testing_paths.testing_dir .. "/testing_copy-" .. luaversion_full - testing_paths.testing_sys_tree = testing_paths.testing_dir .. "/testing_sys-" .. luaversion_full - testing_paths.testing_sys_tree_copy = testing_paths.testing_dir .. "/testing_sys_copy-" .. luaversion_full - testing_paths.testing_cache = testing_paths.testing_dir .. "/testing_cache-" .. luaversion_full - testing_paths.testing_server = testing_paths.testing_dir .. "/testing_server-" .. luaversion_full - - testing_paths.testing_rocks = testing_paths.testing_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version - testing_paths.testing_sys_rocks = testing_paths.testing_sys_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version - - if test_env.TEST_TARGET_OS == "windows" then - testing_paths.win_tools = testing_paths.testing_lrprefix .. "/tools" - end - - return testing_paths -end - ---- Helper function to unload luarocks modules from global table package.loaded --- Needed to load our local (testing) version of LuaRocks -function test_env.unload_luarocks() - for modname, _ in pairs(package.loaded) do - if modname:match("^luarocks%.") then - package.loaded[modname] = nil - end - end -end - ---- Function for initially setup of environment, variables, md5sums for spec files -function test_env.setup_specs(extra_rocks) - -- if global variable about successful creation of testing environment doesn't exist, build environment - if not test_env.setup_done then - if test_env.TRAVIS then - if not test_env.exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then - execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") - execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") - execute_bool("chmod og-wx ~/.ssh/authorized_keys") - execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts") - end - end - - test_env.main() - package.path = test_env.env_variables.LUA_PATH - - test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables) - test_env.lib_extension = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').lib_extension)\"", false, test_env.env_variables) - test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" - test_env.md5sums = create_md5sums(test_env.testing_paths) - test_env.setup_done = true - title("RUNNING TESTS") - end - - if extra_rocks then - local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) - if make_manifest then - test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) - end - end - - if test_env.RESET_ENV then - reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) - end -end - ---- Test if required rock is installed and if not, install it. --- Return `true` if the rock is already installed or has been installed successfully, --- `false` if installation failed. -function test_env.need_rock(rock) - print("Check if " .. rock .. " is installed") - if test_env.run.luarocks_noprint_nocov(test_env.quiet("show " .. rock)) then - return true - else - return test_env.run.luarocks_noprint_nocov(test_env.quiet("install " .. rock)) - end -end - ---- For each key-value pair in replacements table --- replace %{key} in given string with value. -local function substitute(str, replacements) - return (str:gsub("%%%b{}", function(marker) - return replacements[marker:sub(3, -2)] - end)) -end - - ---- Create configs for luacov and several versions of Luarocks --- configs needed for some tests. -local function create_configs() - -- testing_config.lua and testing_config_show_downloads.lua - local config_content = substitute([[ - rocks_trees = { - "%{testing_tree}", - { name = "system", root = "%{testing_sys_tree}" }, - } - rocks_servers = { - "%{testing_server}" - } - local_cache = "%{testing_cache}" - upload_server = "testing" - upload_user = "%{user}" - upload_servers = { - testing = { - rsync = "localhost/tmp/luarocks_testing", - }, - } - external_deps_dirs = { - "/usr/local", - "/usr", - -- These are used for a test that fails, so it - -- can point to invalid paths: - { - prefix = "/opt", - bin = "bin", - include = "include", - lib = { "lib", "lib64" }, - } - } - ]], { - user = os.getenv("USER"), - testing_sys_tree = test_env.testing_paths.testing_sys_tree, - testing_tree = test_env.testing_paths.testing_tree, - testing_server = test_env.testing_paths.testing_server, - testing_cache = test_env.testing_paths.testing_cache - }) - - write_file(test_env.testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") - write_file(test_env.testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content - .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") - - -- testing_config_sftp.lua - config_content = substitute([[ - rocks_trees = { - "%{testing_tree}", - "%{testing_sys_tree}", - } - local_cache = "%{testing_cache}" - upload_server = "testing" - upload_user = "%{user}" - upload_servers = { - testing = { - sftp = "localhost/tmp/luarocks_testing", - }, - } - ]], { - user = os.getenv("USER"), - testing_sys_tree = test_env.testing_paths.testing_sys_tree, - testing_tree = test_env.testing_paths.testing_tree, - testing_cache = test_env.testing_paths.testing_cache - }) - - write_file(test_env.testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) - - -- luacov.config - config_content = substitute([[ - return { - statsfile = "%{testing_dir}/luacov.stats.out", - reportfile = "%{testing_dir}/luacov.report.out", - modules = { - ["luarocks"] = "src/bin/luarocks", - ["luarocks-admin"] = "src/bin/luarocks-admin", - ["luarocks.*"] = "src", - ["luarocks.*.*"] = "src", - ["luarocks.*.*.*"] = "src" - } - } - ]], { - testing_dir = test_env.testing_paths.testing_dir - }) - - write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content) -end - ---- Remove testing directories. -local function clean() - print("Cleaning testing directory...") - test_env.remove_dir(test_env.testing_paths.luarocks_tmp) - test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]") - test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") - test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") - test_env.remove_files(test_env.testing_paths.testing_dir, "upload_config") - print("Cleaning done!") -end - ---- Install luarocks into testing prefix. -local function install_luarocks(install_env_vars) - local testing_paths = test_env.testing_paths - title("Installing LuaRocks") - if test_env.TEST_TARGET_OS == "windows" then - local compiler_flag = test_env.MINGW and "/MW" or "" - assert(execute_bool("install.bat /LUA " .. testing_paths.luadir .. " " .. compiler_flag .. " /P " .. testing_paths.testing_lrprefix .. " /NOREG /NOADMIN /F /Q /CONFIG " .. testing_paths.testing_lrprefix .. "/etc/luarocks", false, install_env_vars)) - assert(execute_bool(testing_paths.win_tools .. "/cp " .. testing_paths.testing_lrprefix .. "/lua/luarocks/core/site_config* " .. testing_paths.src_dir .. "/luarocks/core")) - else - local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix - assert(execute_bool(configure_cmd, false, install_env_vars)) - assert(execute_bool("make clean", false, install_env_vars)) - assert(execute_bool("make src/luarocks/core/site_config_"..test_env.lua_version:gsub("%.", "_")..".lua", false, install_env_vars)) - assert(execute_bool("make dev", false, install_env_vars)) - end - print("LuaRocks installed correctly!") -end - -function test_env.mock_server_extra_rocks(more) - local rocks = { - -- rocks needed for mock-server - "/copas-2.0.1-1.src.rock", - "/coxpcall-1.16.0-1.src.rock", - "/dkjson-2.5-2.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", - "/restserver-0.1-1.src.rock", - "/restserver-xavante-0.2-1.src.rock", - "/rings-1.3.0-1.src.rock", - "/wsapi-1.6.1-1.src.rock", - "/wsapi-xavante-1.6.1-1.src.rock", - "/xavante-2.4.0-1.src.rock" - } - if more then - for _, rock in ipairs(more) do - table.insert(rocks, rock) - end - end - return rocks -end - -function test_env.mock_server_init() - local assert = require("luassert") - local testing_paths = test_env.testing_paths - assert.is_true(test_env.need_rock("restserver-xavante")) - local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.testing_dir .. "/mock-server.lua &", true, test_env.env_variables) - os.execute(final_command) -end - -function test_env.mock_server_done() - os.execute("curl localhost:8080/shutdown") -end - ---- --- Main function to create config files and testing environment -function test_env.main() - local testing_paths = test_env.testing_paths - - if test_env.TEST_ENV_CLEAN then - clean() - end - - lfs.mkdir(testing_paths.testing_cache) - lfs.mkdir(testing_paths.luarocks_tmp) - - create_configs() - - local install_env_vars = { - LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua" - } - - install_luarocks(install_env_vars) - - -- Preparation of rocks for building environment - local rocks = {} -- names of rocks, required for building environment - local urls = {} -- names of rock and rockspec files to be downloaded - table.insert(urls, "/luacov-0.11.0-1.rockspec") - table.insert(urls, "/luacov-0.11.0-1.src.rock") - - if test_env.TYPE_TEST_ENV == "full" then - table.insert(urls, "/luafilesystem-1.6.3-1.src.rock") - table.insert(urls, "/luasocket-3.0rc1-1.src.rock") - table.insert(urls, "/luasocket-3.0rc1-1.rockspec") - table.insert(urls, "/luaposix-33.2.1-1.src.rock") - table.insert(urls, "/md5-1.2-1.src.rock") - table.insert(urls, "/lzlib-0.4.1.53-1.src.rock") - rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} - - if test_env.LUA_V ~= "5.1" then - table.insert(urls, "/luabitop-1.0.2-1.rockspec") - table.insert(urls, "/luabitop-1.0.2-1.src.rock") - table.insert(rocks, "luabitop") - end - end - - table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment - - -- Download rocks needed for LuaRocks testing environment - lfs.mkdir(testing_paths.testing_server) - download_rocks(urls, testing_paths.testing_server) - build_environment(rocks, install_env_vars) -end - -test_env.set_lua_version() -test_env.set_args() -test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) -test_env.env_variables = create_env(test_env.testing_paths) -test_env.run = make_run_functions() - -return test_env diff --git a/test/testfiles/a_rock-1.0-1.rockspec b/test/testfiles/a_rock-1.0-1.rockspec deleted file mode 100644 index 9f15e87a..00000000 --- a/test/testfiles/a_rock-1.0-1.rockspec +++ /dev/null @@ -1,17 +0,0 @@ -package = "a_rock" -version = "1.0-1" -source = { - url = "http://localhost:8080/file/a_rock.lua" -} -description = { - summary = "An example rockspec", -} -dependencies = { - "lua >= 5.1" -} -build = { - type = "builtin", - modules = { - build = "a_rock.lua" - }, -} diff --git a/test/testfiles/a_rock.lua b/test/testfiles/a_rock.lua deleted file mode 100644 index a5647075..00000000 --- a/test/testfiles/a_rock.lua +++ /dev/null @@ -1 +0,0 @@ -return {} diff --git a/test/testfiles/invalid_patch-0.1-1.rockspec b/test/testfiles/invalid_patch-0.1-1.rockspec deleted file mode 100644 index c2ecd160..00000000 --- a/test/testfiles/invalid_patch-0.1-1.rockspec +++ /dev/null @@ -1,29 +0,0 @@ -package = "invalid_patch" -version = "0.1-1" -source = { - -- any valid URL - url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua" -} -description = { - summary = "A rockspec with an invalid patch", -} -dependencies = { - "lua >= 5.1" -} -build = { - type = "builtin", - modules = { - build = "build.lua" - }, - patches = { - ["I_am_an_invalid_patch.patch"] = -[[ -diff -Naur luadoc-3.0.1/src/luadoc/doclet/html.lua luadoc-3.0.1-new/src/luadoc/doclet/html.lua ---- luadoc-3.0.1/src/luadoc/doclet/html.lua2007-12-21 15:50:48.000000000 -0200 -+++ luadoc-3.0.1-new/src/luadoc/doclet/html.lua2008-02-28 01:59:53.000000000 -0300 -@@ -18,6 +18,7 @@ -- gabba gabba gabba -+ gobo gobo gobo -]] - } -} diff --git a/test/testfiles/invalid_validate-args-1.5.4-1.rockspec b/test/testfiles/invalid_validate-args-1.5.4-1.rockspec deleted file mode 100644 index 0b4d807d..00000000 --- a/test/testfiles/invalid_validate-args-1.5.4-1.rockspec +++ /dev/null @@ -1,35 +0,0 @@ -package = 'validate-args' -version = '1.5.4-1' -source = {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{++{ - url = "https://bitbucket.org/djerius/validate.args/downloads/validate-args-1.5.4.tar.gz" -} - -description = { - summary = "Function argument validation", - detailed = [[ - validate.args is a Lua module that provides a framework for - validation of arguments to Lua functions as well as complex data - structures. The included validate.inplace module provides "live" - validation during assignment of values to elements in tables. ]], - license = "GPL-3", - -} - -dependencies = { - "lua >= 5.1" -} - -build = { - - type = "builtin", - - modules = { - ["validate.args"] = "validate/args.lua", - ["validate.inplace"] = "validate/inplace.lua", - }, - - copy_directories = { - "doc", "tests" - } - -} diff --git a/test/testfiles/luajit-fail-1.0-1.rockspec b/test/testfiles/luajit-fail-1.0-1.rockspec deleted file mode 100644 index f8204600..00000000 --- a/test/testfiles/luajit-fail-1.0-1.rockspec +++ /dev/null @@ -1,22 +0,0 @@ -package = "luajit-fail" -version = "1.0-1" -source = { - url = "https://raw.githubusercontent.com/keplerproject/luarocks/master/test/testing.lua", -} -description = { - summary = "Test luajit dependency fail", - detailed = [[ -Fail luajit dependency when running with rockspec_format < 3.0. -]], - homepage = "http://luarocks.org/", - license = "MIT/X license" -} -dependencies = { - "luajit >= 2.0" -} -build = { - type = "builtin", - modules = { - testing = "testing.lua" - } -} diff --git a/test/testfiles/luajit-success-1.0-1.rockspec b/test/testfiles/luajit-success-1.0-1.rockspec deleted file mode 100644 index 31c930c3..00000000 --- a/test/testfiles/luajit-success-1.0-1.rockspec +++ /dev/null @@ -1,23 +0,0 @@ -rockspec_format = "3.0" -package = "luajit-success" -version = "1.0-1" -source = { - url = "https://raw.githubusercontent.com/keplerproject/luarocks/master/test/testing.lua", -} -description = { - summary = "Test luajit dependency fail", - detailed = [[ -Use luajit dependency when running with rockspec_format >= 3.0. -]], - homepage = "http://luarocks.org/", - license = "MIT/X license" -} -dependencies = { - "luajit >= 2.0" -} -build = { - type = "builtin", - modules = { - testing = "testing.lua" - } -} diff --git a/test/testfiles/missing_external-0.1-1.rockspec b/test/testfiles/missing_external-0.1-1.rockspec deleted file mode 100644 index 5f8e6219..00000000 --- a/test/testfiles/missing_external-0.1-1.rockspec +++ /dev/null @@ -1,24 +0,0 @@ -package = "missing_external" -version = "0.1-1" -source = { - -- any valid URL - url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua" -} -description = { - summary = "Missing external dependency", -} -external_dependencies = { - INEXISTENT = { - library = "inexistentlib*", - header = "inexistentheader*.h", - } -} -dependencies = { - "lua >= 5.1" -} -build = { - type = "builtin", - modules = { - build = "build.lua" - } -} diff --git a/test/testfiles/mixed_deploy_type/mdt.c b/test/testfiles/mixed_deploy_type/mdt.c deleted file mode 100644 index a162ce23..00000000 --- a/test/testfiles/mixed_deploy_type/mdt.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "lua.h" - -int luaopen_mdt(lua_State *L) { - lua_pushstring(L, "mdt.c"); - return 1; -} diff --git a/test/testfiles/mixed_deploy_type/mdt.lua b/test/testfiles/mixed_deploy_type/mdt.lua deleted file mode 100644 index c9ca9c68..00000000 --- a/test/testfiles/mixed_deploy_type/mdt.lua +++ /dev/null @@ -1 +0,0 @@ -return "mdt.lua" diff --git a/test/testfiles/mixed_deploy_type/mdt_file b/test/testfiles/mixed_deploy_type/mdt_file deleted file mode 100644 index 1a15f7d7..00000000 --- a/test/testfiles/mixed_deploy_type/mdt_file +++ /dev/null @@ -1 +0,0 @@ -return "mdt_file" diff --git a/test/testfiles/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec b/test/testfiles/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec deleted file mode 100644 index 91b725da..00000000 --- a/test/testfiles/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec +++ /dev/null @@ -1,21 +0,0 @@ -package = "mixed_deploy_type" -version = "0.1.0-1" -source = { - url = "http://example.com" -} -description = { - homepage = "http://example.com", - license = "*** please specify a license ***" -} -dependencies = {} -build = { - type = "builtin", - modules = { - mdt = "mdt/mdt.lua" - }, - install = { - lua = { - mdt_file = "mdt/mdt_file" - } - } -} diff --git a/test/testfiles/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec b/test/testfiles/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec deleted file mode 100644 index 9ca03180..00000000 --- a/test/testfiles/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec +++ /dev/null @@ -1,21 +0,0 @@ -package = "mixed_deploy_type" -version = "0.2.0-1" -source = { - url = "http://example.com" -} -description = { - homepage = "http://example.com", - license = "*** please specify a license ***" -} -dependencies = {} -build = { - type = "builtin", - modules = { - mdt = "mdt/mdt.c" - }, - install = { - lib = { - mdt_file = "mdt/mdt_file" - } - } -} diff --git a/test/testfiles/no_build_table-0.1-1.rockspec b/test/testfiles/no_build_table-0.1-1.rockspec deleted file mode 100644 index 5d79e9a0..00000000 --- a/test/testfiles/no_build_table-0.1-1.rockspec +++ /dev/null @@ -1,12 +0,0 @@ -package = "no_build_table" -version = "0.1-1" -source = { - -- any valid URL - url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua" -} -description = { - summary = "A rockspec with no build field", -} -dependencies = { - "lua >= 5.1" -} diff --git a/test/testfiles/not_a_zipfile-1.0-1.src.rock b/test/testfiles/not_a_zipfile-1.0-1.src.rock deleted file mode 100644 index e36f8bbe..00000000 --- a/test/testfiles/not_a_zipfile-1.0-1.src.rock +++ /dev/null @@ -1 +0,0 @@ -I am not a .zip file! diff --git a/test/testfiles/patch_create_delete-0.1-1.rockspec b/test/testfiles/patch_create_delete-0.1-1.rockspec deleted file mode 100644 index 069e2912..00000000 --- a/test/testfiles/patch_create_delete-0.1-1.rockspec +++ /dev/null @@ -1,34 +0,0 @@ -rockspec_format = "3.0" -package = "patch_create_delete" -version = "0.1-1" -source = { - -- any valid URL - url = "git://github.com/luarocks/luarocks" -} -description = { - summary = "A rockspec with a patch that creates and deletes files", -} -dependencies = { - "lua >= 5.1" -} -build = { - type = "builtin", - modules = { - ["luarocks.loader"] = "src/luarocks/loader.lua" - }, - patches = { - ["create_delete.patch"] = -[[ -diff -Naur luarocks/test/testfiles/patch_create_delete/a_file.txt luarocks-patch/test/testfiles/patch_create_delete/a_file.txt ---- luarocks/test/testfiles/patch_create_delete/a_file.txt 2017-10-04 15:39:44.179306674 -0300 -+++ luarocks-patch/test/testfiles/patch_create_delete/a_file.txt 1969-12-31 21:00:00.000000000 -0300 -@@ -1 +0,0 @@ --I am a file. -diff -Naur luarocks/test/testfiles/patch_create_delete/another_file.txt luarocks-patch/test/testfiles/patch_create_delete/another_file.txt ---- luarocks/test/testfiles/patch_create_delete/another_file.txt 1969-12-31 21:00:00.000000000 -0300 -+++ luarocks-patch/test/testfiles/patch_create_delete/another_file.txt 2017-10-04 15:40:12.836306564 -0300 -@@ -0,0 +1 @@ -+I am another file. -]] - } -} diff --git a/test/testfiles/patch_create_delete/a_file.txt b/test/testfiles/patch_create_delete/a_file.txt deleted file mode 100644 index 6539c24e..00000000 --- a/test/testfiles/patch_create_delete/a_file.txt +++ /dev/null @@ -1 +0,0 @@ -I am a file. diff --git a/test/testfiles/type_mismatch_string-1.0-1.rockspec b/test/testfiles/type_mismatch_string-1.0-1.rockspec deleted file mode 100644 index 7a607cfd..00000000 --- a/test/testfiles/type_mismatch_string-1.0-1.rockspec +++ /dev/null @@ -1,4 +0,0 @@ - -package="type_mismatch_version" -version=1.0 - diff --git a/test/testfiles/type_mismatch_table-1.0-1.rockspec b/test/testfiles/type_mismatch_table-1.0-1.rockspec deleted file mode 100644 index f348b798..00000000 --- a/test/testfiles/type_mismatch_table-1.0-1.rockspec +++ /dev/null @@ -1,5 +0,0 @@ - -package="type_mismatch_table" -version="1.0-1" - -source = "not a table" diff --git a/test/testfiles/type_mismatch_version-1.0-1.rockspec b/test/testfiles/type_mismatch_version-1.0-1.rockspec deleted file mode 100644 index 5e30dae6..00000000 --- a/test/testfiles/type_mismatch_version-1.0-1.rockspec +++ /dev/null @@ -1,4 +0,0 @@ - -package="type_mismatch_version" -version="1.0" - diff --git a/test/testfiles/with_external_dep-0.1-1.rockspec b/test/testfiles/with_external_dep-0.1-1.rockspec deleted file mode 100644 index 45fea4bd..00000000 --- a/test/testfiles/with_external_dep-0.1-1.rockspec +++ /dev/null @@ -1,25 +0,0 @@ -package = "with_external_dep" -version = "0.1-1" -source = { - url = "http://localhost:8080/file/with_external_dep.c" -} -description = { - summary = "An example rockspec", -} -external_dependencies = { - FOO = { - header = "foo/foo.h" - } -} -dependencies = { - "lua >= 5.1" -} -build = { - type = "builtin", - modules = { - with_external_dep = { - sources = "with_external_dep.c", - incdirs = "$(FOO_INCDIR)", - } - } -} diff --git a/test/testfiles/with_external_dep.c b/test/testfiles/with_external_dep.c deleted file mode 100644 index 16435d8f..00000000 --- a/test/testfiles/with_external_dep.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include - -int luaopen_with_external_dep(lua_State* L) { - lua_newtable(L); - lua_pushinteger(L, FOO); - lua_setfield(L, -2, "foo"); - return 1; -} diff --git a/test/testfiles/with_external_dep/foo/foo.h b/test/testfiles/with_external_dep/foo/foo.h deleted file mode 100644 index eedd558f..00000000 --- a/test/testfiles/with_external_dep/foo/foo.h +++ /dev/null @@ -1 +0,0 @@ -#define FOO 42 diff --git a/test/testfiles/with_external_dep/foo/foo.h.gch b/test/testfiles/with_external_dep/foo/foo.h.gch deleted file mode 100644 index 66165c9e..00000000 Binary files a/test/testfiles/with_external_dep/foo/foo.h.gch and /dev/null differ -- cgit v1.2.3-55-g6feb