diff options
| author | Hisham <hisham@gobolinux.org> | 2016-07-28 17:24:15 -0300 |
|---|---|---|
| committer | Hisham <hisham@gobolinux.org> | 2016-07-28 17:24:15 -0300 |
| commit | accce73cf90bde70baa3d8101b76ca56b0cb0720 (patch) | |
| tree | 705bb1ba44cd07f9b701cb8d6cf969d7bb48fd72 | |
| parent | 5f5b26206068ba597091bb6fc22d8d63c0fef408 (diff) | |
| parent | 67a737310b31eed8d1c38eb0e34ff4b6fc411731 (diff) | |
| download | luarocks-accce73cf90bde70baa3d8101b76ca56b0cb0720.tar.gz luarocks-accce73cf90bde70baa3d8101b76ca56b0cb0720.tar.bz2 luarocks-accce73cf90bde70baa3d8101b76ca56b0cb0720.zip | |
Merge branch 'master' into luarocks-3
40 files changed, 2480 insertions, 1199 deletions
diff --git a/.busted b/.busted new file mode 100644 index 00000000..29a8137b --- /dev/null +++ b/.busted | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | return { | ||
| 2 | default = { | ||
| 3 | helper = "test/test_environment", | ||
| 4 | ["auto-insulate"] = false | ||
| 5 | } | ||
| 6 | } | ||
diff --git a/.travis.yml b/.travis.yml index f946bb99..02bdb6c9 100644 --- a/.travis.yml +++ b/.travis.yml | |||
| @@ -1,14 +1,65 @@ | |||
| 1 | language: c | 1 | language: python |
| 2 | 2 | ||
| 3 | compiler: gcc | 3 | matrix: |
| 4 | include: | ||
| 5 | - os: linux | ||
| 6 | env: | ||
| 7 | - LUA="lua=5.1" | ||
| 8 | - os: linux | ||
| 9 | env: | ||
| 10 | - LUA="lua=5.2" | ||
| 11 | - os: linux | ||
| 12 | env: | ||
| 13 | - LUA="lua=5.3" | ||
| 14 | - os: linux | ||
| 15 | env: | ||
| 16 | - LUA="luajit=2.0" | ||
| 17 | - os: linux | ||
| 18 | env: | ||
| 19 | - LUA="luajit=2.1" | ||
| 20 | - os: osx | ||
| 21 | language: generic | ||
| 22 | env: | ||
| 23 | - LUA="lua=5.1" | ||
| 24 | - os: osx | ||
| 25 | language: generic | ||
| 26 | env: | ||
| 27 | - LUA="lua=5.2" | ||
| 28 | - os: osx | ||
| 29 | language: generic | ||
| 30 | env: | ||
| 31 | - LUA="lua=5.3" | ||
| 32 | - os: osx | ||
| 33 | language: generic | ||
| 34 | env: | ||
| 35 | - LUA="luajit=2.0" | ||
| 36 | - os: osx | ||
| 37 | language: generic | ||
| 38 | env: | ||
| 39 | - LUA="luajit=2.1" | ||
| 4 | 40 | ||
| 5 | sudo: false | ||
| 6 | 41 | ||
| 7 | env: | 42 | before_install: |
| 8 | matrix: | 43 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install python; fi |
| 9 | - LUA_VER=5.1.5 | 44 | - pip install hererocks |
| 10 | - LUA_VER=5.2.4 | 45 | - hererocks lua_install -r^ --$LUA |
| 11 | - LUA_VER=5.3.1 | 46 | - export PATH=$PATH:$PWD/lua_install/bin # Add directory with all installed binaries to PATH |
| 12 | - LUA_VER=jit-2.0.4 | ||
| 13 | 47 | ||
| 14 | script: cd test && ./testing.sh --travis --lua $LUA_VER | 48 | install: |
| 49 | - luarocks install busted | ||
| 50 | - luarocks install luacov | ||
| 51 | - luarocks install luacov-coveralls | ||
| 52 | |||
| 53 | script: | ||
| 54 | - busted -Xhelper travis --verbose | ||
| 55 | - busted -Xhelper travis,env=full --verbose | ||
| 56 | |||
| 57 | after_success: | ||
| 58 | - luacov-coveralls -c $TRAVIS_BUILD_DIR/test/luacov.config --exclude $TRAVIS_BUILD_DIR/test/ | ||
| 59 | - luacov -c $TRAVIS_BUILD_DIR/test/luacov.config | ||
| 60 | - grep "Summary" -B1 -A1000 $TRAVIS_BUILD_DIR/test/luacov.report.out | ||
| 61 | |||
| 62 | notifications: | ||
| 63 | email: | ||
| 64 | on_success: change | ||
| 65 | on_failure: change | ||
diff --git a/spec/add_spec.lua b/spec/add_spec.lua new file mode 100644 index 00000000..dca6f850 --- /dev/null +++ b/spec/add_spec.lua | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | local testing_paths = test_env.testing_paths | ||
| 4 | |||
| 5 | test_env.unload_luarocks() | ||
| 6 | |||
| 7 | local extra_rocks = { | ||
| 8 | "/luasocket-3.0rc1-1.src.rock", | ||
| 9 | "/luasocket-3.0rc1-1.rockspec" | ||
| 10 | } | ||
| 11 | |||
| 12 | describe("LuaRocks add tests #blackbox #b_add", function() | ||
| 13 | |||
| 14 | before_each(function() | ||
| 15 | test_env.setup_specs(extra_rocks) | ||
| 16 | end) | ||
| 17 | |||
| 18 | describe("LuaRocks-admin add tests", function() | ||
| 19 | it("LuaRocks-admin add invalid rock #ssh", function() | ||
| 20 | assert.is_false(run.luarocks_admin_bool("--server=testing add invalid")) | ||
| 21 | end) | ||
| 22 | |||
| 23 | it("LuaRocks-admin add missing argument", function() | ||
| 24 | assert.is_false(run.luarocks_admin_bool("--server=testing add")) | ||
| 25 | end) | ||
| 26 | |||
| 27 | it("LuaRocks-admin add invalid server", function() | ||
| 28 | assert.is_false(run.luarocks_admin_bool("--server=invalid add " .. testing_paths.testing_server .. "/luasocket-3.0rc1-1.src.rock")) | ||
| 29 | end) | ||
| 30 | |||
| 31 | it("LuaRocks-admin add invalid server #ssh", function() | ||
| 32 | assert.is_true(run.luarocks_admin_bool("--server=testing add " .. testing_paths.testing_server .. "/luasocket-3.0rc1-1.src.rock")) | ||
| 33 | end) | ||
| 34 | |||
| 35 | --TODO This test fails, sftp not implemented | ||
| 36 | it("LuaRocks-admin add invalid server", function() --? | ||
| 37 | assert.is_false(run.luarocks_admin_bool("--server=testing add luasocket-3.0rc1-1.src.rock", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_sftp.lua" } )) | ||
| 38 | end) | ||
| 39 | |||
| 40 | it("LuaRocks-admin add, split server url", function() | ||
| 41 | assert.is_false(run.luarocks_admin_bool("--server=\"localhost@/tmp/luarocks_testing\" add " .. testing_paths.testing_server .. "luasocket-3.0rc1-1.src.rock")) | ||
| 42 | end) | ||
| 43 | end) | ||
| 44 | end) | ||
diff --git a/spec/build_spec.lua b/spec/build_spec.lua new file mode 100644 index 00000000..2ede5211 --- /dev/null +++ b/spec/build_spec.lua | |||
| @@ -0,0 +1,181 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | local testing_paths = test_env.testing_paths | ||
| 5 | |||
| 6 | test_env.unload_luarocks() | ||
| 7 | |||
| 8 | local extra_rocks = { | ||
| 9 | "/lmathx-20120430.51-1.src.rock", | ||
| 10 | "/lmathx-20120430.51-1.rockspec", | ||
| 11 | "/lmathx-20120430.52-1.src.rock", | ||
| 12 | "/lmathx-20120430.52-1.rockspec", | ||
| 13 | "/lmathx-20150505-1.src.rock", | ||
| 14 | "/lmathx-20150505-1.rockspec", | ||
| 15 | "/lpeg-0.12-1.src.rock", | ||
| 16 | "/lpty-1.0.1-1.src.rock", | ||
| 17 | "/luadoc-3.0.1-1.src.rock", | ||
| 18 | "/luafilesystem-1.6.3-1.src.rock", | ||
| 19 | "/lualogging-1.3.0-1.src.rock", | ||
| 20 | "/luarepl-0.4-1.src.rock", | ||
| 21 | "/luasec-0.6-1.rockspec", | ||
| 22 | "/luasocket-3.0rc1-1.src.rock", | ||
| 23 | "/luasocket-3.0rc1-1.rockspec", | ||
| 24 | "/lxsh-0.8.6-2.src.rock", | ||
| 25 | "/lxsh-0.8.6-2.rockspec", | ||
| 26 | "/stdlib-41.0.0-1.src.rock", | ||
| 27 | "/validate-args-1.5.4-1.rockspec" | ||
| 28 | } | ||
| 29 | |||
| 30 | describe("LuaRocks build tests #blackbox #b_build", function() | ||
| 31 | |||
| 32 | before_each(function() | ||
| 33 | test_env.setup_specs(extra_rocks) | ||
| 34 | end) | ||
| 35 | |||
| 36 | describe("LuaRocks build - basic testing set", function() | ||
| 37 | it("LuaRocks build with no flags/arguments", function() | ||
| 38 | assert.is_false(run.luarocks_bool("build")) | ||
| 39 | end) | ||
| 40 | |||
| 41 | it("LuaRocks build invalid", function() | ||
| 42 | assert.is_false(run.luarocks_bool("build invalid")) | ||
| 43 | end) | ||
| 44 | end) | ||
| 45 | |||
| 46 | describe("LuaRocks build - building lpeg with flags", function() | ||
| 47 | it("LuaRocks build fail build permissions", function() | ||
| 48 | if test_env.TEST_TARGET_OS == "osx" or test_env.TEST_TARGET_OS == "linux" then | ||
| 49 | assert.is_false(run.luarocks_bool("build --tree=/usr lpeg")) | ||
| 50 | end | ||
| 51 | end) | ||
| 52 | |||
| 53 | it("LuaRocks build fail build permissions parent", function() | ||
| 54 | if test_env.TEST_TARGET_OS == "osx" or test_env.TEST_TARGET_OS == "linux" then | ||
| 55 | assert.is_false(run.luarocks_bool("build --tree=/usr/invalid lpeg")) | ||
| 56 | end | ||
| 57 | end) | ||
| 58 | |||
| 59 | it("LuaRocks build lpeg verbose", function() | ||
| 60 | assert.is.truthy(run.luarocks("build --verbose lpeg")) | ||
| 61 | end) | ||
| 62 | |||
| 63 | it("LuaRocks build lpeg branch=master", function() | ||
| 64 | assert.is_true(run.luarocks_bool("build --branch=master lpeg")) | ||
| 65 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 66 | end) | ||
| 67 | |||
| 68 | it("LuaRocks build lpeg deps-mode=123", function() | ||
| 69 | assert.is_false(run.luarocks_bool("build --deps-mode=123 lpeg")) | ||
| 70 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 71 | end) | ||
| 72 | |||
| 73 | it("LuaRocks build lpeg only-sources example", function() | ||
| 74 | assert.is_true(run.luarocks_bool("build --only-sources=\"http://example.com\" lpeg")) | ||
| 75 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 76 | end) | ||
| 77 | |||
| 78 | it("LuaRocks build lpeg with empty tree", function() | ||
| 79 | assert.is_false(run.luarocks_bool("build --tree=\"\" lpeg")) | ||
| 80 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 81 | end) | ||
| 82 | end) | ||
| 83 | |||
| 84 | describe("LuaRocks build - basic builds", function() | ||
| 85 | it("LuaRocks build luadoc", function() | ||
| 86 | assert.is_true(run.luarocks_bool(test_env.quiet("build luadoc"))) | ||
| 87 | end) | ||
| 88 | |||
| 89 | it("LuaRocks build luacov diff version", function() | ||
| 90 | assert.is_true(run.luarocks_bool("build luacov 0.11.0-1")) | ||
| 91 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luacov")) | ||
| 92 | end) | ||
| 93 | |||
| 94 | it("LuaRocks build command stdlib", function() | ||
| 95 | assert.is_true(run.luarocks_bool("build stdlib")) | ||
| 96 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/stdlib")) | ||
| 97 | end) | ||
| 98 | |||
| 99 | it("LuaRocks build install bin luarepl", function() | ||
| 100 | assert.is_true(run.luarocks_bool("build luarepl")) | ||
| 101 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luarepl")) | ||
| 102 | end) | ||
| 103 | |||
| 104 | it("LuaRocks build supported platforms lpty", function() | ||
| 105 | assert.is_true(run.luarocks_bool(test_env.quiet("build lpty"))) | ||
| 106 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpty")) | ||
| 107 | end) | ||
| 108 | |||
| 109 | it("LuaRocks build luasec with skipping dependency checks", function() | ||
| 110 | assert.is_true(run.luarocks_bool(test_env.quiet("build luasec --nodeps"))) | ||
| 111 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec")) | ||
| 112 | end) | ||
| 113 | |||
| 114 | it("LuaRocks build lmathx deps partial match", function() | ||
| 115 | assert.is_true(run.luarocks_bool("build lmathx")) | ||
| 116 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lmathx")) | ||
| 117 | end) | ||
| 118 | end) | ||
| 119 | |||
| 120 | describe("LuaRocks build - more complex tests", function() | ||
| 121 | if test_env.TYPE_TEST_ENV == "full" then | ||
| 122 | it("LuaRocks build luacheck show downloads test_config", function() | ||
| 123 | local output = run.luarocks("build luacheck", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_show_downloads.lua"} ) | ||
| 124 | assert.is.truthy(output:match("%.%.%.")) | ||
| 125 | end) | ||
| 126 | end | ||
| 127 | |||
| 128 | it("LuaRocks build luasec only deps", function() | ||
| 129 | assert.is_true(run.luarocks_bool(test_env.quiet("build luasec --only-deps"))) | ||
| 130 | assert.is_false(run.luarocks_bool("show luasec")) | ||
| 131 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec")) | ||
| 132 | end) | ||
| 133 | |||
| 134 | it("LuaRocks build only deps of downloaded rockspec of lxsh", function() | ||
| 135 | assert.is_true(run.luarocks_bool("download --rockspec lxsh 0.8.6-2")) | ||
| 136 | assert.is.truthy(run.luarocks("build lxsh-0.8.6-2.rockspec --only-deps")) | ||
| 137 | assert.is_false(run.luarocks_bool("show lxsh")) | ||
| 138 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 139 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 140 | assert.is_true(os.remove("lxsh-0.8.6-2.rockspec")) | ||
| 141 | end) | ||
| 142 | |||
| 143 | it("LuaRocks build only deps of downloaded rock of lxsh", function() | ||
| 144 | assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6-2")) | ||
| 145 | assert.is.truthy(run.luarocks("build lxsh-0.8.6-2.src.rock --only-deps")) | ||
| 146 | assert.is_false(run.luarocks_bool("show lxsh")) | ||
| 147 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 148 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 149 | assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) | ||
| 150 | end) | ||
| 151 | |||
| 152 | it("LuaRocks build no https", function() | ||
| 153 | assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) | ||
| 154 | assert.is_true(run.luarocks_bool("build validate-args-1.5.4-1.rockspec")) | ||
| 155 | |||
| 156 | assert.is.truthy(run.luarocks("show validate-args")) | ||
| 157 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/validate-args")) | ||
| 158 | |||
| 159 | assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) | ||
| 160 | end) | ||
| 161 | |||
| 162 | it("LuaRocks build with https", function() | ||
| 163 | assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) | ||
| 164 | assert.is_true(run.luarocks_bool(test_env.quiet("install luasec"))) | ||
| 165 | assert.is_true(run.luarocks_bool("build validate-args-1.5.4-1.rockspec")) | ||
| 166 | |||
| 167 | assert.is.truthy(run.luarocks("show validate-args")) | ||
| 168 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/validate-args")) | ||
| 169 | |||
| 170 | assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) | ||
| 171 | end) | ||
| 172 | |||
| 173 | it("LuaRocks build missing external", function() | ||
| 174 | assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) | ||
| 175 | end) | ||
| 176 | |||
| 177 | it("LuaRocks build invalid patch", function() | ||
| 178 | assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) | ||
| 179 | end) | ||
| 180 | end) | ||
| 181 | end) | ||
diff --git a/spec/config_spec.lua b/spec/config_spec.lua new file mode 100644 index 00000000..0dee8620 --- /dev/null +++ b/spec/config_spec.lua | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | local testing_paths = test_env.testing_paths | ||
| 5 | local site_config | ||
| 6 | |||
| 7 | test_env.unload_luarocks() | ||
| 8 | |||
| 9 | describe("LuaRocks config tests #blackbox #b_config", function() | ||
| 10 | |||
| 11 | before_each(function() | ||
| 12 | test_env.setup_specs() | ||
| 13 | test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs | ||
| 14 | site_config = require("luarocks.site_config") | ||
| 15 | end) | ||
| 16 | |||
| 17 | describe("LuaRocks config - basic tests", function() | ||
| 18 | it("LuaRocks config with no flags/arguments", function() | ||
| 19 | assert.is_false(run.luarocks_bool("config")) | ||
| 20 | end) | ||
| 21 | |||
| 22 | it("LuaRocks config include dir", function() | ||
| 23 | local output = run.luarocks("config --lua-incdir") | ||
| 24 | assert.are.same(output, site_config.LUA_INCDIR) | ||
| 25 | end) | ||
| 26 | |||
| 27 | it("LuaRocks config library dir", function() | ||
| 28 | local output = run.luarocks("config --lua-libdir") | ||
| 29 | assert.are.same(output, site_config.LUA_LIBDIR) | ||
| 30 | end) | ||
| 31 | |||
| 32 | it("LuaRocks config lua version", function() | ||
| 33 | local output = run.luarocks("config --lua-ver") | ||
| 34 | local lua_version = _VERSION:gsub("Lua ", "") | ||
| 35 | if test_env.LUAJIT_V then | ||
| 36 | lua_version = "5.1" | ||
| 37 | end | ||
| 38 | assert.are.same(output, lua_version) | ||
| 39 | end) | ||
| 40 | |||
| 41 | it("LuaRocks config rock trees", function() | ||
| 42 | assert.is_true(run.luarocks_bool("config --rock-trees")) | ||
| 43 | end) | ||
| 44 | |||
| 45 | it("LuaRocks config user config", function() | ||
| 46 | local user_config_path = run.luarocks("config --user-config") | ||
| 47 | assert.is.truthy(lfs.attributes(user_config_path)) | ||
| 48 | end) | ||
| 49 | |||
| 50 | it("LuaRocks config missing user config", function() | ||
| 51 | assert.is_false(run.luarocks_bool("config --user-config", {LUAROCKS_CONFIG = "missing_file.lua"})) | ||
| 52 | end) | ||
| 53 | end) | ||
| 54 | |||
| 55 | describe("LuaRocks config - more complex tests", function() | ||
| 56 | it("LuaRocks fail system config", function() | ||
| 57 | os.remove(testing_paths.testing_lrprefix .. "/etc/luarocks/config.lua") | ||
| 58 | assert.is_false(run.luarocks_bool("config --system-config;")) | ||
| 59 | end) | ||
| 60 | |||
| 61 | it("LuaRocks system config", function() | ||
| 62 | local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" | ||
| 63 | lfs.mkdir(testing_paths.testing_lrprefix) | ||
| 64 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") | ||
| 65 | lfs.mkdir(scdir) | ||
| 66 | |||
| 67 | local sysconfig = io.open(scdir .. "/config.lua", "w+") | ||
| 68 | sysconfig:write(" ") | ||
| 69 | sysconfig:close() | ||
| 70 | |||
| 71 | local output = run.luarocks("config --system-config;") | ||
| 72 | assert.are.same(output, scdir .. "/config.lua") | ||
| 73 | test_env.remove_dir(testing_paths.testing_lrprefix) | ||
| 74 | end) | ||
| 75 | |||
| 76 | it("LuaRocks fail system config invalid", function() | ||
| 77 | local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" | ||
| 78 | lfs.mkdir(testing_paths.testing_lrprefix) | ||
| 79 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") | ||
| 80 | lfs.mkdir(scdir) | ||
| 81 | |||
| 82 | local sysconfig = io.open(scdir .. "/config.lua", "w+") | ||
| 83 | sysconfig:write("if if if") | ||
| 84 | sysconfig:close() | ||
| 85 | |||
| 86 | assert.is_false(run.luarocks_bool("config --system-config;")) | ||
| 87 | test_env.remove_dir(testing_paths.testing_lrprefix) | ||
| 88 | end) | ||
| 89 | end) | ||
| 90 | end) | ||
diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua new file mode 100644 index 00000000..c1bd404d --- /dev/null +++ b/spec/deps_spec.lua | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | local testing_paths = test_env.testing_paths | ||
| 5 | |||
| 6 | test_env.unload_luarocks() | ||
| 7 | |||
| 8 | local extra_rocks = { | ||
| 9 | "/lxsh-0.8.6-2.src.rock", | ||
| 10 | "/lxsh-0.8.6-2.rockspec", | ||
| 11 | "/luasocket-3.0rc1-1.src.rock", | ||
| 12 | "/luasocket-3.0rc1-1.rockspec", | ||
| 13 | "/lpeg-0.12-1.src.rock" | ||
| 14 | } | ||
| 15 | |||
| 16 | describe("LuaRocks deps tests #blackbox #b_deps", function() | ||
| 17 | |||
| 18 | before_each(function() | ||
| 19 | test_env.setup_specs(extra_rocks) | ||
| 20 | end) | ||
| 21 | |||
| 22 | it("LuaRocks deps mode one", function() | ||
| 23 | assert.is_true(run.luarocks_bool("build --tree=system lpeg")) | ||
| 24 | assert.is_true(run.luarocks_bool("build --deps-mode=one --tree=" .. testing_paths.testing_tree .. " lxsh")) | ||
| 25 | |||
| 26 | assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 27 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 28 | assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 29 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 30 | end) | ||
| 31 | |||
| 32 | it("LuaRocks deps mode order", function() | ||
| 33 | assert.is_true(run.luarocks_bool("build --tree=system lpeg")) | ||
| 34 | assert.is_true(run.luarocks_bool("build --deps-mode=order --tree=" .. testing_paths.testing_tree .. " lxsh")) | ||
| 35 | |||
| 36 | assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 37 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 38 | assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 39 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 40 | end) | ||
| 41 | |||
| 42 | it("LuaRocks deps mode order sys", function() | ||
| 43 | assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " lpeg")) | ||
| 44 | assert.is_true(run.luarocks_bool("build --deps-mode=order --tree=" .. testing_paths.testing_sys_tree .. " lxsh")) | ||
| 45 | |||
| 46 | assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 47 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 48 | assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 49 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 50 | end) | ||
| 51 | |||
| 52 | it("LuaRocks deps mode all sys", function() | ||
| 53 | assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " lpeg")) | ||
| 54 | assert.is_true(run.luarocks_bool("build --deps-mode=all --tree=" .. testing_paths.testing_sys_tree .. " lxsh")) | ||
| 55 | |||
| 56 | assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 57 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 58 | assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 59 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 60 | end) | ||
| 61 | |||
| 62 | it("LuaRocks deps mode none", function() | ||
| 63 | assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " lpeg")) | ||
| 64 | assert.is_true(run.luarocks_bool("build --deps-mode=none lxsh")) | ||
| 65 | |||
| 66 | assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 67 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 68 | assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 69 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 70 | end) | ||
| 71 | |||
| 72 | it("LuaRocks nodeps alias", function() | ||
| 73 | assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " --nodeps lxsh")) | ||
| 74 | |||
| 75 | assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 76 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 77 | assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 78 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 79 | end) | ||
| 80 | |||
| 81 | it("LuaRocks deps mode make order", function() | ||
| 82 | assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_sys_tree .. " lpeg")) | ||
| 83 | assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6")) | ||
| 84 | assert.is_true(run.luarocks_bool("unpack lxsh-0.8.6-2.src.rock")) | ||
| 85 | lfs.chdir("lxsh-0.8.6-2/lxsh-0.8.6-1/") | ||
| 86 | assert.is_true(run.luarocks_bool("make --tree=" .. testing_paths.testing_tree .. " --deps-mode=order")) | ||
| 87 | |||
| 88 | lfs.chdir(testing_paths.luarocks_dir) | ||
| 89 | test_env.remove_dir("lxsh-0.8.6-2") | ||
| 90 | assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) | ||
| 91 | |||
| 92 | assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 93 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 94 | assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 95 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 96 | end) | ||
| 97 | |||
| 98 | it("LuaRocks deps mode make order sys", function() | ||
| 99 | assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " lpeg")) | ||
| 100 | assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6")) | ||
| 101 | assert.is_true(run.luarocks_bool("unpack lxsh-0.8.6-2.src.rock")) | ||
| 102 | lfs.chdir("lxsh-0.8.6-2/lxsh-0.8.6-1/") | ||
| 103 | assert.is_true(run.luarocks_bool("make --tree=" .. testing_paths.testing_sys_tree .. " --deps-mode=order")) | ||
| 104 | |||
| 105 | lfs.chdir(testing_paths.luarocks_dir) | ||
| 106 | test_env.remove_dir("lxsh-0.8.6-2") | ||
| 107 | assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) | ||
| 108 | |||
| 109 | assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 110 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) | ||
| 111 | assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 112 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 113 | end) | ||
| 114 | end) | ||
diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua new file mode 100644 index 00000000..a04d3c14 --- /dev/null +++ b/spec/doc_spec.lua | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | local testing_paths = test_env.testing_paths | ||
| 4 | |||
| 5 | test_env.unload_luarocks() | ||
| 6 | |||
| 7 | local extra_rocks = { | ||
| 8 | "/luarepl-0.4-1.src.rock", | ||
| 9 | "/c3-1.0-1.src.rock" | ||
| 10 | } | ||
| 11 | |||
| 12 | describe("LuaRocks doc tests #blackbox #b_doc", function() | ||
| 13 | |||
| 14 | before_each(function() | ||
| 15 | test_env.setup_specs(extra_rocks) | ||
| 16 | end) | ||
| 17 | |||
| 18 | describe("LuaRocks doc basic tests", function() | ||
| 19 | it("LuaRocks doc with no flags/arguments", function() | ||
| 20 | assert.is_false(run.luarocks_bool("doc")) | ||
| 21 | end) | ||
| 22 | it("LuaRocks doc with invalid argument", function() | ||
| 23 | assert.is_false(run.luarocks_bool("doc invalid")) | ||
| 24 | end) | ||
| 25 | it("LuaRocks doc with no homepage", function() | ||
| 26 | assert.is_true(run.luarocks_bool("install c3")) | ||
| 27 | assert.is_false(run.luarocks_bool("doc c3 --home")) | ||
| 28 | end) | ||
| 29 | it("LuaRocks doc with no home page and no doc folder", function() | ||
| 30 | assert.is_true(run.luarocks_bool("install c3")) | ||
| 31 | test_env.remove_dir(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/c3/1.0-1/doc") | ||
| 32 | assert.is_false(run.luarocks_bool("doc c3")) | ||
| 33 | end) | ||
| 34 | it("LuaRocks doc with no doc folder opening descript.homepage", function() | ||
| 35 | assert.is_true(run.luarocks_bool("install luarepl")) | ||
| 36 | test_env.remove_dir(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luarepl/0.4-1/doc") | ||
| 37 | local output = run.luarocks("doc luarepl") | ||
| 38 | assert.is.truthy(output:find("Local documentation directory not found")) | ||
| 39 | end) | ||
| 40 | end) | ||
| 41 | |||
| 42 | describe("LuaRocks doc tests with flags", function() | ||
| 43 | it("LuaRocks doc of installed luarepl", function() | ||
| 44 | assert.is_true(run.luarocks_bool("install luarepl")) | ||
| 45 | assert.is_true(run.luarocks_bool("doc luarepl")) | ||
| 46 | end) | ||
| 47 | |||
| 48 | it("LuaRocks doc of luacov and access its home page", function() | ||
| 49 | assert.is_true(run.luarocks_bool("install luacov")) | ||
| 50 | assert.is_true(run.luarocks_bool("doc luacov --home")) | ||
| 51 | end) | ||
| 52 | |||
| 53 | it("LuaRocks doc of luacov and list doc folder", function() | ||
| 54 | assert.is_true(run.luarocks_bool("install luacov")) | ||
| 55 | local output = assert.is.truthy(run.luarocks("doc luacov --list")) | ||
| 56 | assert.is.truthy(output:find("/lib/luarocks/rocks/luacov/0.11.0--1/doc/")) | ||
| 57 | end) | ||
| 58 | |||
| 59 | it("LuaRocks doc of luacov local", function() | ||
| 60 | assert.is_true(run.luarocks_bool("install luacov")) | ||
| 61 | assert.is_true(run.luarocks_bool("doc luacov --local")) | ||
| 62 | end) | ||
| 63 | |||
| 64 | it("LuaRocks doc of luacov porcelain", function() | ||
| 65 | assert.is_true(run.luarocks_bool("install luacov")) | ||
| 66 | assert.is_true(run.luarocks_bool("doc luacov --porcelain")) | ||
| 67 | end) | ||
| 68 | end) | ||
| 69 | end) | ||
| 70 | |||
| 71 | |||
diff --git a/spec/download_spec.lua b/spec/download_spec.lua new file mode 100644 index 00000000..320d9304 --- /dev/null +++ b/spec/download_spec.lua | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | |||
| 5 | test_env.unload_luarocks() | ||
| 6 | |||
| 7 | local extra_rocks = { | ||
| 8 | "/validate-args-1.5.4-1.rockspec" | ||
| 9 | } | ||
| 10 | |||
| 11 | describe("LuaRocks download tests #blackbox #b_download", function() | ||
| 12 | |||
| 13 | before_each(function() | ||
| 14 | test_env.setup_specs(extra_rocks) | ||
| 15 | end) | ||
| 16 | |||
| 17 | it("LuaRocks download with no flags/arguments", function() | ||
| 18 | assert.is_false(run.luarocks_bool("download")) | ||
| 19 | end) | ||
| 20 | |||
| 21 | it("LuaRocks download invalid", function() | ||
| 22 | assert.is_false(run.luarocks_bool("download invalid")) | ||
| 23 | end) | ||
| 24 | |||
| 25 | it("LuaRocks download all with delete downloaded files", function() --TODO maybe download --all more rocks | ||
| 26 | assert.is_true(run.luarocks_bool("download --all validate-args")) | ||
| 27 | assert.is.truthy(lfs.attributes("validate-args-1.5.4-1.rockspec")) | ||
| 28 | test_env.remove_files(lfs.currentdir(), "validate--args--") | ||
| 29 | end) | ||
| 30 | |||
| 31 | it("LuaRocks download rockspec version", function() | ||
| 32 | assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) | ||
| 33 | assert.is.truthy(lfs.attributes("validate-args-1.5.4-1.rockspec")) | ||
| 34 | test_env.remove_files(lfs.currentdir(), "validate--args--") | ||
| 35 | end) | ||
| 36 | end) | ||
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua new file mode 100644 index 00000000..05a709e4 --- /dev/null +++ b/spec/fetch_spec.lua | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | |||
| 3 | test_env.unload_luarocks() | ||
| 4 | local fetch = require("luarocks.fetch") | ||
| 5 | |||
| 6 | describe("Luarocks fetch test #whitebox #w_fetch", function() | ||
| 7 | it("Fetch url to base dir", function() | ||
| 8 | assert.are.same("v0.3", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) | ||
| 9 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) | ||
| 10 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) | ||
| 11 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) | ||
| 12 | assert.are.same("parser.moon", fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) | ||
| 13 | assert.are.same("v0.3", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) | ||
| 14 | end) | ||
| 15 | end) | ||
diff --git a/spec/help_spec.lua b/spec/help_spec.lua new file mode 100644 index 00000000..88aa5030 --- /dev/null +++ b/spec/help_spec.lua | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | |||
| 4 | test_env.unload_luarocks() | ||
| 5 | |||
| 6 | describe("LuaRocks help tests #blackbox #b_help", function() | ||
| 7 | |||
| 8 | before_each(function() | ||
| 9 | test_env.setup_specs() | ||
| 10 | end) | ||
| 11 | |||
| 12 | it("LuaRocks help with no flags/arguments", function() | ||
| 13 | assert.is_true(run.luarocks_bool(test_env.quiet("help"))) | ||
| 14 | end) | ||
| 15 | |||
| 16 | it("LuaRocks help invalid argument", function() | ||
| 17 | assert.is_false(run.luarocks_bool("help invalid")) | ||
| 18 | end) | ||
| 19 | |||
| 20 | it("LuaRocks help config", function() | ||
| 21 | assert.is_true(run.luarocks_bool(test_env.quiet("help config"))) | ||
| 22 | end) | ||
| 23 | |||
| 24 | it("LuaRocks-admin help with no flags/arguments", function() | ||
| 25 | assert.is_true(run.luarocks_admin_bool(test_env.quiet("help"))) | ||
| 26 | end) | ||
| 27 | end) | ||
diff --git a/spec/install_spec.lua b/spec/install_spec.lua new file mode 100644 index 00000000..bd480c21 --- /dev/null +++ b/spec/install_spec.lua | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | local testing_paths = test_env.testing_paths | ||
| 5 | local env_variables = test_env.env_variables | ||
| 6 | |||
| 7 | test_env.unload_luarocks() | ||
| 8 | |||
| 9 | local extra_rocks = { | ||
| 10 | "/cprint-0.1-2.src.rock", | ||
| 11 | "/cprint-0.1-2.rockspec", | ||
| 12 | "/lpeg-0.12-1.src.rock", | ||
| 13 | "/luasec-0.6-1.rockspec", | ||
| 14 | "/luassert-1.7.0-1.src.rock", | ||
| 15 | "/luasocket-3.0rc1-1.src.rock", | ||
| 16 | "/luasocket-3.0rc1-1.rockspec", | ||
| 17 | "/lxsh-0.8.6-2.src.rock", | ||
| 18 | "/lxsh-0.8.6-2.rockspec", | ||
| 19 | "/say-1.2-1.src.rock", | ||
| 20 | "/say-1.0-1.src.rock", | ||
| 21 | "/wsapi-1.6-1.src.rock" | ||
| 22 | } | ||
| 23 | |||
| 24 | describe("LuaRocks install tests #blackbox #b_install", function() | ||
| 25 | |||
| 26 | before_each(function() | ||
| 27 | test_env.setup_specs(extra_rocks) | ||
| 28 | end) | ||
| 29 | |||
| 30 | describe("LuaRocks install - basic tests", function() | ||
| 31 | it("LuaRocks install with no flags/arguments", function() | ||
| 32 | assert.is_false(run.luarocks_bool("install")) | ||
| 33 | end) | ||
| 34 | |||
| 35 | it("LuaRocks install with invalid argument", function() | ||
| 36 | assert.is_false(run.luarocks_bool("install invalid")) | ||
| 37 | end) | ||
| 38 | |||
| 39 | it("LuaRocks install invalid patch", function() | ||
| 40 | assert.is_false(run.luarocks_bool("install " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) | ||
| 41 | end) | ||
| 42 | |||
| 43 | it("LuaRocks install invalid rock", function() | ||
| 44 | assert.is_false(run.luarocks_bool("install \"invalid.rock\" ")) | ||
| 45 | end) | ||
| 46 | |||
| 47 | it("LuaRocks install with local flag as root", function() | ||
| 48 | assert.is_false(run.luarocks_bool("install --local luasocket", { USER = "root" } )) | ||
| 49 | end) | ||
| 50 | |||
| 51 | it("LuaRocks install not a zip file", function() | ||
| 52 | assert.is_false(run.luarocks_bool("install " .. testing_paths.testing_dir .. "/testfiles/not_a_zipfile-1.0-1.src.rock")) | ||
| 53 | end) | ||
| 54 | |||
| 55 | it("LuaRocks install only-deps of lxsh show there is no lxsh", function() | ||
| 56 | assert.is_true(run.luarocks_bool("install lxsh 0.8.6-2 --only-deps")) | ||
| 57 | assert.is_false(run.luarocks_bool("show lxsh")) | ||
| 58 | end) | ||
| 59 | |||
| 60 | it("LuaRocks install incompatible architecture", function() | ||
| 61 | assert.is_false(run.luarocks_bool("install \"foo-1.0-1.impossible-x86.rock\" ")) | ||
| 62 | end) | ||
| 63 | |||
| 64 | it("LuaRocks install wsapi with bin", function() | ||
| 65 | run.luarocks_bool("install wsapi") | ||
| 66 | end) | ||
| 67 | |||
| 68 | it("LuaRocks install luasec and show luasocket (dependency)", function() | ||
| 69 | assert.is_true(run.luarocks_bool("install luasec")) | ||
| 70 | assert.is_true(run.luarocks_bool("show luasocket")) | ||
| 71 | end) | ||
| 72 | end) | ||
| 73 | |||
| 74 | describe("LuaRocks install - more complex tests", function() | ||
| 75 | it('LuaRocks install luasec with skipping dependency checks', function() | ||
| 76 | run.luarocks_bool(test_env.quiet(" install luasec --nodeps")) | ||
| 77 | assert.is_true(run.luarocks_bool(test_env.quiet("show luasec"))) | ||
| 78 | if env_variables.TYPE_TEST_ENV == "minimal" then | ||
| 79 | assert.is_false(run.luarocks_bool(test_env.quiet("show luasocket"))) | ||
| 80 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
| 81 | end | ||
| 82 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec")) | ||
| 83 | end) | ||
| 84 | |||
| 85 | it("LuaRocks install only-deps of luasocket packed rock", function() | ||
| 86 | assert.is_true(run.luarocks_bool(test_env.quiet("build --pack-binary-rock luasocket 3.0rc1-1"))) | ||
| 87 | local output = run.luarocks("install --only-deps " .. "luasocket-3.0rc1-1." .. test_env.platform .. ".rock") | ||
| 88 | assert.are.same(output, "Successfully installed dependencies for luasocket 3.0rc1-1") | ||
| 89 | assert.is_true(os.remove("luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) | ||
| 90 | end) | ||
| 91 | |||
| 92 | it("LuaRocks install reinstall", function() | ||
| 93 | assert.is_true(run.luarocks_bool(test_env.quiet("build --pack-binary-rock luasocket 3.0rc1-1"))) | ||
| 94 | assert.is_true(run.luarocks_bool("install " .. "luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) | ||
| 95 | assert.is_true(run.luarocks_bool("install --deps-mode=none " .. "luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) | ||
| 96 | assert.is_true(os.remove("luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) | ||
| 97 | end) | ||
| 98 | |||
| 99 | it("LuaRocks install binary rock of cprint", function() | ||
| 100 | assert.is_true(run.luarocks_bool(test_env.quiet("build --pack-binary-rock cprint"))) | ||
| 101 | assert.is_true(run.luarocks_bool("install cprint-0.1-2." .. test_env.platform .. ".rock")) | ||
| 102 | assert.is_true(os.remove("cprint-0.1-2." .. test_env.platform .. ".rock")) | ||
| 103 | end) | ||
| 104 | end) | ||
| 105 | |||
| 106 | describe("New install functionality based on pull request 552", function() | ||
| 107 | it("LuaRocks install break dependencies warning", function() | ||
| 108 | assert.is_true(run.luarocks_bool("install say 1.2")) | ||
| 109 | assert.is_true(run.luarocks_bool("install luassert")) | ||
| 110 | assert.is_true(run.luarocks_bool("install say 1.0")) | ||
| 111 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.2-1")) | ||
| 112 | end) | ||
| 113 | it("LuaRocks install break dependencies force", function() | ||
| 114 | assert.is_true(run.luarocks_bool("install say 1.2")) | ||
| 115 | assert.is_true(run.luarocks_bool("install luassert")) | ||
| 116 | local output = run.luarocks("install --force say 1.0") | ||
| 117 | assert.is.truthy(output:find("Checking stability of dependencies")) | ||
| 118 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.2-1")) | ||
| 119 | end) | ||
| 120 | it("LuaRocks install break dependencies force fast", function() | ||
| 121 | assert.is_true(run.luarocks_bool("install say 1.2")) | ||
| 122 | assert.is_true(run.luarocks_bool("install luassert")) | ||
| 123 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.2-1")) | ||
| 124 | local output = run.luarocks("install --force-fast say 1.0") | ||
| 125 | assert.is.falsy(output:find("Checking stability of dependencies")) | ||
| 126 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.0-1")) | ||
| 127 | end) | ||
| 128 | end) | ||
| 129 | end) | ||
diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua new file mode 100644 index 00000000..f7496037 --- /dev/null +++ b/spec/lint_spec.lua | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | local testing_paths = test_env.testing_paths | ||
| 4 | |||
| 5 | test_env.unload_luarocks() | ||
| 6 | |||
| 7 | local extra_rocks = { | ||
| 8 | "/validate-args-1.5.4-1.rockspec" | ||
| 9 | } | ||
| 10 | |||
| 11 | describe("LuaRocks lint tests #blackbox #b_lint", function() | ||
| 12 | |||
| 13 | before_each(function() | ||
| 14 | test_env.setup_specs(extra_rocks) | ||
| 15 | end) | ||
| 16 | |||
| 17 | it("LuaRocks lint with no flags/arguments", function() | ||
| 18 | assert.is_false(run.luarocks_bool("lint")) | ||
| 19 | end) | ||
| 20 | |||
| 21 | it("LuaRocks lint invalid argument", function() | ||
| 22 | assert.is_false(run.luarocks_bool("lint invalid")) | ||
| 23 | end) | ||
| 24 | |||
| 25 | it("LuaRocks lint OK", function() | ||
| 26 | assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) | ||
| 27 | local output = run.luarocks("lint validate-args-1.5.4-1.rockspec") | ||
| 28 | assert.are.same(output, "") | ||
| 29 | assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) | ||
| 30 | end) | ||
| 31 | |||
| 32 | describe("LuaRocks lint mismatch set", function() | ||
| 33 | it("LuaRocks lint mismatch string", function() | ||
| 34 | assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/type_mismatch_string-1.0-1.rockspec")) | ||
| 35 | end) | ||
| 36 | |||
| 37 | it("LuaRocks lint mismatch version", function() | ||
| 38 | assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/type_mismatch_version-1.0-1.rockspec")) | ||
| 39 | end) | ||
| 40 | |||
| 41 | it("LuaRocks lint mismatch table", function() | ||
| 42 | assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/type_mismatch_table-1.0-1.rockspec")) | ||
| 43 | end) | ||
| 44 | |||
| 45 | it("LuaRocks lint mismatch no build table", function() | ||
| 46 | assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/no_build_table-1.0-1.rockspec")) | ||
| 47 | end) | ||
| 48 | end) | ||
| 49 | end) | ||
diff --git a/spec/list_spec.lua b/spec/list_spec.lua new file mode 100644 index 00000000..1b082ab6 --- /dev/null +++ b/spec/list_spec.lua | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | local testing_paths = test_env.testing_paths | ||
| 4 | |||
| 5 | test_env.unload_luarocks() | ||
| 6 | |||
| 7 | local extra_rocks = { | ||
| 8 | "/say-1.0-1.src.rock", | ||
| 9 | "/say-1.2-1.src.rock" | ||
| 10 | } | ||
| 11 | |||
| 12 | describe("LuaRocks list tests #blackbox #b_list", function() | ||
| 13 | |||
| 14 | before_each(function() | ||
| 15 | test_env.setup_specs(extra_rocks) | ||
| 16 | end) | ||
| 17 | |||
| 18 | it("LuaRocks list with no flags/arguments", function() | ||
| 19 | local output = run.luarocks("list") | ||
| 20 | assert.is.truthy(output:find("luacov")) | ||
| 21 | end) | ||
| 22 | |||
| 23 | it("LuaRocks list porcelain", function() | ||
| 24 | local output = run.luarocks("list --porcelain") | ||
| 25 | local path = testing_paths.testing_sys_tree:gsub("-", "--") -- !not sure! why this is good | ||
| 26 | assert.is.truthy(output:find("luacov\t0.11.0--1\tinstalled\t" .. path .. "/lib/luarocks/rocks" )) | ||
| 27 | end) | ||
| 28 | |||
| 29 | it("LuaRocks install outdated and list it", function() | ||
| 30 | assert.is_true(run.luarocks_bool("install say 1.0-1")) | ||
| 31 | local output = run.luarocks("list --outdated") | ||
| 32 | assert.is.truthy(output:find("say")) | ||
| 33 | end) | ||
| 34 | |||
| 35 | it("LuaRocks list invalid tree", function() | ||
| 36 | local output = run.luarocks("--tree=/some/invalid/tree list") | ||
| 37 | assert.are.same(output, "Installed rocks:----------------") | ||
| 38 | end) | ||
| 39 | end) | ||
diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua new file mode 100644 index 00000000..1c7f5bf8 --- /dev/null +++ b/spec/make_manifest_spec.lua | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | |||
| 4 | test_env.unload_luarocks() | ||
| 5 | |||
| 6 | describe("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() | ||
| 7 | |||
| 8 | before_each(function() | ||
| 9 | test_env.setup_specs() | ||
| 10 | end) | ||
| 11 | |||
| 12 | describe("LuaRocks-admin make manifest tests", function() | ||
| 13 | it("LuaRocks-admin make manifest", function() | ||
| 14 | assert.is_true(run.luarocks_admin_bool("make_manifest")) | ||
| 15 | end) | ||
| 16 | end) | ||
| 17 | end) | ||
diff --git a/spec/make_spec.lua b/spec/make_spec.lua new file mode 100644 index 00000000..e684033a --- /dev/null +++ b/spec/make_spec.lua | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | local testing_paths = test_env.testing_paths | ||
| 5 | |||
| 6 | test_env.unload_luarocks() | ||
| 7 | |||
| 8 | local extra_rocks = { | ||
| 9 | "/lpeg-0.12-1.src.rock", | ||
| 10 | "/luasocket-3.0rc1-1.src.rock", | ||
| 11 | "/luasocket-3.0rc1-1.rockspec", | ||
| 12 | "/lxsh-0.8.6-2.src.rock", | ||
| 13 | "/lxsh-0.8.6-2.rockspec" | ||
| 14 | } | ||
| 15 | |||
| 16 | describe("LuaRocks make tests #blackbox #b_make", function() | ||
| 17 | |||
| 18 | before_each(function() | ||
| 19 | test_env.setup_specs(extra_rocks) | ||
| 20 | end) | ||
| 21 | |||
| 22 | it("LuaRocks make with no flags/arguments", function() | ||
| 23 | lfs.chdir("test") | ||
| 24 | assert.is_false(run.luarocks_bool("make")) | ||
| 25 | lfs.chdir(testing_paths.luarocks_dir) | ||
| 26 | end) | ||
| 27 | |||
| 28 | it("LuaRocks make with rockspec", function() | ||
| 29 | -- make luasocket | ||
| 30 | assert.is_true(run.luarocks_bool("download --source luasocket 3.0rc1-1")) | ||
| 31 | assert.is_true(run.luarocks_bool("unpack luasocket-3.0rc1-1.src.rock")) | ||
| 32 | lfs.chdir("luasocket-3.0rc1-1/luasocket-3.0-rc1/") | ||
| 33 | assert.is_true(run.luarocks_bool(test_env.quiet("make luasocket-3.0rc1-1.rockspec"))) | ||
| 34 | |||
| 35 | -- test it | ||
| 36 | assert.is_true(run.luarocks_bool(test_env.quiet("show luasocket"))) | ||
| 37 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
| 38 | |||
| 39 | -- delete downloaded and unpacked files | ||
| 40 | lfs.chdir(testing_paths.luarocks_dir) | ||
| 41 | test_env.remove_dir("luasocket-3.0rc1-1") | ||
| 42 | assert.is_true(os.remove("luasocket-3.0rc1-1.src.rock")) | ||
| 43 | end) | ||
| 44 | |||
| 45 | describe("LuaRocks making rockspecs (using lxsh)", function() | ||
| 46 | --download lxsh and unpack it | ||
| 47 | before_each(function() | ||
| 48 | assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6-2")) | ||
| 49 | assert.is_true(run.luarocks_bool("unpack lxsh-0.8.6-2.src.rock")) | ||
| 50 | assert.is_true(lfs.chdir("lxsh-0.8.6-2/lxsh-0.8.6-1/")) | ||
| 51 | end) | ||
| 52 | |||
| 53 | -- delete downloaded and unpacked files | ||
| 54 | after_each(function() | ||
| 55 | assert.is_true(lfs.chdir(testing_paths.luarocks_dir)) | ||
| 56 | test_env.remove_dir("lxsh-0.8.6-2") | ||
| 57 | assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) | ||
| 58 | end) | ||
| 59 | |||
| 60 | it("LuaRocks make default rockspec", function() | ||
| 61 | assert.is_true(run.luarocks_bool("new_version lxsh-0.8.6-2.rockspec")) | ||
| 62 | assert.is_true(run.luarocks_bool("make")) | ||
| 63 | |||
| 64 | assert.is_true(run.luarocks_bool(test_env.quiet("show lxsh"))) | ||
| 65 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 66 | end) | ||
| 67 | |||
| 68 | it("LuaRocks make unnamed rockspec", function() | ||
| 69 | os.execute("cp lxsh-0.8.6-2.rockspec rockspec") --rewrite with lfs | ||
| 70 | assert.is_true(run.luarocks_bool("make")) | ||
| 71 | |||
| 72 | assert.is_true(run.luarocks_bool(test_env.quiet("show lxsh"))) | ||
| 73 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 74 | end) | ||
| 75 | |||
| 76 | it("LuaRocks make ambiguous rockspec", function() | ||
| 77 | assert.is.truthy(os.rename("lxsh-0.8.6-2.rockspec", "lxsh2-0.8.6-2.rockspec")) | ||
| 78 | assert.is_false(run.luarocks_bool("make")) | ||
| 79 | |||
| 80 | assert.is_false(run.luarocks_bool("show lxsh")) | ||
| 81 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 82 | end) | ||
| 83 | |||
| 84 | it("LuaRocks make ambiguous unnamed rockspec", function() | ||
| 85 | assert.is.truthy(os.rename("lxsh-0.8.6-2.rockspec", "1_rockspec")) | ||
| 86 | os.execute("cp 1_rockspec 2_rockspec") --rewrite with lfs | ||
| 87 | assert.is_false(run.luarocks_bool("make")) | ||
| 88 | |||
| 89 | assert.is_false(run.luarocks_bool("show lxsh")) | ||
| 90 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
| 91 | end) | ||
| 92 | |||
| 93 | it("LuaRocks make pack binary rock", function() | ||
| 94 | assert.is_true(run.luarocks_bool(test_env.quiet("make --deps-mode=none --pack-binary-rock"))) | ||
| 95 | assert.is.truthy(lfs.attributes("lxsh-0.8.6-2.all.rock")) | ||
| 96 | end) | ||
| 97 | end) | ||
| 98 | end) | ||
diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua new file mode 100644 index 00000000..c4185b1d --- /dev/null +++ b/spec/new_version_spec.lua | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | local testing_paths = test_env.testing_paths | ||
| 5 | |||
| 6 | test_env.unload_luarocks() | ||
| 7 | |||
| 8 | local extra_rocks = { | ||
| 9 | "/abelhas-1.0-1.rockspec", | ||
| 10 | "/lpeg-0.12-1.rockspec" | ||
| 11 | } | ||
| 12 | |||
| 13 | describe("LuaRocks new_version tests #blackbox #b_new_version", function() | ||
| 14 | |||
| 15 | before_each(function() | ||
| 16 | test_env.setup_specs(extra_rocks) | ||
| 17 | end) | ||
| 18 | |||
| 19 | describe("LuaRocks new_version basic tests", function() | ||
| 20 | it("LuaRocks new version with no flags/arguments", function() | ||
| 21 | lfs.chdir("test") | ||
| 22 | assert.is_false(run.luarocks_bool("new_version")) | ||
| 23 | lfs.chdir(testing_paths.luarocks_dir) | ||
| 24 | end) | ||
| 25 | |||
| 26 | it("LuaRocks new version invalid", function() | ||
| 27 | assert.is_false(run.luarocks_bool("new_version invalid")) | ||
| 28 | end) | ||
| 29 | |||
| 30 | it("LuaRocks new version invalid url", function() | ||
| 31 | assert.is_true(run.luarocks_bool("download --rockspec abelhas 1.0")) | ||
| 32 | assert.is_true(run.luarocks_bool("new_version abelhas-1.0-1.rockspec 1.1 http://luainvalid")) | ||
| 33 | assert.is.truthy(lfs.attributes("abelhas-1.1-1.rockspec")) | ||
| 34 | test_env.remove_files(lfs.currentdir(), "abelhas--") | ||
| 35 | end) | ||
| 36 | end) | ||
| 37 | |||
| 38 | describe("LuaRocks new_version more complex tests", function() | ||
| 39 | it("LuaRocks new version with remote spec", function() | ||
| 40 | assert.is_true(run.luarocks_bool("new_version https://luarocks.org/manifests/luarocks/luasocket-2.0.2-6.rockspec")) | ||
| 41 | assert.is.truthy(lfs.attributes("luasocket-2.0.2-6.rockspec")) | ||
| 42 | assert.is.truthy(lfs.attributes("luasocket-2.0.2-7.rockspec")) | ||
| 43 | test_env.remove_files(lfs.currentdir(), "luasocket--") | ||
| 44 | end) | ||
| 45 | |||
| 46 | it("LuaRocks new_version of luacov", function() | ||
| 47 | assert.is_true(run.luarocks_bool("download --rockspec luacov 0.11.0")) | ||
| 48 | assert.is_true(run.luarocks_bool("new_version luacov-0.11.0-1.rockspec 0.2")) | ||
| 49 | assert.is.truthy(lfs.attributes("luacov-0.2-1.rockspec")) | ||
| 50 | test_env.remove_files(lfs.currentdir(), "luacov--") | ||
| 51 | end) | ||
| 52 | |||
| 53 | it("LuaRocks new_version url of abelhas", function() | ||
| 54 | assert.is_true(run.luarocks_bool("download --rockspec abelhas 1.0")) | ||
| 55 | assert.is_true(run.luarocks_bool("new_version abelhas-1.0-1.rockspec 1.1 http://luaforge.net/frs/download.php/2658/abelhas-1.0.tar.gz")) | ||
| 56 | assert.is.truthy(lfs.attributes("abelhas-1.1-1.rockspec")) | ||
| 57 | test_env.remove_files(lfs.currentdir(), "abelhas--") | ||
| 58 | end) | ||
| 59 | |||
| 60 | it("LuaRocks new_version of luacov with tag", function() | ||
| 61 | assert.is_true(run.luarocks_bool("download --rockspec luacov 0.11.0")) | ||
| 62 | assert.is_true(run.luarocks_bool("new_version luacov-0.11.0-1.rockspec --tag v0.3")) | ||
| 63 | assert.is.truthy(lfs.attributes("luacov-0.3-1.rockspec")) | ||
| 64 | test_env.remove_files(lfs.currentdir(), "luacov--") | ||
| 65 | end) | ||
| 66 | |||
| 67 | it("LuaRocks new version updating md5", function() | ||
| 68 | assert.is_true(run.luarocks_bool("download --rockspec lpeg 0.12")) | ||
| 69 | assert.is_true(run.luarocks_bool("new_version lpeg-0.12-1.rockspec 0.2 https://luarocks.org/manifests/gvvaughan/lpeg-1.0.0-1.rockspec")) | ||
| 70 | test_env.remove_files(lfs.currentdir(), "lpeg--") | ||
| 71 | end) | ||
| 72 | end) | ||
| 73 | end) | ||
diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua new file mode 100644 index 00000000..0e5b31c6 --- /dev/null +++ b/spec/pack_spec.lua | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | local testing_paths = test_env.testing_paths | ||
| 5 | |||
| 6 | test_env.unload_luarocks() | ||
| 7 | |||
| 8 | local extra_rocks = { | ||
| 9 | "/luasec-0.6-1.rockspec", | ||
| 10 | "/luasocket-3.0rc1-1.src.rock", | ||
| 11 | "/luasocket-3.0rc1-1.rockspec", | ||
| 12 | "/say-1.2-1.src.rock", | ||
| 13 | "/say-1.0-1.src.rock" | ||
| 14 | } | ||
| 15 | |||
| 16 | describe("LuaRocks pack tests #blackbox #b_pack", function() | ||
| 17 | |||
| 18 | before_each(function() | ||
| 19 | test_env.setup_specs(extra_rocks) | ||
| 20 | end) | ||
| 21 | |||
| 22 | it("LuaRocks pack with no flags/arguments", function() | ||
| 23 | assert.is_false(run.luarocks_bool("pack")) | ||
| 24 | end) | ||
| 25 | |||
| 26 | it("LuaRocks pack basic", function() | ||
| 27 | assert.is_true(run.luarocks_bool(test_env.quiet("pack luacov"))) | ||
| 28 | assert.is_true(test_env.remove_files(lfs.currentdir(), "luacov-")) | ||
| 29 | end) | ||
| 30 | |||
| 31 | it("LuaRocks pack invalid rockspec", function() | ||
| 32 | assert.is_false(run.luarocks_bool("pack " .. testing_paths.testing_dir .. "/testfiles/invaild_validate-args-1.5.4-1.rockspec")) | ||
| 33 | end) | ||
| 34 | |||
| 35 | it("LuaRocks pack not installed rock", function() | ||
| 36 | assert.is_false(run.luarocks_bool("pack cjson")) | ||
| 37 | end) | ||
| 38 | |||
| 39 | it("LuaRocks pack not installed rock from non existing manifest", function() | ||
| 40 | assert.is_false(run.luarocks_bool("pack /non/exist/temp.manif")) | ||
| 41 | end) | ||
| 42 | |||
| 43 | it("LuaRocks pack specify which version of rock", function() | ||
| 44 | assert.is_true(run.luarocks_bool("install say 1.2")) | ||
| 45 | assert.is_true(run.luarocks_bool("install luassert")) | ||
| 46 | assert.is_true(run.luarocks_bool("install say 1.0")) | ||
| 47 | |||
| 48 | assert.is_false(run.luarocks_bool("pack say")) | ||
| 49 | end) | ||
| 50 | |||
| 51 | it("LuaRocks pack src", function() | ||
| 52 | assert.is_true(run.luarocks_bool(test_env.quiet("install luasec"))) | ||
| 53 | assert.is_true(run.luarocks_bool("download --rockspec luasocket 3.0rc1-1")) | ||
| 54 | assert.is_true(run.luarocks_bool("pack luasocket-3.0rc1-1.rockspec")) | ||
| 55 | assert.is_true(test_env.remove_files(lfs.currentdir(), "luasocket-")) | ||
| 56 | end) | ||
| 57 | end) | ||
| 58 | |||
| 59 | |||
diff --git a/spec/path_spec.lua b/spec/path_spec.lua new file mode 100644 index 00000000..22f07591 --- /dev/null +++ b/spec/path_spec.lua | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | |||
| 4 | test_env.unload_luarocks() | ||
| 5 | |||
| 6 | describe("LuaRocks path tests #blackbox #b_path", function() | ||
| 7 | before_each(function() | ||
| 8 | test_env.setup_specs() | ||
| 9 | end) | ||
| 10 | |||
| 11 | it("LuaRocks path bin", function() | ||
| 12 | assert.is_true(run.luarocks_bool("path --bin")) | ||
| 13 | end) | ||
| 14 | |||
| 15 | it("LuaRocks path lr-path", function() | ||
| 16 | assert.is_true(run.luarocks_bool("path --lr-path")) | ||
| 17 | end) | ||
| 18 | |||
| 19 | it("LuaRocks path lr-cpath", function() | ||
| 20 | assert.is_true(run.luarocks_bool("path --lr-cpath")) | ||
| 21 | end) | ||
| 22 | |||
| 23 | it("LuaRocks path with tree", function() | ||
| 24 | assert.is_true(run.luarocks_bool("path --tree=lua_modules")) | ||
| 25 | end) | ||
| 26 | end) | ||
diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua new file mode 100644 index 00000000..09a9d433 --- /dev/null +++ b/spec/purge_spec.lua | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | local testing_paths = test_env.testing_paths | ||
| 4 | |||
| 5 | test_env.unload_luarocks() | ||
| 6 | |||
| 7 | describe("LuaRocks purge tests #blackbox #b_purge", function() | ||
| 8 | before_each(function() | ||
| 9 | test_env.setup_specs() | ||
| 10 | end) | ||
| 11 | |||
| 12 | describe("LuaRocks purge basic tests", function() | ||
| 13 | it("LuaRocks purge missing tree", function() | ||
| 14 | assert.is_false(run.luarocks_bool("purge --tree=" .. testing_paths.testing_tree)) | ||
| 15 | end) | ||
| 16 | it("LuaRocks purge tree with no string", function() | ||
| 17 | assert.is_false(run.luarocks_bool("purge --tree=1")) | ||
| 18 | end) | ||
| 19 | it("LuaRocks purge tree with no string", function() | ||
| 20 | assert.is_true(run.luarocks_bool("purge --tree=" .. testing_paths.testing_sys_tree)) | ||
| 21 | end) | ||
| 22 | it("LuaRocks purge old versions tree", function() | ||
| 23 | assert.is_true(run.luarocks_bool("purge --old-versions --tree=" .. testing_paths.testing_sys_tree)) | ||
| 24 | end) | ||
| 25 | end) | ||
| 26 | end) | ||
| 27 | |||
| 28 | |||
diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua new file mode 100644 index 00000000..c20771ab --- /dev/null +++ b/spec/refresh_cache_spec.lua | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | |||
| 4 | test_env.unload_luarocks() | ||
| 5 | |||
| 6 | describe("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() | ||
| 7 | |||
| 8 | before_each(function() | ||
| 9 | test_env.setup_specs() | ||
| 10 | end) | ||
| 11 | |||
| 12 | describe("LuaRocks-admin refresh cache tests #ssh", function() | ||
| 13 | it("LuaRocks-admin refresh cache", function() | ||
| 14 | assert.is_true(run.luarocks_admin_bool("--server=testing refresh_cache")) | ||
| 15 | end) | ||
| 16 | end) | ||
| 17 | end) | ||
diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua new file mode 100644 index 00000000..7bf1bb10 --- /dev/null +++ b/spec/remove_spec.lua | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | local testing_paths = test_env.testing_paths | ||
| 5 | |||
| 6 | test_env.unload_luarocks() | ||
| 7 | |||
| 8 | local extra_rocks = { | ||
| 9 | "/abelhas-1.0-1.rockspec", | ||
| 10 | "/lualogging-1.3.0-1.src.rock", | ||
| 11 | "/luasocket-3.0rc1-1.src.rock", | ||
| 12 | "/luasocket-3.0rc1-1.rockspec" | ||
| 13 | } | ||
| 14 | |||
| 15 | describe("LuaRocks remove tests #blackbox #b_remove", function() | ||
| 16 | |||
| 17 | before_each(function() | ||
| 18 | test_env.setup_specs(extra_rocks) | ||
| 19 | end) | ||
| 20 | |||
| 21 | describe("LuaRocks remove basic tests", function() | ||
| 22 | it("LuaRocks remove with no flags/arguments", function() | ||
| 23 | assert.is_false(run.luarocks_bool("remove")) | ||
| 24 | end) | ||
| 25 | |||
| 26 | it("LuaRocks remove invalid rock", function() | ||
| 27 | assert.is_false(run.luarocks_bool("remove invalid.rock")) | ||
| 28 | end) | ||
| 29 | |||
| 30 | it("LuaRocks remove missing rock", function() | ||
| 31 | assert.is_false(run.luarocks_bool("remove missing_rock")) | ||
| 32 | end) | ||
| 33 | |||
| 34 | it("LuaRocks remove invalid argument", function() | ||
| 35 | assert.is_false(run.luarocks_bool("remove luacov --deps-mode")) | ||
| 36 | end) | ||
| 37 | |||
| 38 | it("LuaRocks remove builded abelhas", function() | ||
| 39 | assert.is_true(run.luarocks_bool("build abelhas 1.0")) | ||
| 40 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/abelhas")) | ||
| 41 | assert.is_true(run.luarocks_bool("remove abelhas 1.0")) | ||
| 42 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/abelhas")) | ||
| 43 | end) | ||
| 44 | end) | ||
| 45 | |||
| 46 | describe("LuaRocks remove more complex tests", function() | ||
| 47 | before_each(function() | ||
| 48 | assert.is.truthy(test_env.need_rock("luasocket")) | ||
| 49 | end) | ||
| 50 | |||
| 51 | it("LuaRocks remove fail, break dependencies", function() | ||
| 52 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
| 53 | assert.is_true(run.luarocks_bool("build lualogging")) | ||
| 54 | |||
| 55 | assert.is_false(run.luarocks_bool("remove luasocket")) | ||
| 56 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
| 57 | end) | ||
| 58 | |||
| 59 | it("LuaRocks remove force", function() | ||
| 60 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
| 61 | assert.is_true(run.luarocks_bool("build lualogging")) | ||
| 62 | |||
| 63 | local output = run.luarocks("remove --force luasocket") | ||
| 64 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
| 65 | assert.is.truthy(output:find("Checking stability of dependencies")) | ||
| 66 | end) | ||
| 67 | |||
| 68 | it("LuaRocks remove force fast", function() | ||
| 69 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
| 70 | assert.is_true(run.luarocks_bool("build lualogging")) | ||
| 71 | |||
| 72 | local output = run.luarocks("remove --force-fast luasocket") | ||
| 73 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
| 74 | assert.is.falsy(output:find("Checking stability of dependencies")) | ||
| 75 | end) | ||
| 76 | end) | ||
| 77 | |||
| 78 | it("LuaRocks-admin remove #ssh", function() | ||
| 79 | assert.is_true(run.luarocks_admin_bool("--server=testing remove luasocket-3.0rc1-1.src.rock")) | ||
| 80 | end) | ||
| 81 | |||
| 82 | it("LuaRocks-admin remove missing", function() | ||
| 83 | assert.is_false(run.luarocks_admin_bool("--server=testing remove")) | ||
| 84 | end) | ||
| 85 | end) | ||
diff --git a/spec/search_spec.lua b/spec/search_spec.lua new file mode 100644 index 00000000..b31624b8 --- /dev/null +++ b/spec/search_spec.lua | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | |||
| 4 | test_env.unload_luarocks() | ||
| 5 | |||
| 6 | local extra_rocks = { | ||
| 7 | "/lzlib-0.4.1.53-1.src.rock" | ||
| 8 | } | ||
| 9 | |||
| 10 | describe("LuaRocks search tests #blackbox #b_search", function() | ||
| 11 | |||
| 12 | before_each(function() | ||
| 13 | test_env.setup_specs(extra_rocks) | ||
| 14 | end) | ||
| 15 | |||
| 16 | it("LuaRocks search with no flags/arguments", function() | ||
| 17 | assert.is_false(run.luarocks_bool("search")) | ||
| 18 | end) | ||
| 19 | |||
| 20 | it("LuaRocks search zlib", function() | ||
| 21 | assert.is_true(run.luarocks_bool("search zlib")) | ||
| 22 | end) | ||
| 23 | |||
| 24 | it("LuaRocks search zlib 1.1", function() | ||
| 25 | assert.is_true(run.luarocks_bool("search zlib 1.1")) | ||
| 26 | end) | ||
| 27 | |||
| 28 | it("LuaRocks search missing rock", function() | ||
| 29 | assert.is_true(run.luarocks_bool("search missing_rock")) | ||
| 30 | end) | ||
| 31 | |||
| 32 | it("LuaRocks search with flag all", function() | ||
| 33 | assert.is_true(run.luarocks_bool(test_env.quiet("search --all"))) | ||
| 34 | end) | ||
| 35 | |||
| 36 | end) | ||
diff --git a/spec/show_spec.lua b/spec/show_spec.lua new file mode 100644 index 00000000..f528a6de --- /dev/null +++ b/spec/show_spec.lua | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | |||
| 4 | test_env.unload_luarocks() | ||
| 5 | |||
| 6 | describe("LuaRocks show tests #blackbox #b_show", function() | ||
| 7 | |||
| 8 | before_each(function() | ||
| 9 | test_env.setup_specs() | ||
| 10 | end) | ||
| 11 | |||
| 12 | it("LuaRocks show with no flags/arguments", function() | ||
| 13 | assert.is_false(run.luarocks_bool("show")) | ||
| 14 | end) | ||
| 15 | |||
| 16 | describe("LuaRocks show basic tests with flags", function() | ||
| 17 | it("LuaRocks show invalid", function() | ||
| 18 | assert.is_false(run.luarocks_bool("show invalid")) | ||
| 19 | end) | ||
| 20 | |||
| 21 | it("LuaRocks show luacov", function() | ||
| 22 | local output = run.luarocks("show luacov") | ||
| 23 | end) | ||
| 24 | |||
| 25 | it("LuaRocks show modules of luacov", function() | ||
| 26 | local output = run.luarocks("show --modules luacov") | ||
| 27 | end) | ||
| 28 | |||
| 29 | it("LuaRocks show dependencies of luacov", function() | ||
| 30 | local output = run.luarocks("show --deps luacov") | ||
| 31 | end) | ||
| 32 | |||
| 33 | it("LuaRocks show rockspec of luacov", function() | ||
| 34 | local output = run.luarocks("show --rockspec luacov") | ||
| 35 | end) | ||
| 36 | |||
| 37 | it("LuaRocks show mversion of luacov", function() | ||
| 38 | local output = run.luarocks("show --mversion luacov") | ||
| 39 | end) | ||
| 40 | |||
| 41 | it("LuaRocks show rock tree of luacov", function() | ||
| 42 | local output = run.luarocks("show --rock-tree luacov") | ||
| 43 | end) | ||
| 44 | |||
| 45 | it("LuaRocks show rock directory of luacov", function() | ||
| 46 | local output = run.luarocks("show --rock-dir luacov") | ||
| 47 | end) | ||
| 48 | end) | ||
| 49 | |||
| 50 | it("LuaRocks show old version of luacov", function() | ||
| 51 | run.luarocks("install luacov 0.11.0") | ||
| 52 | run.luarocks("show luacov 0.11.0") | ||
| 53 | end) | ||
| 54 | end) | ||
diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua new file mode 100644 index 00000000..495c514e --- /dev/null +++ b/spec/unpack_spec.lua | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | local testing_paths = test_env.testing_paths | ||
| 4 | local lfs = require("lfs") | ||
| 5 | |||
| 6 | test_env.unload_luarocks() | ||
| 7 | |||
| 8 | local extra_rocks = { | ||
| 9 | "/cprint-0.1-2.src.rock", | ||
| 10 | "/cprint-0.1-2.rockspec", | ||
| 11 | "/luazip-1.2.4-1.rockspec" | ||
| 12 | } | ||
| 13 | |||
| 14 | describe("LuaRocks unpack tests #blackbox #b_unpack", function() | ||
| 15 | |||
| 16 | before_each(function() | ||
| 17 | test_env.setup_specs(extra_rocks) | ||
| 18 | end) | ||
| 19 | |||
| 20 | describe("LuaRocks unpack basic fail tests", function() | ||
| 21 | it("LuaRocks unpack with no flags/arguments", function() | ||
| 22 | assert.is_false(run.luarocks_bool("unpack")) | ||
| 23 | end) | ||
| 24 | it("LuaRocks unpack with invalid rockspec", function() | ||
| 25 | assert.is_false(run.luarocks_bool("unpack invalid.rockspec")) | ||
| 26 | end) | ||
| 27 | it("LuaRocks unpack with invalid patch", function() | ||
| 28 | assert.is_false(run.luarocks_bool("unpack " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) | ||
| 29 | end) | ||
| 30 | end) | ||
| 31 | |||
| 32 | describe("LuaRocks unpack more complex tests", function() | ||
| 33 | it("LuaRocks unpack download", function() | ||
| 34 | assert.is_true(run.luarocks_bool("unpack cprint")) | ||
| 35 | test_env.remove_dir("cprint-0.1-2") | ||
| 36 | end) | ||
| 37 | it("LuaRocks unpack src", function() | ||
| 38 | assert.is_true(run.luarocks_bool("download --source cprint")) | ||
| 39 | assert.is_true(run.luarocks_bool("unpack cprint-0.1-2.src.rock")) | ||
| 40 | os.remove("cprint-0.1-2.src.rock") | ||
| 41 | test_env.remove_dir("cprint-0.1-2") | ||
| 42 | end) | ||
| 43 | it("LuaRocks unpack rockspec", function() | ||
| 44 | assert.is_true(run.luarocks_bool("download --rockspec cprint")) | ||
| 45 | assert.is_true(run.luarocks_bool("unpack cprint-0.1-2.rockspec")) | ||
| 46 | os.remove("cprint-0.1-2.rockspec") | ||
| 47 | os.remove("lua-cprint") | ||
| 48 | test_env.remove_dir("cprint-0.1-2") | ||
| 49 | end) | ||
| 50 | -- #595 luarocks unpack of a git:// rockspec fails to copy the rockspec | ||
| 51 | it("LuaRocks unpack git:// rockspec", function() | ||
| 52 | assert.is_true(run.luarocks_bool("download --rockspec cprint")) | ||
| 53 | assert.is_true(run.luarocks_bool("unpack luazip-1.2.4-1.rockspec")) | ||
| 54 | assert.is_truthy(lfs.attributes("luazip-1.2.4-1/luazip/luazip-1.2.4-1.rockspec")) | ||
| 55 | test_env.remove_dir("luazip-1.2.4-1") | ||
| 56 | end) | ||
| 57 | it("LuaRocks unpack binary", function() | ||
| 58 | assert.is_true(run.luarocks_bool("build cprint")) | ||
| 59 | assert.is_true(run.luarocks_bool("pack cprint")) | ||
| 60 | assert.is_true(run.luarocks_bool("unpack cprint-0.1-2." .. test_env.platform .. ".rock")) | ||
| 61 | test_env.remove_dir("cprint-0.1-2") | ||
| 62 | os.remove("cprint-0.1-2." .. test_env.platform .. ".rock") | ||
| 63 | end) | ||
| 64 | end) | ||
| 65 | end) | ||
| 66 | |||
| 67 | |||
diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua new file mode 100644 index 00000000..c68a1cdf --- /dev/null +++ b/spec/upload_spec.lua | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local run = test_env.run | ||
| 3 | local testing_paths = test_env.testing_paths | ||
| 4 | |||
| 5 | test_env.unload_luarocks() | ||
| 6 | |||
| 7 | local extra_rocks = { | ||
| 8 | "/lua-cjson-2.1.0-1.src.rock", | ||
| 9 | |||
| 10 | -- rocks needed for mock-server | ||
| 11 | "/copas-2.0.1-1.src.rock", | ||
| 12 | "/coxpcall-1.16.0-1.src.rock", | ||
| 13 | "/dkjson-2.5-2.src.rock", | ||
| 14 | "/luafilesystem-1.6.3-1.src.rock", | ||
| 15 | "/luasec-0.6-1.rockspec", | ||
| 16 | "/luasocket-3.0rc1-2.src.rock", | ||
| 17 | "/luasocket-3.0rc1-2.rockspec", | ||
| 18 | "/restserver-0.1-1.src.rock", | ||
| 19 | "/restserver-xavante-0.2-1.src.rock", | ||
| 20 | "/rings-1.3.0-1.src.rock", | ||
| 21 | "/wsapi-1.6.1-1.src.rock", | ||
| 22 | "/wsapi-xavante-1.6.1-1.src.rock", | ||
| 23 | "/xavante-2.4.0-1.src.rock" | ||
| 24 | } | ||
| 25 | |||
| 26 | describe("LuaRocks upload tests #blackbox #b_upload", function() | ||
| 27 | |||
| 28 | before_each(function() | ||
| 29 | test_env.setup_specs(extra_rocks) | ||
| 30 | end) | ||
| 31 | |||
| 32 | it("LuaRocks upload with no flags/arguments", function() | ||
| 33 | assert.is_false(run.luarocks_bool("upload")) | ||
| 34 | end) | ||
| 35 | |||
| 36 | it("LuaRocks upload invalid rockspec", function() | ||
| 37 | assert.is_false(run.luarocks_bool("upload invalid.rockspec")) | ||
| 38 | end) | ||
| 39 | |||
| 40 | it("LuaRocks upload api key invalid", function() | ||
| 41 | assert.is_false(run.luarocks_bool("upload --api-key=invalid invalid.rockspec")) | ||
| 42 | end) | ||
| 43 | |||
| 44 | it("LuaRocks upload api key invalid and skip-pack", function() | ||
| 45 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --skip-pack luacov-0.11.0-1.rockspec")) | ||
| 46 | end) | ||
| 47 | |||
| 48 | it("LuaRocks upload force", function() | ||
| 49 | assert.is_true(run.luarocks_bool("install lua-cjson")) | ||
| 50 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force luacov-0.11.0-1.rockspec")) | ||
| 51 | assert.is_true(run.luarocks_bool("install lua-cjson")) | ||
| 52 | end) | ||
| 53 | |||
| 54 | describe("LuaRocks upload tests with Xavante server #mock", function() | ||
| 55 | before_each(function() | ||
| 56 | assert.is.truthy(test_env.need_rock("restserver-xavante")) | ||
| 57 | local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.testing_dir .. "/mock-server.lua &", true, test_env.env_variables) | ||
| 58 | os.execute(final_command) | ||
| 59 | end) | ||
| 60 | |||
| 61 | after_each(function() | ||
| 62 | os.execute("curl localhost:8080/shutdown") | ||
| 63 | end) | ||
| 64 | |||
| 65 | it("LuaRocks upload rockspec with api-key", function() | ||
| 66 | assert.is_true(run.luarocks_bool("upload " .. testing_paths.testing_server .. "/luasocket-3.0rc1-2.rockspec --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) | ||
| 67 | end) | ||
| 68 | it("LuaRocks upload rockspec with api-key and skip-pack", function() | ||
| 69 | assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.testing_server .. "/luasocket-3.0rc1-2.rockspec --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) | ||
| 70 | end) | ||
| 71 | end) | ||
| 72 | end) | ||
| 73 | |||
| 74 | |||
diff --git a/spec/util_spec.lua b/spec/util_spec.lua new file mode 100644 index 00000000..23e3ebd8 --- /dev/null +++ b/spec/util_spec.lua | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | local testing_paths = test_env.testing_paths | ||
| 5 | local env_variables = test_env.env_variables | ||
| 6 | |||
| 7 | describe("Basic tests #blackbox #b_util", function() | ||
| 8 | |||
| 9 | before_each(function() | ||
| 10 | test_env.setup_specs() | ||
| 11 | end) | ||
| 12 | |||
| 13 | it("LuaRocks version", function() | ||
| 14 | assert.is_true(run.luarocks_bool("--version")) | ||
| 15 | end) | ||
| 16 | |||
| 17 | it("LuaRocks unknown command", function() | ||
| 18 | assert.is_false(run.luarocks_bool("unknown_command")) | ||
| 19 | end) | ||
| 20 | |||
| 21 | it("LuaRocks arguments fail", function() | ||
| 22 | assert.is_false(run.luarocks_bool("--porcelain=invalid")) | ||
| 23 | assert.is_false(run.luarocks_bool("--invalid-flag")) | ||
| 24 | assert.is_false(run.luarocks_bool("--server")) | ||
| 25 | assert.is_false(run.luarocks_bool("--server --porcelain")) | ||
| 26 | assert.is_false(run.luarocks_bool("--invalid-flag=abc")) | ||
| 27 | assert.is_false(run.luarocks_bool("invalid=5")) | ||
| 28 | end) | ||
| 29 | |||
| 30 | it("LuaRocks execute from not existing directory", function() | ||
| 31 | local main_path = lfs.currentdir() | ||
| 32 | assert.is_true(lfs.mkdir("idontexist")) | ||
| 33 | assert.is_true(lfs.chdir("idontexist")) | ||
| 34 | local delete_path = lfs.currentdir() | ||
| 35 | assert.is_true(os.remove(delete_path)) | ||
| 36 | |||
| 37 | local output = run.luarocks("") | ||
| 38 | assert.is.falsy(output:find("LuaRocks scm, a module deployment system for Lua")) | ||
| 39 | assert.is_true(lfs.chdir(main_path)) | ||
| 40 | |||
| 41 | output = run.luarocks("") | ||
| 42 | assert.is.truthy(output:find("LuaRocks scm, a module deployment system for Lua")) | ||
| 43 | end) | ||
| 44 | |||
| 45 | it("LuaRocks timeout", function() | ||
| 46 | assert.is.truthy(run.luarocks("--timeout=10")) | ||
| 47 | end) | ||
| 48 | |||
| 49 | it("LuaRocks timeout invalid", function() | ||
| 50 | assert.is_false(run.luarocks_bool("--timeout=abc")) | ||
| 51 | end) | ||
| 52 | |||
| 53 | it("LuaRocks only server=testing", function() | ||
| 54 | assert.is.truthy(run.luarocks("--only-server=testing")) | ||
| 55 | end) | ||
| 56 | |||
| 57 | it("LuaRocks test site config", function() | ||
| 58 | assert.is.truthy(os.rename("src/luarocks/site_config.lua", "src/luarocks/site_config.lua.tmp")) | ||
| 59 | assert.is.falsy(lfs.attributes("src/luarocks/site_config.lua")) | ||
| 60 | assert.is.truthy(lfs.attributes("src/luarocks/site_config.lua.tmp")) | ||
| 61 | |||
| 62 | assert.is.truthy(run.luarocks("")) | ||
| 63 | |||
| 64 | assert.is.truthy(os.rename("src/luarocks/site_config.lua.tmp", "src/luarocks/site_config.lua")) | ||
| 65 | assert.is.falsy(lfs.attributes("src/luarocks/site_config.lua.tmp")) | ||
| 66 | assert.is.truthy(lfs.attributes("src/luarocks/site_config.lua")) | ||
| 67 | end) | ||
| 68 | |||
| 69 | describe("LuaRocks sysconfig fails", function() | ||
| 70 | local scdir = "" | ||
| 71 | |||
| 72 | before_each(function() | ||
| 73 | scdir = testing_paths.testing_lrprefix .. "/etc/luarocks/" | ||
| 74 | lfs.mkdir(testing_paths.testing_lrprefix) | ||
| 75 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") | ||
| 76 | lfs.mkdir(scdir) | ||
| 77 | end) | ||
| 78 | |||
| 79 | after_each(function() | ||
| 80 | test_env.remove_dir(testing_paths.testing_lrprefix) | ||
| 81 | end) | ||
| 82 | |||
| 83 | it("LuaRocks sysconfig fail", function() | ||
| 84 | local sysconfig = io.open(scdir .. "/config.lua", "w+") | ||
| 85 | sysconfig:write("aoeui") | ||
| 86 | sysconfig:close() | ||
| 87 | |||
| 88 | assert.is_false(run.luarocks_bool("list")) | ||
| 89 | end) | ||
| 90 | |||
| 91 | it("LuaRocks sysconfig fail", function() | ||
| 92 | local sysconfig = io.open(scdir .. "/config-" .. env_variables.LUA_VERSION .. ".lua", "w+") | ||
| 93 | sysconfig:write("aoeui") | ||
| 94 | sysconfig:close() | ||
| 95 | |||
| 96 | assert.is_false(run.luarocks_bool("list")) | ||
| 97 | end) | ||
| 98 | end) | ||
| 99 | end) | ||
diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua new file mode 100644 index 00000000..531d11eb --- /dev/null +++ b/spec/write_rockspec_spec.lua | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local run = test_env.run | ||
| 4 | |||
| 5 | test_env.unload_luarocks() | ||
| 6 | |||
| 7 | describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() | ||
| 8 | |||
| 9 | before_each(function() | ||
| 10 | test_env.setup_specs() | ||
| 11 | end) | ||
| 12 | |||
| 13 | describe("LuaRocks write_rockspec basic tests", function() | ||
| 14 | it("LuaRocks write_rockspec with no flags/arguments", function() | ||
| 15 | assert.is_true(run.luarocks_bool("write_rockspec")) | ||
| 16 | os.remove("luarocks-scm-1.rockspec") | ||
| 17 | end) | ||
| 18 | |||
| 19 | it("LuaRocks write_rockspec with invalid argument", function() | ||
| 20 | assert.is_false(run.luarocks_bool("write_rockspec invalid")) | ||
| 21 | end) | ||
| 22 | |||
| 23 | it("LuaRocks write_rockspec invalid zip", function() | ||
| 24 | assert.is_false(run.luarocks_bool("write_rockspec http://example.com/invalid.zip")) | ||
| 25 | end) | ||
| 26 | end) | ||
| 27 | |||
| 28 | describe("LuaRocks write_rockspec more complex tests", function() | ||
| 29 | it("LuaRocks write_rockspec git luarocks", function() | ||
| 30 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/keplerproject/luarocks")) | ||
| 31 | assert.is.truthy(lfs.attributes("luarocks-scm-1.rockspec")) | ||
| 32 | assert.is_true(os.remove("luarocks-scm-1.rockspec")) | ||
| 33 | end) | ||
| 34 | |||
| 35 | it("LuaRocks write_rockspec git luarocks --tag=v2.3.0", function() | ||
| 36 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0")) | ||
| 37 | assert.is.truthy(lfs.attributes("luarocks-2.3.0-1.rockspec")) | ||
| 38 | assert.is_true(os.remove("luarocks-2.3.0-1.rockspec")) | ||
| 39 | end) | ||
| 40 | |||
| 41 | it("LuaRocks write_rockspec git luarocks with format flag", function() | ||
| 42 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/mbalmer/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2")) | ||
| 43 | assert.is.truthy(lfs.attributes("luarocks-scm-1.rockspec")) | ||
| 44 | assert.is_true(os.remove("luarocks-scm-1.rockspec")) | ||
| 45 | end) | ||
| 46 | |||
| 47 | it("LuaRocks write_rockspec git luarocks with full flags", function() | ||
| 48 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/mbalmer/luarocks --lua-version=5.1,5.2 --license=\"MIT/X11\" " | ||
| 49 | .. " --homepage=\"http://www.luarocks.org\" --summary=\"A package manager for Lua modules\" ")) | ||
| 50 | assert.is.truthy(lfs.attributes("luarocks-scm-1.rockspec")) | ||
| 51 | assert.is_true(os.remove("luarocks-scm-1.rockspec")) | ||
| 52 | end) | ||
| 53 | |||
| 54 | it("LuaRocks write_rockspec rockspec via http", function() | ||
| 55 | assert.is_true(run.luarocks_bool("write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1")) | ||
| 56 | assert.is.truthy(lfs.attributes("luarocks-2.1.0-1.rockspec")) | ||
| 57 | assert.is_true(os.remove("luarocks-2.1.0-1.rockspec")) | ||
| 58 | end) | ||
| 59 | |||
| 60 | it("LuaRocks write_rockspec base dir, luassert.tar.gz via https", function() | ||
| 61 | assert.is_true(run.luarocks_bool("write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1")) | ||
| 62 | assert.is.truthy(lfs.attributes("luassert-1.2-1.rockspec")) | ||
| 63 | assert.is_true(os.remove("luassert-1.2-1.rockspec")) | ||
| 64 | end) | ||
| 65 | |||
| 66 | it("LuaRocks write_rockspec git luafcgi with many flags", function() | ||
| 67 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license=\"3-clause BSD\" " .. "--lua-version=5.1,5.2")) | ||
| 68 | assert.is.truthy(lfs.attributes("luafcgi-scm-1.rockspec")) -- TODO maybe read it content and find arguments from flags? | ||
| 69 | assert.is_true(os.remove("luafcgi-scm-1.rockspec")) | ||
| 70 | end) | ||
| 71 | end) | ||
| 72 | end) | ||
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 42508b9e..73bff097 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
| @@ -406,7 +406,7 @@ local defaults = { | |||
| 406 | 406 | ||
| 407 | if cfg.platforms.windows then | 407 | if cfg.platforms.windows then |
| 408 | local full_prefix = (site_config.LUAROCKS_PREFIX or (os.getenv("PROGRAMFILES")..[[\LuaRocks]])) | 408 | local full_prefix = (site_config.LUAROCKS_PREFIX or (os.getenv("PROGRAMFILES")..[[\LuaRocks]])) |
| 409 | extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua" | 409 | extra_luarocks_module_dir = full_prefix.."/lua/?.lua" |
| 410 | 410 | ||
| 411 | home_config_file = home_config_file and home_config_file:gsub("\\","/") | 411 | home_config_file = home_config_file and home_config_file:gsub("\\","/") |
| 412 | defaults.fs_use_modules = false | 412 | defaults.fs_use_modules = false |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index c03db6a0..9ce95986 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
| @@ -130,6 +130,8 @@ function win32.wrap_script(file, dest, name, version) | |||
| 130 | local wrapname = fs.is_dir(dest) and dest.."/"..base or dest | 130 | local wrapname = fs.is_dir(dest) and dest.."/"..base or dest |
| 131 | wrapname = wrapname..".bat" | 131 | wrapname = wrapname..".bat" |
| 132 | local lpath, lcpath = cfg.package_paths() | 132 | local lpath, lcpath = cfg.package_paths() |
| 133 | lpath = util.remove_path_dupes(lpath, ";") | ||
| 134 | lcpath = util.remove_path_dupes(lcpath, ";") | ||
| 133 | local wrapper = io.open(wrapname, "w") | 135 | local wrapper = io.open(wrapname, "w") |
| 134 | if not wrapper then | 136 | if not wrapper then |
| 135 | return nil, "Could not open "..wrapname.." for writing." | 137 | return nil, "Could not open "..wrapname.." for writing." |
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 51e2cf57..d27c3a50 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
| @@ -64,7 +64,7 @@ function help.command(flags, command) | |||
| 64 | --verbose Display verbose output of commands executed. | 64 | --verbose Display verbose output of commands executed. |
| 65 | --timeout=<seconds> Timeout on network operations, in seconds. | 65 | --timeout=<seconds> Timeout on network operations, in seconds. |
| 66 | 0 means no timeout (wait forever). | 66 | 0 means no timeout (wait forever). |
| 67 | Default is ]]..cfg.connection_timeout..[[.]]) | 67 | Default is ]]..tostring(cfg.connection_timeout)..[[.]]) |
| 68 | print_section("VARIABLES") | 68 | print_section("VARIABLES") |
| 69 | util.printout([[ | 69 | util.printout([[ |
| 70 | Variables from the "variables" table of the configuration file | 70 | Variables from the "variables" table of the configuration file |
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index eb5dea25..000b459b 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua | |||
| @@ -133,15 +133,19 @@ function new_version.command(flags, input, version, url) | |||
| 133 | end | 133 | end |
| 134 | assert(type(input) == "string") | 134 | assert(type(input) == "string") |
| 135 | 135 | ||
| 136 | local filename = input | 136 | local filename, err |
| 137 | if not input:match("rockspec$") then | 137 | if input:match("rockspec$") then |
| 138 | local err | 138 | filename, err = fetch.fetch_url(input) |
| 139 | if not filename then | ||
| 140 | return nil, err | ||
| 141 | end | ||
| 142 | else | ||
| 139 | filename, err = download.download("rockspec", input) | 143 | filename, err = download.download("rockspec", input) |
| 140 | if not filename then | 144 | if not filename then |
| 141 | return nil, err | 145 | return nil, err |
| 142 | end | 146 | end |
| 143 | end | 147 | end |
| 144 | 148 | ||
| 145 | local valid_rs, err = fetch.load_rockspec(filename) | 149 | local valid_rs, err = fetch.load_rockspec(filename) |
| 146 | if not valid_rs then | 150 | if not valid_rs then |
| 147 | return nil, err | 151 | return nil, err |
| @@ -167,7 +171,7 @@ function new_version.command(flags, input, version, url) | |||
| 167 | end | 171 | end |
| 168 | local new_rockver = new_ver:gsub("-", "") | 172 | local new_rockver = new_ver:gsub("-", "") |
| 169 | 173 | ||
| 170 | local out_rs = persist.load_into_table(filename) | 174 | local out_rs, err = persist.load_into_table(filename) |
| 171 | local out_name = out_rs.package:lower() | 175 | local out_name = out_rs.package:lower() |
| 172 | out_rs.version = new_rockver.."-"..new_rev | 176 | out_rs.version = new_rockver.."-"..new_rev |
| 173 | 177 | ||
diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua index 22b3f49b..af3398ab 100644 --- a/src/luarocks/unpack.lua +++ b/src/luarocks/unpack.lua | |||
| @@ -44,7 +44,6 @@ local function unpack_rockspec(rockspec_file, dir_name) | |||
| 44 | if not ok then return nil, err end | 44 | if not ok then return nil, err end |
| 45 | ok, err = build.apply_patches(rockspec) | 45 | ok, err = build.apply_patches(rockspec) |
| 46 | fs.pop_dir() | 46 | fs.pop_dir() |
| 47 | fs.pop_dir() | ||
| 48 | if not ok then return nil, err end | 47 | if not ok then return nil, err end |
| 49 | return rockspec | 48 | return rockspec |
| 50 | end | 49 | end |
diff --git a/src/luarocks/upload.lua b/src/luarocks/upload.lua index 4bda4303..baee47ab 100644 --- a/src/luarocks/upload.lua +++ b/src/luarocks/upload.lua | |||
| @@ -75,6 +75,9 @@ function upload.command(flags, fname) | |||
| 75 | local module_url = res.module_url | 75 | local module_url = res.module_url |
| 76 | 76 | ||
| 77 | if rock_fname then | 77 | if rock_fname then |
| 78 | if (not res.version) or (not res.version.id) then | ||
| 79 | return nil, "Invalid response from server." | ||
| 80 | end | ||
| 78 | util.printout(("Sending " .. tostring(rock_fname) .. " ...")) | 81 | util.printout(("Sending " .. tostring(rock_fname) .. " ...")) |
| 79 | res, err = api:method("upload_rock/" .. ("%d"):format(res.version.id), nil, { | 82 | res, err = api:method("upload_rock/" .. ("%d"):format(res.version.id), nil, { |
| 80 | rock_file = multipart.new_file(rock_fname) | 83 | rock_file = multipart.new_file(rock_fname) |
diff --git a/test/README.md b/test/README.md new file mode 100644 index 00000000..c374438f --- /dev/null +++ b/test/README.md | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #LuaRocks testsuite | ||
| 2 | ##Overview | ||
| 3 | Test suite for LuaRocks project with Busted unit testing framework(http://olivinelabs.com/busted/). | ||
| 4 | |||
| 5 | * Contains white-box & black-box tests | ||
| 6 | * Easy setup for your purpose on command line or from configuration file | ||
| 7 | |||
| 8 | |||
| 9 | ## Dependencies | ||
| 10 | * Lua >= 5.1 | ||
| 11 | * Busted with dependencies | ||
| 12 | |||
| 13 | |||
| 14 | ##Usage | ||
| 15 | Running of tests is based on basic Busted usage. *-Xhelper* flag is mandatory for inserting arguments into testing (primary black-box). Flag *--tags=* or *-t* is mandatory for specifying which tests will run. Mandatory *-Xhelper* flag always needs version of Lua or LuaJIT (e.g. *lua=5.2.4* or *luajit=2.0.3*). Start tests inside LuaRocks folder or specify with *-C* flag. | ||
| 16 | |||
| 17 | **Arguments for Busted helper script** | ||
| 18 | |||
| 19 | ``` | ||
| 20 | lua=<version>, !mandatory! type your full version of Lua (e.g. lua=5.2.4) | ||
| 21 | OR | ||
| 22 | luajit=<version>, !mandatory! type your full version of LuaJIT (e.g. luajit=5.2.4) | ||
| 23 | |||
| 24 | env=<type>, (default:"minimal") type what kind of environment to use ["minimal", "full"] | ||
| 25 | clean, remove existing testing environment | ||
| 26 | travis, add just if running on TravisCI | ||
| 27 | os=<version>, type your OS ["linux", "os x", "windows"] | ||
| 28 | ``` | ||
| 29 | --------------------------------------------------------------------------------------------- | ||
| 30 | ####_**Tags** of tests are required and are in this format:_ | ||
| 31 | |||
| 32 | **whitebox** - run all whitebox tests | ||
| 33 | |||
| 34 | **blackbox** - run all blackbox tests | ||
| 35 | |||
| 36 | **ssh** - run all tests which require ssh | ||
| 37 | |||
| 38 | **w**\_*name-of-command* - whitebox testing of command | ||
| 39 | |||
| 40 | **b**\_*name-of-command* - blackbox testing of command | ||
| 41 | |||
| 42 | for example: `b_install` or `w_help` | ||
| 43 | |||
| 44 | ###Examples | ||
| 45 | To run white-box tests in LuaRocks directory type : | ||
| 46 | |||
| 47 | `busted -t "whitebox"` | ||
| 48 | |||
| 49 | To run black-box tests just of *install* command (we defined our OS, so OS check is skipped.): | ||
| 50 | |||
| 51 | `busted -Xhelper lua=5.2.4,os=linux -t "b_install"` | ||
| 52 | |||
| 53 | To run black-box tests of *install* command, whitebox of *help* command (using *full* type of environment): | ||
| 54 | |||
| 55 | `busted -Xhelper lua=5.2.4,env=full -t "b_install", "w_help"` | ||
| 56 | |||
| 57 | To run black-box tests without tests, which use ssh: | ||
| 58 | |||
| 59 | `busted -Xhelper lua=5.2.4 -t "blackbox" --exclude-tags=ssh` \ No newline at end of file | ||
diff --git a/test/luarocks_site.lua b/test/luarocks_site.lua new file mode 100644 index 00000000..cfa77dca --- /dev/null +++ b/test/luarocks_site.lua | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | -- Config file of LuaRocks site for tests | ||
| 2 | upload = { | ||
| 3 | server = "http://localhost:8080", | ||
| 4 | tool_version = "1.0.0", | ||
| 5 | api_version = "1", | ||
| 6 | } \ No newline at end of file | ||
diff --git a/test/mock-server.lua b/test/mock-server.lua new file mode 100644 index 00000000..797e2bc5 --- /dev/null +++ b/test/mock-server.lua | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | #!/usr/bin/env lua | ||
| 2 | |||
| 3 | --- A simple LuaRocks mock-server for testing. | ||
| 4 | local restserver = require("restserver") | ||
| 5 | local server = restserver:new():port(8080) | ||
| 6 | |||
| 7 | server:add_resource("api/tool_version", { | ||
| 8 | { | ||
| 9 | method = "GET", | ||
| 10 | path = "/", | ||
| 11 | produces = "application/json", | ||
| 12 | handler = function(query) | ||
| 13 | local json = { version = query.current } | ||
| 14 | return restserver.response():status(200):entity(json) | ||
| 15 | end | ||
| 16 | } | ||
| 17 | }) | ||
| 18 | |||
| 19 | server:add_resource("api/1/{id:[0-9]+}/status", { | ||
| 20 | { | ||
| 21 | method = "GET", | ||
| 22 | path = "/", | ||
| 23 | produces = "application/json", | ||
| 24 | handler = function(query) | ||
| 25 | local json = { user_id = "123", created_at = "29.1.1993" } | ||
| 26 | return restserver.response():status(200):entity(json) | ||
| 27 | end | ||
| 28 | } | ||
| 29 | }) | ||
| 30 | |||
| 31 | server:add_resource("/api/1/{id:[0-9]+}/check_rockspec", { | ||
| 32 | { | ||
| 33 | method = "GET", | ||
| 34 | path = "/", | ||
| 35 | produces = "application/json", | ||
| 36 | handler = function(query) | ||
| 37 | local json = {} | ||
| 38 | return restserver.response():status(200):entity(json) | ||
| 39 | end | ||
| 40 | } | ||
| 41 | }) | ||
| 42 | |||
| 43 | server:add_resource("/api/1/{id:[0-9]+}/upload", { | ||
| 44 | { | ||
| 45 | method = "POST", | ||
| 46 | path = "/", | ||
| 47 | produces = "application/json", | ||
| 48 | handler = function(query) | ||
| 49 | local json = {module = "luasocket", version = {id = "1.0"}, module_url = "http://localhost/luasocket", manifests = "root", is_new = "is_new"} | ||
| 50 | return restserver.response():status(200):entity(json) | ||
| 51 | end | ||
| 52 | } | ||
| 53 | }) | ||
| 54 | |||
| 55 | server:add_resource("/api/1/{id:[0-9]+}/upload_rock/{id:[0-9]+}", { | ||
| 56 | { | ||
| 57 | method = "POST", | ||
| 58 | path = "/", | ||
| 59 | produces = "application/json", | ||
| 60 | handler = function(query) | ||
| 61 | local json = {"rock","module_url"} | ||
| 62 | return restserver.response():status(200):entity(json) | ||
| 63 | end | ||
| 64 | } | ||
| 65 | }) | ||
| 66 | |||
| 67 | -- SHUTDOWN this mock-server | ||
| 68 | server:add_resource("/shutdown", { | ||
| 69 | { | ||
| 70 | method = "GET", | ||
| 71 | path = "/", | ||
| 72 | handler = function(query) | ||
| 73 | os.exit() | ||
| 74 | return restserver.response():status(200):entity() | ||
| 75 | end | ||
| 76 | } | ||
| 77 | }) | ||
| 78 | |||
| 79 | -- This loads the restserver.xavante plugin | ||
| 80 | server:enable("restserver.xavante"):start() \ No newline at end of file | ||
diff --git a/test/test_environment.lua b/test/test_environment.lua new file mode 100644 index 00000000..13e548f9 --- /dev/null +++ b/test/test_environment.lua | |||
| @@ -0,0 +1,617 @@ | |||
| 1 | local lfs = require("lfs") | ||
| 2 | local test_env = {} | ||
| 3 | |||
| 4 | local help_message = [[ | ||
| 5 | LuaRocks test-suite | ||
| 6 | |||
| 7 | INFORMATION | ||
| 8 | New test-suite for LuaRocks project, using unit testing framework Busted. | ||
| 9 | REQUIREMENTS | ||
| 10 | Be sure sshd is running on your system, or use '--exclude-tags=ssh', | ||
| 11 | to not execute tests which require sshd. | ||
| 12 | USAGE | ||
| 13 | busted [-Xhelper <arguments>] | ||
| 14 | ARGUMENTS | ||
| 15 | env=<type> Set type of environment to use ("minimal" or "full", | ||
| 16 | default: "minimal"). | ||
| 17 | noreset Don't reset environment after each test | ||
| 18 | clean Remove existing testing environment. | ||
| 19 | travis Add if running on TravisCI. | ||
| 20 | os=<type> Set OS ("linux", "osx", or "windows"). | ||
| 21 | ]] | ||
| 22 | |||
| 23 | local function help() | ||
| 24 | print(help_message) | ||
| 25 | os.exit(1) | ||
| 26 | end | ||
| 27 | |||
| 28 | local function title(str) | ||
| 29 | print() | ||
| 30 | print(("-"):rep(#str)) | ||
| 31 | print(str) | ||
| 32 | print(("-"):rep(#str)) | ||
| 33 | end | ||
| 34 | |||
| 35 | local function exists(path) | ||
| 36 | return lfs.attributes(path, "mode") ~= nil | ||
| 37 | end | ||
| 38 | |||
| 39 | function test_env.quiet(commad) | ||
| 40 | if not test_env.VERBOSE then | ||
| 41 | if test_env.TEST_TARGET_OS == "linux" or test_env.TEST_TARGET_OS == "osx" then | ||
| 42 | return commad .. " 1> /dev/null 2> /dev/null" | ||
| 43 | elseif test_env.TEST_TARGET_OS == "windows" then | ||
| 44 | return commad .. " 2> NUL 1> NUL" | ||
| 45 | end | ||
| 46 | else | ||
| 47 | return command | ||
| 48 | end | ||
| 49 | end | ||
| 50 | |||
| 51 | --- Helper function for execute_bool and execute_output | ||
| 52 | -- @param command string: command to execute | ||
| 53 | -- @param print_command boolean: print command if 'true' | ||
| 54 | -- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"} | ||
| 55 | -- @return final_command string: concatenated command to execution | ||
| 56 | function test_env.execute_helper(command, print_command, env_variables) | ||
| 57 | local final_command = "" | ||
| 58 | |||
| 59 | if print_command then | ||
| 60 | print("\n[EXECUTING]: " .. command) | ||
| 61 | end | ||
| 62 | |||
| 63 | if env_variables then | ||
| 64 | final_command = "export " | ||
| 65 | for k,v in pairs(env_variables) do | ||
| 66 | final_command = final_command .. k .. "='" .. v .. "' " | ||
| 67 | end | ||
| 68 | -- remove last space and add ';' to separate exporting variables from command | ||
| 69 | final_command = final_command:sub(1, -2) .. "; " | ||
| 70 | end | ||
| 71 | |||
| 72 | final_command = final_command .. command | ||
| 73 | |||
| 74 | return final_command | ||
| 75 | end | ||
| 76 | |||
| 77 | --- Execute command and returns true/false | ||
| 78 | -- In Lua5.1 os.execute returns numeric value, but in Lua5.2+ returns boolean | ||
| 79 | -- @return true/false boolean: status of the command execution | ||
| 80 | local function execute_bool(command, print_command, env_variables) | ||
| 81 | command = test_env.execute_helper(command, print_command, env_variables) | ||
| 82 | |||
| 83 | local ok = os.execute(command) | ||
| 84 | return ok == true or ok == 0 | ||
| 85 | end | ||
| 86 | |||
| 87 | --- Execute command and returns output of command | ||
| 88 | -- @return output string: output the command execution | ||
| 89 | local function execute_output(command, print_command, env_variables) | ||
| 90 | command = test_env.execute_helper(command, print_command, env_variables) | ||
| 91 | |||
| 92 | local file = assert(io.popen(command)) | ||
| 93 | local output = file:read('*all') | ||
| 94 | file:close() | ||
| 95 | return output:gsub("\n","") -- output adding new line, need to be removed | ||
| 96 | end | ||
| 97 | |||
| 98 | --- Set test_env.LUA_V or test_env.LUAJIT_V based | ||
| 99 | -- on version of Lua used to run this script. | ||
| 100 | function test_env.set_lua_version() | ||
| 101 | if _G.jit then | ||
| 102 | test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d") | ||
| 103 | else | ||
| 104 | test_env.LUA_V = _VERSION:match("5%.%d") | ||
| 105 | end | ||
| 106 | end | ||
| 107 | |||
| 108 | --- Set all arguments from input into global variables | ||
| 109 | function test_env.set_args() | ||
| 110 | -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables | ||
| 111 | test_env.TYPE_TEST_ENV = "minimal" | ||
| 112 | test_env.RESET_ENV = true | ||
| 113 | |||
| 114 | for _, argument in ipairs(arg) do | ||
| 115 | if argument:find("^env=") then | ||
| 116 | test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$") | ||
| 117 | elseif argument == "noreset" then | ||
| 118 | test_env.RESET_ENV = false | ||
| 119 | elseif argument == "clean" then | ||
| 120 | test_env.TEST_ENV_CLEAN = true | ||
| 121 | elseif argument == "verbose" then | ||
| 122 | test_env.VERBOSE = true | ||
| 123 | elseif argument == "travis" then | ||
| 124 | test_env.TRAVIS = true | ||
| 125 | elseif argument:find("^os=") then | ||
| 126 | test_env.TEST_TARGET_OS = argument:match("^os=(.*)$") | ||
| 127 | else | ||
| 128 | help() | ||
| 129 | end | ||
| 130 | end | ||
| 131 | |||
| 132 | if not test_env.TEST_TARGET_OS then | ||
| 133 | title("OS CHECK") | ||
| 134 | |||
| 135 | if execute_bool("sw_vers") then | ||
| 136 | test_env.TEST_TARGET_OS = "osx" | ||
| 137 | elseif execute_bool("uname -s") then | ||
| 138 | test_env.TEST_TARGET_OS = "linux" | ||
| 139 | else | ||
| 140 | test_env.TEST_TARGET_OS = "windows" | ||
| 141 | end | ||
| 142 | end | ||
| 143 | return true | ||
| 144 | end | ||
| 145 | |||
| 146 | --- Remove directory recursively | ||
| 147 | -- @param path string: directory path to delete | ||
| 148 | function test_env.remove_dir(path) | ||
| 149 | if exists(path) then | ||
| 150 | for file in lfs.dir(path) do | ||
| 151 | if file ~= "." and file ~= ".." then | ||
| 152 | local full_path = path..'/'..file | ||
| 153 | |||
| 154 | if lfs.attributes(full_path, "mode") == "directory" then | ||
| 155 | test_env.remove_dir(full_path) | ||
| 156 | else | ||
| 157 | os.remove(full_path) | ||
| 158 | end | ||
| 159 | end | ||
| 160 | end | ||
| 161 | end | ||
| 162 | os.remove(path) | ||
| 163 | end | ||
| 164 | |||
| 165 | --- Remove subdirectories of a directory that match a pattern | ||
| 166 | -- @param path string: path to directory | ||
| 167 | -- @param pattern string: pattern matching basenames of subdirectories to be removed | ||
| 168 | function test_env.remove_subdirs(path, pattern) | ||
| 169 | if exists(path) then | ||
| 170 | for file in lfs.dir(path) do | ||
| 171 | if file ~= "." and file ~= ".." then | ||
| 172 | local full_path = path..'/'..file | ||
| 173 | |||
| 174 | if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then | ||
| 175 | test_env.remove_dir(full_path) | ||
| 176 | end | ||
| 177 | end | ||
| 178 | end | ||
| 179 | end | ||
| 180 | end | ||
| 181 | |||
| 182 | --- Remove files matching a pattern | ||
| 183 | -- @param path string: directory where to delete files | ||
| 184 | -- @param pattern string: pattern matching basenames of files to be deleted | ||
| 185 | -- @return result_check boolean: true if one or more files deleted | ||
| 186 | function test_env.remove_files(path, pattern) | ||
| 187 | local result_check = false | ||
| 188 | if exists(path) then | ||
| 189 | for file in lfs.dir(path) do | ||
| 190 | if file ~= "." and file ~= ".." then | ||
| 191 | if file:find(pattern) then | ||
| 192 | if os.remove(path .. "/" .. file) then | ||
| 193 | result_check = true | ||
| 194 | end | ||
| 195 | end | ||
| 196 | end | ||
| 197 | end | ||
| 198 | end | ||
| 199 | return result_check | ||
| 200 | end | ||
| 201 | |||
| 202 | |||
| 203 | --- Function for downloading rocks and rockspecs | ||
| 204 | -- @param urls table: array of full names of rocks/rockspecs to download | ||
| 205 | -- @param save_path string: path to directory, where to download rocks/rockspecs | ||
| 206 | -- @return make_manifest boolean: true if new rocks downloaded | ||
| 207 | local function download_rocks(urls, save_path) | ||
| 208 | local luarocks_repo = "https://luarocks.org" | ||
| 209 | local make_manifest = false | ||
| 210 | |||
| 211 | for _, url in ipairs(urls) do | ||
| 212 | -- check if already downloaded | ||
| 213 | if not exists(save_path .. url) then | ||
| 214 | execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) | ||
| 215 | make_manifest = true | ||
| 216 | end | ||
| 217 | end | ||
| 218 | return make_manifest | ||
| 219 | end | ||
| 220 | |||
| 221 | --- Create a file containing a string. | ||
| 222 | -- @param path string: path to file. | ||
| 223 | -- @param str string: content of the file. | ||
| 224 | local function write_file(path, str) | ||
| 225 | local file = assert(io.open(path, "w")) | ||
| 226 | file:write(str) | ||
| 227 | file:close() | ||
| 228 | end | ||
| 229 | |||
| 230 | --- Create md5sum of directory structure recursively, based on filename and size | ||
| 231 | -- @param path string: path to directory for generate md5sum | ||
| 232 | -- @return md5sum string: md5sum of directory | ||
| 233 | local function hash_environment(path) | ||
| 234 | if test_env.TEST_TARGET_OS == "linux" then | ||
| 235 | return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") | ||
| 236 | elseif test_env.TEST_TARGET_OS == "osx" then | ||
| 237 | return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") | ||
| 238 | else | ||
| 239 | -- TODO: Windows | ||
| 240 | return "" | ||
| 241 | end | ||
| 242 | end | ||
| 243 | |||
| 244 | --- Create environment variables needed for tests | ||
| 245 | -- @param testing_paths table: table with paths to testing directory | ||
| 246 | -- @return env_variables table: table with created environment variables | ||
| 247 | local function create_env(testing_paths) | ||
| 248 | local luaversion_short = _VERSION:gsub("Lua ", "") | ||
| 249 | |||
| 250 | if test_env.LUAJIT_V then | ||
| 251 | luaversion_short="5.1" | ||
| 252 | end | ||
| 253 | |||
| 254 | local env_variables = {} | ||
| 255 | env_variables.LUA_VERSION = luaversion_short | ||
| 256 | env_variables.LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua" | ||
| 257 | env_variables.LUA_PATH = testing_paths.testing_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" | ||
| 258 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" | ||
| 259 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" | ||
| 260 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" | ||
| 261 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" | ||
| 262 | env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" | ||
| 263 | .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" | ||
| 264 | env_variables.PATH = os.getenv("PATH") .. ":" .. testing_paths.testing_tree .. "/bin:" .. testing_paths.testing_sys_tree .. "/bin" | ||
| 265 | |||
| 266 | return env_variables | ||
| 267 | end | ||
| 268 | |||
| 269 | --- Create md5sums of origin system and system-copy testing directory | ||
| 270 | -- @param testing_paths table: table with paths to testing directory | ||
| 271 | -- @return md5sums table: table of md5sums of system and system-copy testing directory | ||
| 272 | local function create_md5sums(testing_paths) | ||
| 273 | local md5sums = {} | ||
| 274 | md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy) | ||
| 275 | md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy) | ||
| 276 | |||
| 277 | return md5sums | ||
| 278 | end | ||
| 279 | |||
| 280 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) | ||
| 281 | local cmd_prefix = test_env.testing_paths.lua .. " " | ||
| 282 | |||
| 283 | if with_coverage then | ||
| 284 | cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testing_dir .. "/luacov.config')\" " | ||
| 285 | end | ||
| 286 | |||
| 287 | cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " | ||
| 288 | |||
| 289 | return function(cmd, new_vars) | ||
| 290 | local temp_vars = {} | ||
| 291 | for k, v in pairs(test_env.env_variables) do | ||
| 292 | temp_vars[k] = v | ||
| 293 | end | ||
| 294 | if new_vars then | ||
| 295 | for k, v in pairs(new_vars) do | ||
| 296 | temp_vars[k] = v | ||
| 297 | end | ||
| 298 | end | ||
| 299 | return exec_function(cmd_prefix .. cmd, do_print, temp_vars) | ||
| 300 | end | ||
| 301 | end | ||
| 302 | |||
| 303 | local function make_run_functions() | ||
| 304 | return { | ||
| 305 | luarocks = make_run_function("luarocks", execute_output, true, true), | ||
| 306 | luarocks_bool = make_run_function("luarocks", execute_bool, true, true), | ||
| 307 | luarocks_noprint = make_run_function("luarocks", execute_bool, true, false), | ||
| 308 | luarocks_nocov = make_run_function("luarocks", execute_bool, false, true), | ||
| 309 | luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false), | ||
| 310 | luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true), | ||
| 311 | luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true), | ||
| 312 | luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false) | ||
| 313 | } | ||
| 314 | end | ||
| 315 | |||
| 316 | --- Rebuild environment. | ||
| 317 | -- Remove old installed rocks and install new ones, | ||
| 318 | -- updating manifests and tree copies. | ||
| 319 | local function build_environment(rocks, env_variables) | ||
| 320 | title("BUILDING ENVIRONMENT") | ||
| 321 | local testing_paths = test_env.testing_paths | ||
| 322 | test_env.remove_dir(testing_paths.testing_tree) | ||
| 323 | test_env.remove_dir(testing_paths.testing_sys_tree) | ||
| 324 | test_env.remove_dir(testing_paths.testing_tree_copy) | ||
| 325 | test_env.remove_dir(testing_paths.testing_sys_tree_copy) | ||
| 326 | |||
| 327 | lfs.mkdir(testing_paths.testing_tree) | ||
| 328 | lfs.mkdir(testing_paths.testing_sys_tree) | ||
| 329 | |||
| 330 | test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) | ||
| 331 | test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) | ||
| 332 | |||
| 333 | for _, rock in ipairs(rocks) do | ||
| 334 | if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) then | ||
| 335 | test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) | ||
| 336 | test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) | ||
| 337 | execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) | ||
| 338 | end | ||
| 339 | end | ||
| 340 | |||
| 341 | execute_bool("cp -a " .. testing_paths.testing_tree .. "/. " .. testing_paths.testing_tree_copy) | ||
| 342 | execute_bool("cp -a " .. testing_paths.testing_sys_tree .. "/. " .. testing_paths.testing_sys_tree_copy) | ||
| 343 | end | ||
| 344 | |||
| 345 | --- Reset testing environment | ||
| 346 | local function reset_environment(testing_paths, md5sums) | ||
| 347 | local testing_tree_md5 = hash_environment(testing_paths.testing_tree) | ||
| 348 | local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree) | ||
| 349 | |||
| 350 | if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then | ||
| 351 | test_env.remove_dir(testing_paths.testing_tree) | ||
| 352 | execute_bool("cp -a " .. testing_paths.testing_tree_copy .. "/. " .. testing_paths.testing_tree) | ||
| 353 | end | ||
| 354 | |||
| 355 | if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then | ||
| 356 | test_env.remove_dir(testing_paths.testing_sys_tree) | ||
| 357 | execute_bool("cp -a " .. testing_paths.testing_sys_tree_copy .. "/. " .. testing_paths.testing_sys_tree) | ||
| 358 | end | ||
| 359 | |||
| 360 | print("\n[ENVIRONMENT RESET]") | ||
| 361 | end | ||
| 362 | |||
| 363 | local function create_paths(luaversion_full) | ||
| 364 | local cfg = require("luarocks.cfg") | ||
| 365 | |||
| 366 | local testing_paths = {} | ||
| 367 | testing_paths.luadir = cfg.variables.LUA_BINDIR:gsub("/bin/?$", "") | ||
| 368 | testing_paths.lua = cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter | ||
| 369 | |||
| 370 | testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows? | ||
| 371 | |||
| 372 | testing_paths.luarocks_dir = lfs.currentdir() | ||
| 373 | testing_paths.testing_dir = testing_paths.luarocks_dir .. "/test" | ||
| 374 | testing_paths.src_dir = testing_paths.luarocks_dir .. "/src" | ||
| 375 | testing_paths.testing_lrprefix = testing_paths.testing_dir .. "/testing_lrprefix-" .. luaversion_full | ||
| 376 | testing_paths.testing_tree = testing_paths.testing_dir .. "/testing-" .. luaversion_full | ||
| 377 | testing_paths.testing_tree_copy = testing_paths.testing_dir .. "/testing_copy-" .. luaversion_full | ||
| 378 | testing_paths.testing_sys_tree = testing_paths.testing_dir .. "/testing_sys-" .. luaversion_full | ||
| 379 | testing_paths.testing_sys_tree_copy = testing_paths.testing_dir .. "/testing_sys_copy-" .. luaversion_full | ||
| 380 | testing_paths.testing_cache = testing_paths.testing_dir .. "/testing_cache-" .. luaversion_full | ||
| 381 | testing_paths.testing_server = testing_paths.testing_dir .. "/testing_server-" .. luaversion_full | ||
| 382 | |||
| 383 | return testing_paths | ||
| 384 | end | ||
| 385 | |||
| 386 | --- Helper function to unload luarocks modules from global table package.loaded | ||
| 387 | -- Needed to load our local (testing) version of LuaRocks | ||
| 388 | function test_env.unload_luarocks() | ||
| 389 | for modname, _ in pairs(package.loaded) do | ||
| 390 | if modname:match("^luarocks%.") then | ||
| 391 | package.loaded[modname] = nil | ||
| 392 | end | ||
| 393 | end | ||
| 394 | end | ||
| 395 | |||
| 396 | --- Function for initially setup of environment, variables, md5sums for spec files | ||
| 397 | function test_env.setup_specs(extra_rocks) | ||
| 398 | -- if global variable about successful creation of testing environment doesn't exists, build environment | ||
| 399 | if not test_env.setup_done then | ||
| 400 | if test_env.TRAVIS then | ||
| 401 | if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then | ||
| 402 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") | ||
| 403 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") | ||
| 404 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") | ||
| 405 | execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts") | ||
| 406 | end | ||
| 407 | end | ||
| 408 | |||
| 409 | test_env.main() | ||
| 410 | package.path = test_env.env_variables.LUA_PATH | ||
| 411 | |||
| 412 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) | ||
| 413 | test_env.md5sums = create_md5sums(test_env.testing_paths) | ||
| 414 | test_env.setup_done = true | ||
| 415 | title("RUNNING TESTS") | ||
| 416 | end | ||
| 417 | |||
| 418 | if extra_rocks then | ||
| 419 | local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) | ||
| 420 | if make_manifest then | ||
| 421 | test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) | ||
| 422 | end | ||
| 423 | end | ||
| 424 | |||
| 425 | if test_env.RESET_ENV then | ||
| 426 | reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) | ||
| 427 | end | ||
| 428 | end | ||
| 429 | |||
| 430 | --- Test if required rock is installed if not, install it | ||
| 431 | function test_env.need_rock(rock) | ||
| 432 | print("Check if " .. rock .. " is installed") | ||
| 433 | if test_env.run.luarocks_noprint_nocov(test_env.quiet("show " .. rock)) then | ||
| 434 | return true | ||
| 435 | else | ||
| 436 | return test_env.run.luarocks_noprint_nocov(test_env.quiet("install " .. rock)) | ||
| 437 | end | ||
| 438 | end | ||
| 439 | |||
| 440 | --- For each key-value pair in replacements table | ||
| 441 | -- replace %{key} in given string with value. | ||
| 442 | local function substitute(str, replacements) | ||
| 443 | return (str:gsub("%%%b{}", function(marker) | ||
| 444 | return replacements[marker:sub(3, -2)] | ||
| 445 | end)) | ||
| 446 | end | ||
| 447 | |||
| 448 | |||
| 449 | --- Create configs for luacov and several versions of Luarocks | ||
| 450 | -- configs needed for some tests. | ||
| 451 | local function create_configs() | ||
| 452 | -- testing_config.lua and testing_config_show_downloads.lua | ||
| 453 | local config_content = substitute([[ | ||
| 454 | rocks_trees = { | ||
| 455 | "%{testing_tree}", | ||
| 456 | { name = "system", root = "%{testing_sys_tree}" }, | ||
| 457 | } | ||
| 458 | rocks_servers = { | ||
| 459 | "%{testing_server}" | ||
| 460 | } | ||
| 461 | local_cache = "%{testing_cache}" | ||
| 462 | upload_server = "testing" | ||
| 463 | upload_user = "%{user}" | ||
| 464 | upload_servers = { | ||
| 465 | testing = { | ||
| 466 | rsync = "localhost/tmp/luarocks_testing", | ||
| 467 | }, | ||
| 468 | } | ||
| 469 | external_deps_dirs = { | ||
| 470 | "/usr/local", | ||
| 471 | "/usr", | ||
| 472 | -- These are used for a test that fails, so it | ||
| 473 | -- can point to invalid paths: | ||
| 474 | { | ||
| 475 | prefix = "/opt", | ||
| 476 | bin = "bin", | ||
| 477 | include = "include", | ||
| 478 | lib = { "lib", "lib64" }, | ||
| 479 | } | ||
| 480 | } | ||
| 481 | ]], { | ||
| 482 | user = os.getenv("USER"), | ||
| 483 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | ||
| 484 | testing_tree = test_env.testing_paths.testing_tree, | ||
| 485 | testing_server = test_env.testing_paths.testing_server, | ||
| 486 | testing_cache = test_env.testing_paths.testing_cache | ||
| 487 | }) | ||
| 488 | |||
| 489 | write_file(test_env.testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") | ||
| 490 | write_file(test_env.testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content | ||
| 491 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") | ||
| 492 | |||
| 493 | -- testing_config_sftp.lua | ||
| 494 | config_content = substitute([[ | ||
| 495 | rocks_trees = { | ||
| 496 | "%{testing_tree}", | ||
| 497 | "%{testing_sys_tree}", | ||
| 498 | } | ||
| 499 | local_cache = "%{testing_cache}" | ||
| 500 | upload_server = "testing" | ||
| 501 | upload_user = "%{user}" | ||
| 502 | upload_servers = { | ||
| 503 | testing = { | ||
| 504 | sftp = "localhost/tmp/luarocks_testing", | ||
| 505 | }, | ||
| 506 | } | ||
| 507 | ]], { | ||
| 508 | user = os.getenv("USER"), | ||
| 509 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | ||
| 510 | testing_tree = test_env.testing_paths.testing_tree, | ||
| 511 | testing_cache = test_env.testing_paths.testing_cache | ||
| 512 | }) | ||
| 513 | |||
| 514 | write_file(test_env.testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) | ||
| 515 | |||
| 516 | -- luacov.config | ||
| 517 | config_content = substitute([[ | ||
| 518 | return { | ||
| 519 | statsfile = "%{testing_dir}/luacov.stats.out", | ||
| 520 | reportfile = "%{testing_dir}/luacov.report.out", | ||
| 521 | modules = { | ||
| 522 | ["luarocks"] = "src/bin/luarocks", | ||
| 523 | ["luarocks-admin"] = "src/bin/luarocks-admin", | ||
| 524 | ["luarocks.*"] = "src", | ||
| 525 | ["luarocks.*.*"] = "src", | ||
| 526 | ["luarocks.*.*.*"] = "src" | ||
| 527 | } | ||
| 528 | } | ||
| 529 | ]], { | ||
| 530 | testing_dir = test_env.testing_paths.testing_dir | ||
| 531 | }) | ||
| 532 | |||
| 533 | write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content) | ||
| 534 | end | ||
| 535 | |||
| 536 | --- Remove testing directories. | ||
| 537 | local function clean() | ||
| 538 | print("Cleaning testing directory...") | ||
| 539 | test_env.remove_dir(test_env.testing_paths.luarocks_tmp) | ||
| 540 | test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]") | ||
| 541 | test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") | ||
| 542 | test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") | ||
| 543 | test_env.remove_files(test_env.testing_paths.testing_dir, "upload_config") | ||
| 544 | print("Cleaning done!") | ||
| 545 | end | ||
| 546 | |||
| 547 | --- Install luarocks into testing prefix. | ||
| 548 | local function install_luarocks(install_env_vars) | ||
| 549 | -- Configure LuaRocks testing environment | ||
| 550 | title("Installing LuaRocks") | ||
| 551 | local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. " --prefix=" .. test_env.testing_paths.testing_lrprefix | ||
| 552 | assert(execute_bool(test_env.quiet(configure_cmd), false, install_env_vars)) | ||
| 553 | assert(execute_bool(test_env.quiet("make clean"), false, install_env_vars)) | ||
| 554 | assert(execute_bool(test_env.quiet("make src/luarocks/site_config.lua"), false, install_env_vars)) | ||
| 555 | assert(execute_bool(test_env.quiet("make dev"), false, install_env_vars)) | ||
| 556 | print("LuaRocks installed correctly!") | ||
| 557 | end | ||
| 558 | |||
| 559 | --- | ||
| 560 | -- Main function to create config files and testing environment | ||
| 561 | function test_env.main() | ||
| 562 | local testing_paths = test_env.testing_paths | ||
| 563 | |||
| 564 | if test_env.TEST_ENV_CLEAN then | ||
| 565 | clean() | ||
| 566 | end | ||
| 567 | |||
| 568 | lfs.mkdir(testing_paths.testing_cache) | ||
| 569 | lfs.mkdir(testing_paths.luarocks_tmp) | ||
| 570 | |||
| 571 | create_configs() | ||
| 572 | |||
| 573 | local install_env_vars = { | ||
| 574 | LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua", | ||
| 575 | LUA_PATH = "", | ||
| 576 | LUA_CPATH = "" | ||
| 577 | } | ||
| 578 | |||
| 579 | install_luarocks(install_env_vars) | ||
| 580 | |||
| 581 | -- Preparation of rocks for building environment | ||
| 582 | local rocks = {} -- names of rocks, required for building environment | ||
| 583 | local urls = {} -- names of rock and rockspec files to be downloaded | ||
| 584 | table.insert(urls, "/luacov-0.11.0-1.rockspec") | ||
| 585 | table.insert(urls, "/luacov-0.11.0-1.src.rock") | ||
| 586 | |||
| 587 | if test_env.TYPE_TEST_ENV == "full" then | ||
| 588 | table.insert(urls, "/luafilesystem-1.6.3-1.src.rock") | ||
| 589 | table.insert(urls, "/luasocket-3.0rc1-1.src.rock") | ||
| 590 | table.insert(urls, "/luasocket-3.0rc1-1.rockspec") | ||
| 591 | table.insert(urls, "/luaposix-33.2.1-1.src.rock") | ||
| 592 | table.insert(urls, "/md5-1.2-1.src.rock") | ||
| 593 | table.insert(urls, "/lzlib-0.4.1.53-1.src.rock") | ||
| 594 | rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} | ||
| 595 | |||
| 596 | if test_env.LUA_V ~= "5.1" then | ||
| 597 | table.insert(urls, "/luabitop-1.0.2-1.rockspec") | ||
| 598 | table.insert(urls, "/luabitop-1.0.2-1.src.rock") | ||
| 599 | table.insert(rocks, "luabitop") | ||
| 600 | end | ||
| 601 | end | ||
| 602 | |||
| 603 | table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment | ||
| 604 | |||
| 605 | -- Download rocks needed for LuaRocks testing environment | ||
| 606 | lfs.mkdir(testing_paths.testing_server) | ||
| 607 | download_rocks(urls, testing_paths.testing_server) | ||
| 608 | build_environment(rocks, install_env_vars) | ||
| 609 | end | ||
| 610 | |||
| 611 | test_env.set_lua_version() | ||
| 612 | test_env.set_args() | ||
| 613 | test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) | ||
| 614 | test_env.env_variables = create_env(test_env.testing_paths) | ||
| 615 | test_env.run = make_run_functions() | ||
| 616 | |||
| 617 | return test_env | ||
diff --git a/test/testfiles/invalid_validate-args-1.5.4-1.rockspec b/test/testfiles/invalid_validate-args-1.5.4-1.rockspec new file mode 100644 index 00000000..0b4d807d --- /dev/null +++ b/test/testfiles/invalid_validate-args-1.5.4-1.rockspec | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | package = 'validate-args' | ||
| 2 | version = '1.5.4-1' | ||
| 3 | source = {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{++{ | ||
| 4 | url = "https://bitbucket.org/djerius/validate.args/downloads/validate-args-1.5.4.tar.gz" | ||
| 5 | } | ||
| 6 | |||
| 7 | description = { | ||
| 8 | summary = "Function argument validation", | ||
| 9 | detailed = [[ | ||
| 10 | validate.args is a Lua module that provides a framework for | ||
| 11 | validation of arguments to Lua functions as well as complex data | ||
| 12 | structures. The included validate.inplace module provides "live" | ||
| 13 | validation during assignment of values to elements in tables. ]], | ||
| 14 | license = "GPL-3", | ||
| 15 | |||
| 16 | } | ||
| 17 | |||
| 18 | dependencies = { | ||
| 19 | "lua >= 5.1" | ||
| 20 | } | ||
| 21 | |||
| 22 | build = { | ||
| 23 | |||
| 24 | type = "builtin", | ||
| 25 | |||
| 26 | modules = { | ||
| 27 | ["validate.args"] = "validate/args.lua", | ||
| 28 | ["validate.inplace"] = "validate/inplace.lua", | ||
| 29 | }, | ||
| 30 | |||
| 31 | copy_directories = { | ||
| 32 | "doc", "tests" | ||
| 33 | } | ||
| 34 | |||
| 35 | } | ||
diff --git a/test/testing.lua b/test/testing.lua deleted file mode 100644 index 1a837484..00000000 --- a/test/testing.lua +++ /dev/null | |||
| @@ -1,483 +0,0 @@ | |||
| 1 | |||
| 2 | local variables = {} | ||
| 3 | |||
| 4 | -- Expand variables in the format $foo or ${foo} according | ||
| 5 | -- to the variables table. | ||
| 6 | local function expand_variables(str) | ||
| 7 | return str:gsub("%$({?)([A-Za-z0-9_]+)(}?)", function(o, v, c) | ||
| 8 | return #o <= #c and (variables[v] or "") .. (#o < #c and c or "") | ||
| 9 | end) | ||
| 10 | end | ||
| 11 | |||
| 12 | -- @param cmd command to run | ||
| 13 | -- @param envtable optional table of temporary environment variables | ||
| 14 | local function run(cmd, envtable) | ||
| 15 | cmd = expand_variables(cmd) | ||
| 16 | local env = {} | ||
| 17 | for var, val in pairs(envtable) do | ||
| 18 | table.insert(env, var.."='"..expand_variables(val).."' ") | ||
| 19 | end | ||
| 20 | local code = os.execute(table.concat(env)..cmd) | ||
| 21 | return (code == 0 or code == true) | ||
| 22 | end | ||
| 23 | |||
| 24 | local function cd_run(dir, cmd, envtable) | ||
| 25 | return run("cd "..dir.." && "..cmd, envtable) | ||
| 26 | end | ||
| 27 | |||
| 28 | local function run_get_contents(cmd) | ||
| 29 | end | ||
| 30 | |||
| 31 | local function mkdir(dirname) | ||
| 32 | cmd = expand_variables(dirname) | ||
| 33 | -- TODO | ||
| 34 | end | ||
| 35 | |||
| 36 | local function rm_rf(...) | ||
| 37 | -- TODO | ||
| 38 | end | ||
| 39 | |||
| 40 | local function mv(src, dst) | ||
| 41 | -- TODO | ||
| 42 | end | ||
| 43 | |||
| 44 | local function exists(filename) | ||
| 45 | filename = expand_variables(filename) | ||
| 46 | -- TODO | ||
| 47 | end | ||
| 48 | |||
| 49 | local function glob(patt) | ||
| 50 | -- TODO | ||
| 51 | end | ||
| 52 | |||
| 53 | local function touch(filename) | ||
| 54 | -- TODO | ||
| 55 | end | ||
| 56 | |||
| 57 | local function rm(...) | ||
| 58 | for _, filename in ipairs {...} do | ||
| 59 | filename = expand_variables(filename) | ||
| 60 | -- TODO | ||
| 61 | end | ||
| 62 | return true | ||
| 63 | end | ||
| 64 | |||
| 65 | local function file_set_contents(filename, contents) | ||
| 66 | filename = expand_variables(filename) | ||
| 67 | |||
| 68 | local fd, err = io.open(filename, "w") | ||
| 69 | if not fd then return nil, err end | ||
| 70 | fd:write(contents) | ||
| 71 | fd:close() | ||
| 72 | return true | ||
| 73 | end | ||
| 74 | |||
| 75 | local function need_luasocket() | ||
| 76 | -- TODO | ||
| 77 | end | ||
| 78 | |||
| 79 | local tests = { | ||
| 80 | |||
| 81 | test_version = function() return run "$luarocks --version" end, | ||
| 82 | fail_unknown_command = function() return run "$luarocks unknown_command" end, | ||
| 83 | fail_arg_boolean_parameter = function() return run "$luarocks --porcelain=invalid" end, | ||
| 84 | fail_arg_boolean_unknown = function() return run "$luarocks --invalid-flag" end, | ||
| 85 | fail_arg_string_no_parameter = function() return run "$luarocks --server" end, | ||
| 86 | fail_arg_string_followed_by_flag = function() return run "$luarocks --server --porcelain" end, | ||
| 87 | fail_arg_string_unknown = function() return run "$luarocks --invalid-flag=abc" end, | ||
| 88 | test_empty_list = function() return run "$luarocks list" end, | ||
| 89 | test_list_outdated = function () return run "$luarocks list --outdated" end, | ||
| 90 | fail_sysconfig_err = function() | ||
| 91 | mkdir "$testing_lrprefix/etc/luarocks" | ||
| 92 | file_set_contents("$testing_lrprefix/etc/luarocks/config.lua", "aoeui") | ||
| 93 | return run "$luarocks list" | ||
| 94 | and rm "$testing_lrprefix/etc/luarocks/config.lua" | ||
| 95 | end, | ||
| 96 | fail_sysconfig_default_err = function() | ||
| 97 | mkdir "$testing_lrprefix/etc/luarocks" | ||
| 98 | file_set_contents("$testing_lrprefix/etc/luarocks/config-$luashortversion.lua", "aoeui") | ||
| 99 | return run "$luarocks list" | ||
| 100 | and rm "$testing_lrprefix/etc/luarocks/config-$luashortversion.lua" | ||
| 101 | end, | ||
| 102 | fail_build_noarg = function() return run "$luarocks build" end, | ||
| 103 | fail_download_noarg = function() return run "$luarocks download" end, | ||
| 104 | fail_install_noarg = function() return run "$luarocks install" end, | ||
| 105 | fail_lint_noarg = function() return run "$luarocks lint" end, | ||
| 106 | fail_search_noarg = function() return run "$luarocks search" end, | ||
| 107 | fail_show_noarg = function() return run "$luarocks show" end, | ||
| 108 | fail_unpack_noarg = function() return run "$luarocks unpack" end, | ||
| 109 | fail_upload_noarg = function() return run "$luarocks upload" end, | ||
| 110 | fail_remove_noarg = function() return run "$luarocks remove" end, | ||
| 111 | fail_doc_noarg = function() return run "$luarocks doc" end, | ||
| 112 | fail_new_version_noarg = function() return run "$luarocks new_version" end, | ||
| 113 | fail_write_rockspec_noarg = function() return run "$luarocks write_rockspec" end, | ||
| 114 | fail_build_invalid = function() return run "$luarocks build invalid" end, | ||
| 115 | fail_download_invalid = function() return run "$luarocks download invalid" end, | ||
| 116 | fail_install_invalid = function() return run "$luarocks install invalid" end, | ||
| 117 | fail_lint_invalid = function() return run "$luarocks lint invalid" end, | ||
| 118 | fail_show_invalid = function() return run "$luarocks show invalid" end, | ||
| 119 | fail_new_version_invalid = function() return run "$luarocks new_version invalid" end, | ||
| 120 | test_list_invalidtree = function() return run "$luarocks --tree=/some/invalid/tree list" end, | ||
| 121 | fail_inexistent_dir = function() | ||
| 122 | -- Unix only? | ||
| 123 | return run "mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err" | ||
| 124 | end, | ||
| 125 | fail_make_norockspec = function() return run "$luarocks make" end, | ||
| 126 | fail_build_permissions = function() return run "$luarocks build --tree=/usr lpeg" end, | ||
| 127 | fail_build_permissions_parent = function() return run "$luarocks build --tree=/usr/invalid lpeg" end, | ||
| 128 | test_build_verbose = function() return run "$luarocks build --verbose lpeg" end, | ||
| 129 | fail_build_blank_arg = function() return run "$luarocks build --tree="" lpeg" end, | ||
| 130 | test_build_withpatch = function() need_luasocket(); return run "$luarocks build luadoc" end, | ||
| 131 | test_build_diffversion = function() return run "$luarocks build luacov ${version_luacov}" end, | ||
| 132 | test_build_command = function() return run "$luarocks build stdlib" end, | ||
| 133 | test_build_install_bin = function() return run "$luarocks build luarepl" end, | ||
| 134 | test_build_nohttps = function() | ||
| 135 | need_luasocket() | ||
| 136 | return run "$luarocks download --rockspec validate-args ${verrev_validate_args}" | ||
| 137 | and run "$luarocks build ./validate-args-${version_validate_args}-1.rockspec" | ||
| 138 | and rm "./validate-args-${version_validate_args}-1.rockspec" | ||
| 139 | end, | ||
| 140 | test_build_https = function() | ||
| 141 | need_luasocket() | ||
| 142 | return run "$luarocks download --rockspec validate-args ${verrev_validate_args}" | ||
| 143 | and run "$luarocks install luasec" | ||
| 144 | and run "$luarocks build ./validate-args-${verrev_validate_args}.rockspec" | ||
| 145 | and rm "./validate-args-${verrev_validate_args}.rockspec" | ||
| 146 | end, | ||
| 147 | test_build_supported_platforms = function() return run "$luarocks build lpty" end, | ||
| 148 | test_build_only_deps_rockspec = function() | ||
| 149 | return run "$luarocks download --rockspec lxsh ${verrev_lxsh}" | ||
| 150 | and run "$luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps" | ||
| 151 | and (not run "$luarocks show lxsh") | ||
| 152 | end, | ||
| 153 | test_build_only_deps_src_rock = function() | ||
| 154 | return run "$luarocks download --source lxsh ${verrev_lxsh}" | ||
| 155 | and run "$luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps" | ||
| 156 | and (not run "$luarocks show lxsh") | ||
| 157 | end, | ||
| 158 | test_build_only_deps = function() return run "$luarocks build luasec --only-deps" and (not run "$luarocks show luasec") end, | ||
| 159 | test_install_only_deps = function() return run "$luarocks install lxsh ${verrev_lxsh} --only-deps" and (not run "$luarocks show lxsh") end, | ||
| 160 | fail_build_missing_external = function() return run '$luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"' end, | ||
| 161 | fail_build_invalidpatch = function() | ||
| 162 | need_luasocket() | ||
| 163 | return run '$luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"' | ||
| 164 | end, | ||
| 165 | test_build_deps_partial_match = function() return run "$luarocks build lmathx" end, | ||
| 166 | test_build_show_downloads = function() | ||
| 167 | return run("$luarocks build alien", { LUAROCKS_CONFIG="$testing_dir/testing_config_show_downloads.lua" }) | ||
| 168 | end, | ||
| 169 | test_download_all = function() | ||
| 170 | return run "$luarocks download --all validate-args" | ||
| 171 | and rm(glob("validate-args-*")) | ||
| 172 | end, | ||
| 173 | test_download_rockspecversion = function() | ||
| 174 | return run "$luarocks download --rockspec validate-args ${verrev_validate_args}" | ||
| 175 | and rm(glob("validate-args-*")) | ||
| 176 | end, | ||
| 177 | test_help = function() return run "$luarocks help" end, | ||
| 178 | fail_help_invalid = function() return run "$luarocks help invalid" end, | ||
| 179 | test_install_binaryrock = function() | ||
| 180 | return run "$luarocks build --pack-binary-rock cprint" | ||
| 181 | and run "$luarocks install ./cprint-${verrev_cprint}.${platform}.rock" | ||
| 182 | and rm "./cprint-${verrev_cprint}.${platform}.rock" | ||
| 183 | end, | ||
| 184 | test_install_with_bin = function() return run "$luarocks install wsapi" end, | ||
| 185 | fail_install_notazipfile = function() return run '$luarocks install "$testing_dir/testfiles/not_a_zipfile-1.0-1.src.rock"' end, | ||
| 186 | fail_install_invalidpatch = function() | ||
| 187 | need_luasocket() | ||
| 188 | return run '$luarocks install "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"' | ||
| 189 | end, | ||
| 190 | fail_install_invalid_filename = function() return run '$luarocks install "invalid.rock"' end, | ||
| 191 | fail_install_invalid_arch = function() return run '$luarocks install "foo-1.0-1.impossible-x86.rock"' end, | ||
| 192 | test_install_reinstall = function() | ||
| 193 | return run '$luarocks install "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"' | ||
| 194 | and run '$luarocks install --deps-mode=none "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"' | ||
| 195 | end, | ||
| 196 | fail_local_root = function() return run("$luarocks install --local luasocket", { USER="root" }) end, | ||
| 197 | test_site_config = function() | ||
| 198 | mv("../src/luarocks/site_config.lua", "../src/luarocks/site_config.lua.tmp") | ||
| 199 | local ok = run "$luarocks" | ||
| 200 | mv("../src/luarocks/site_config.lua.tmp", "../src/luarocks/site_config.lua") | ||
| 201 | return ok | ||
| 202 | end, | ||
| 203 | test_lint_ok = function() | ||
| 204 | return run "$luarocks download --rockspec validate-args ${verrev_validate_args}" | ||
| 205 | and run "$luarocks lint ./validate-args-${verrev_validate_args}.rockspec" | ||
| 206 | and rm "./validate-args-${verrev_validate_args}.rockspec" | ||
| 207 | end, | ||
| 208 | fail_lint_type_mismatch_string = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_string-1.0-1.rockspec"' end, | ||
| 209 | fail_lint_type_mismatch_version = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_version-1.0-1.rockspec"' end, | ||
| 210 | fail_lint_type_mismatch_table = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_table-1.0-1.rockspec"' end, | ||
| 211 | fail_lint_no_build_table = function() return run '$luarocks lint "$testing_dir/testfiles/no_build_table-0.1-1.rockspec"' end, | ||
| 212 | test_list = function() return run "$luarocks list" end, | ||
| 213 | test_list_porcelain = function() return run "$luarocks list --porcelain" end, | ||
| 214 | test_make_with_rockspec = function() | ||
| 215 | return rm_rf "./luasocket-${verrev_luasocket}" | ||
| 216 | and run "$luarocks download --source luasocket" | ||
| 217 | and run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock" | ||
| 218 | and cd_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make luasocket-${verrev_luasocket}.rockspec") | ||
| 219 | and rm_rf "./luasocket-${verrev_luasocket}" | ||
| 220 | end, | ||
| 221 | test_make_default_rockspec = function() | ||
| 222 | return rm_rf "./lxsh-${verrev_lxsh}" | ||
| 223 | and run "$luarocks download --source lxsh ${verrev_lxsh}" | ||
| 224 | and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock" | ||
| 225 | and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", "$luarocks make") | ||
| 226 | and rm_rf "./lxsh-${verrev_lxsh}" | ||
| 227 | end, | ||
| 228 | test_make_pack_binary_rock = function() | ||
| 229 | return rm_rf "./lxsh-${verrev_lxsh}" | ||
| 230 | and run "$luarocks download --source lxsh ${verrev_lxsh}" | ||
| 231 | and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock" | ||
| 232 | and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", "$luarocks make --deps-mode=none --pack-binary-rock") | ||
| 233 | and exists "lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1/lxsh-${verrev_lxsh}.all.rock" | ||
| 234 | and rm_rf "./lxsh-${verrev_lxsh}" | ||
| 235 | end, | ||
| 236 | fail_make_which_rockspec = function() | ||
| 237 | rm_rf "./luasocket-${verrev_luasocket}" | ||
| 238 | run "$luarocks download --source luasocket" | ||
| 239 | run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock" | ||
| 240 | local ok = cd_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make") | ||
| 241 | rm_rf "./luasocket-${verrev_luasocket}" | ||
| 242 | return ok | ||
| 243 | end, | ||
| 244 | test_new_version = function() | ||
| 245 | return run "$luarocks download --rockspec luacov ${version_luacov}" | ||
| 246 | and run "$luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2" | ||
| 247 | and rm(glob("./luacov-0.*")) | ||
| 248 | end, | ||
| 249 | test_new_version_url = function() | ||
| 250 | return run "$luarocks download --rockspec abelhas 1.0" | ||
| 251 | and run "$luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz" | ||
| 252 | and rm(glob("./abelhas-*")) | ||
| 253 | end, | ||
| 254 | test_pack = function() | ||
| 255 | return run "$luarocks list" | ||
| 256 | and run "$luarocks pack luacov" | ||
| 257 | and rm(glob("./luacov-*.rock")) | ||
| 258 | end, | ||
| 259 | test_pack_src = function() | ||
| 260 | return run "$luarocks install luasec" | ||
| 261 | and run "$luarocks download --rockspec luasocket" | ||
| 262 | and run "$luarocks pack ./luasocket-${verrev_luasocket}.rockspec" | ||
| 263 | and rm(glob("./luasocket-${version_luasocket}-*.rock")) | ||
| 264 | end, | ||
| 265 | test_path = function() return run "$luarocks path --bin" end, | ||
| 266 | test_path_lr_path = function() return run "$luarocks path --lr-path" end, | ||
| 267 | test_path_lr_cpath = function() return run "$luarocks path --lr-cpath" end, | ||
| 268 | test_path_lr_bin = function() return run "$luarocks path --lr-bin" end, | ||
| 269 | test_path_with_tree = function() return run "$luarocks path --tree=lua_modules" end, | ||
| 270 | fail_purge_missing_tree = function() return run '$luarocks purge --tree="$testing_tree"' end, | ||
| 271 | test_purge = function() return run '$luarocks purge --tree="$testing_sys_tree"' end, | ||
| 272 | test_remove = function() | ||
| 273 | return run "$luarocks build abelhas ${version_abelhas}" | ||
| 274 | and run "$luarocks remove abelhas ${version_abelhas}" | ||
| 275 | end, | ||
| 276 | test_remove_force = function() | ||
| 277 | need_luasocket() | ||
| 278 | return run "$luarocks build lualogging" | ||
| 279 | and run "$luarocks remove --force luasocket" | ||
| 280 | end, | ||
| 281 | fail_remove_deps = function() | ||
| 282 | need_luasocket() | ||
| 283 | return run "$luarocks build lualogging" | ||
| 284 | and run "$luarocks remove luasocket" | ||
| 285 | end, | ||
| 286 | fail_remove_missing = function() return run "$luarocks remove missing_rock" end, | ||
| 287 | fail_remove_invalid_name = function() return run "$luarocks remove invalid.rock" end, | ||
| 288 | test_search_found = function() return run "$luarocks search zlib" end, | ||
| 289 | test_search_missing = function() return run "$luarocks search missing_rock" end, | ||
| 290 | test_show = function() return run "$luarocks show luacov" end, | ||
| 291 | test_show_modules = function() return run "$luarocks show --modules luacov" end, | ||
| 292 | test_show_home = function() return run "$luarocks show --home luacov" end, | ||
| 293 | test_show_depends = function() | ||
| 294 | need_luasocket() | ||
| 295 | return run "$luarocks install luasec" | ||
| 296 | and run "$luarocks show luasec" | ||
| 297 | end, | ||
| 298 | test_show_oldversion = function() | ||
| 299 | return run "$luarocks install luacov ${version_luacov}" | ||
| 300 | and run "$luarocks show luacov ${version_luacov}" | ||
| 301 | end, | ||
| 302 | test_unpack_download = function() | ||
| 303 | return rm_rf "./cprint-${verrev_cprint}" | ||
| 304 | and run "$luarocks unpack cprint" | ||
| 305 | and rm_rf "./cprint-${verrev_cprint}" | ||
| 306 | end, | ||
| 307 | test_unpack_src = function() | ||
| 308 | return rm_rf "./cprint-${verrev_cprint}" | ||
| 309 | and run "$luarocks download --source cprint" | ||
| 310 | and run "$luarocks unpack ./cprint-${verrev_cprint}.src.rock" | ||
| 311 | and rm_rf "./cprint-${verrev_cprint}" | ||
| 312 | end, | ||
| 313 | test_unpack_rockspec = function() | ||
| 314 | return rm_rf "./cprint-${verrev_cprint}" | ||
| 315 | and run "$luarocks download --rockspec cprint" | ||
| 316 | and run "$luarocks unpack ./cprint-${verrev_cprint}.rockspec" | ||
| 317 | and rm_rf "./cprint-${verrev_cprint}" | ||
| 318 | end, | ||
| 319 | test_unpack_binary = function() | ||
| 320 | return rm_rf "./cprint-${verrev_cprint}" | ||
| 321 | and run "$luarocks build cprint" | ||
| 322 | and run "$luarocks pack cprint" | ||
| 323 | and run "$luarocks unpack ./cprint-${verrev_cprint}.${platform}.rock" | ||
| 324 | and rm_rf "./cprint-${verrev_cprint}" | ||
| 325 | end, | ||
| 326 | fail_unpack_invalidpatch = function() | ||
| 327 | need_luasocket() | ||
| 328 | return run '$luarocks unpack "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"' | ||
| 329 | end, | ||
| 330 | fail_unpack_invalidrockspec = function() | ||
| 331 | need_luasocket() | ||
| 332 | return run '$luarocks unpack "invalid.rockspec"' | ||
| 333 | end, | ||
| 334 | fail_upload_invalidrockspec = function() return run '$luarocks upload "invalid.rockspec"' end, | ||
| 335 | fail_upload_invalidkey = function() return run '$luarocks upload --api-key="invalid" "invalid.rockspec"' end, | ||
| 336 | test_admin_help = function() return run "$luarocks_admin help" end, | ||
| 337 | test_admin_make_manifest = function() return run "$luarocks_admin make_manifest" end, | ||
| 338 | test_admin_add_rsync = function() return run '$luarocks_admin --server=testing add "$testing_server/luasocket-${verrev_luasocket}.src.rock"' end, | ||
| 339 | test_admin_add_sftp = function() | ||
| 340 | return run("$luarocks_admin --server=testing add ./luasocket-${verrev_luasocket}.src.rock", { LUAROCKS_CONFIG="$testing_dir/testing_config_sftp.lua" }) | ||
| 341 | end, | ||
| 342 | fail_admin_add_missing = function() return run "$luarocks_admin --server=testing add" end, | ||
| 343 | fail_admin_invalidserver = function() return run '$luarocks_admin --server=invalid add "$testing_server/luasocket-${verrev_luasocket}.src.rock"' end, | ||
| 344 | fail_admin_invalidrock = function() return run "$luarocks_admin --server=testing add invalid" end, | ||
| 345 | test_admin_refresh_cache = function() return run "$luarocks_admin --server=testing refresh_cache" end, | ||
| 346 | test_admin_remove = function() return run "$luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock" end, | ||
| 347 | fail_admin_remove_missing = function() return run "$luarocks_admin --server=testing remove" end, | ||
| 348 | fail_deps_mode_invalid_arg = function() return run "$luarocks remove luacov --deps-mode" end, | ||
| 349 | |||
| 350 | test_deps_mode_one = function() | ||
| 351 | return run '$luarocks build --tree="system" lpeg' | ||
| 352 | and run '$luarocks list' | ||
| 353 | and run '$luarocks build --deps-mode=one --tree="$testing_tree" lxsh' | ||
| 354 | and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' ~= "" | ||
| 355 | end, | ||
| 356 | test_deps_mode_order = function() | ||
| 357 | return run '$luarocks build --tree="system" lpeg' | ||
| 358 | and run '$luarocks build --deps-mode=order --tree="$testing_tree" lxsh' | ||
| 359 | and run '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' | ||
| 360 | and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == "" | ||
| 361 | end, | ||
| 362 | test_deps_mode_order_sys = function() | ||
| 363 | return run '$luarocks build --tree="$testing_tree" lpeg' | ||
| 364 | and run '$luarocks build --deps-mode=order --tree="$testing_sys_tree" lxsh' | ||
| 365 | and run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' ~= "" | ||
| 366 | end, | ||
| 367 | test_deps_mode_all_sys = function() | ||
| 368 | return run '$luarocks build --tree="$testing_tree" lpeg' | ||
| 369 | and run '$luarocks build --deps-mode=all --tree="$testing_sys_tree" lxsh' | ||
| 370 | and run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' == "" | ||
| 371 | end, | ||
| 372 | |||
| 373 | test_deps_mode_none = function() | ||
| 374 | return run '$luarocks build --tree="$testing_tree" --deps-mode=none lxsh' | ||
| 375 | and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == "" | ||
| 376 | end, | ||
| 377 | test_deps_mode_nodeps_alias = function() | ||
| 378 | return run '$luarocks build --tree="$testing_tree" --nodeps lxsh' | ||
| 379 | and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == "" | ||
| 380 | end, | ||
| 381 | test_deps_mode_make_order = function() | ||
| 382 | local ok = run '$luarocks build --tree="$testing_sys_tree" lpeg' | ||
| 383 | and rm_rf "./lxsh-${verrev_lxsh}" | ||
| 384 | and run "$luarocks download --source lxsh ${verrev_lxsh}" | ||
| 385 | and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock" | ||
| 386 | and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", '$luarocks make --tree="$testing_tree" --deps-mode=order') | ||
| 387 | if not ok then | ||
| 388 | return false | ||
| 389 | end | ||
| 390 | local found = run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' | ||
| 391 | rm_rf "./lxsh-${verrev_lxsh}" | ||
| 392 | return found == "" | ||
| 393 | end, | ||
| 394 | test_deps_mode_make_order_sys = function() | ||
| 395 | local ok = run '$luarocks build --tree="$testing_tree" lpeg' | ||
| 396 | and rm_rf "./lxsh-${verrev_lxsh}" | ||
| 397 | and run "$luarocks download --source lxsh ${verrev_lxsh}" | ||
| 398 | and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock" | ||
| 399 | and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", '$luarocks make --tree="$testing_sys_tree" --deps-mode=order') | ||
| 400 | if not ok then | ||
| 401 | return false | ||
| 402 | end | ||
| 403 | local found = run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' | ||
| 404 | rm_rf "./lxsh-${verrev_lxsh}" | ||
| 405 | return found ~= "" | ||
| 406 | end, | ||
| 407 | test_write_rockspec = function() return run "$luarocks write_rockspec git://github.com/keplerproject/luarocks" end, | ||
| 408 | test_write_rockspec_lib = function() return run '$luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2' end, | ||
| 409 | test_write_rockspec_format = function() return run '$luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2' end, | ||
| 410 | test_write_rockspec_fullargs = function() return run '$luarocks write_rockspec git://github.com/keplerproject/luarocks --lua-version=5.1,5.2 --license="MIT/X11" --homepage="http://www.luarocks.org" --summary="A package manager for Lua modules"' end, | ||
| 411 | fail_write_rockspec_args = function() return run "$luarocks write_rockspec invalid" end, | ||
| 412 | fail_write_rockspec_args_url = function() return run "$luarocks write_rockspec http://example.com/invalid.zip" end, | ||
| 413 | test_write_rockspec_http = function() return run "$luarocks write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1" end, | ||
| 414 | test_write_rockspec_basedir = function() return run "$luarocks write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1" end, | ||
| 415 | |||
| 416 | fail_config_noflags = function() return run "$luarocks config; " end, | ||
| 417 | test_config_lua_incdir = function() return run "$luarocks config --lua-incdir; " end, | ||
| 418 | test_config_lua_libdir = function() return run "$luarocks config --lua-libdir; " end, | ||
| 419 | test_config_lua_ver = function() return run "$luarocks config --lua-ver; " end, | ||
| 420 | fail_config_system_config = function() | ||
| 421 | return rm "$testing_lrprefix/etc/luarocks/config.lua" | ||
| 422 | and run "$luarocks config --system-config; " | ||
| 423 | end, | ||
| 424 | test_config_system_config = function() | ||
| 425 | local ok = mkdir "$testing_lrprefix/etc/luarocks" | ||
| 426 | and touch "$testing_lrprefix/etc/luarocks/config.lua" | ||
| 427 | and run "$luarocks config --system-config; " | ||
| 428 | rm "$testing_lrprefix/etc/luarocks/config.lua" | ||
| 429 | return ok | ||
| 430 | end, | ||
| 431 | fail_config_system_config_invalid = function() | ||
| 432 | local ok = mkdir "$testing_lrprefix/etc/luarocks" | ||
| 433 | and run "echo 'if if if' > '$testing_lrprefix/etc/luarocks/config.lua' ;" | ||
| 434 | and run "$luarocks config --system-config" | ||
| 435 | rm "$testing_lrprefix/etc/luarocks/config.lua" | ||
| 436 | return ok | ||
| 437 | end, | ||
| 438 | test_config_user_config = function() return run "$luarocks config --user-config; " end, | ||
| 439 | fail_config_user_config = function() return run "LUAROCKS_CONFIG='/missing_file.lua' $luarocks config --user-config; " end, | ||
| 440 | test_config_rock_trees = function() return run "$luarocks config --rock-trees;" end, | ||
| 441 | test_config_help = function() return run "$luarocks help config;" end, | ||
| 442 | test_doc = function() | ||
| 443 | return run "$luarocks install luarepl" | ||
| 444 | and run "$luarocks doc luarepl" | ||
| 445 | end, | ||
| 446 | test_doc_home = function() | ||
| 447 | return run "$luarocks install luacov" | ||
| 448 | and run "$luarocks doc luacov --home" | ||
| 449 | end, | ||
| 450 | fail_doc_invalid = function () return run "$luarocks doc invalid" end, | ||
| 451 | |||
| 452 | -- Tests for https://github.com/keplerproject/luarocks/issues/375 | ||
| 453 | test_fetch_base_dir = function() | ||
| 454 | local fetch = require "luarocks.fetch" | ||
| 455 | |||
| 456 | return assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) | ||
| 457 | and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) | ||
| 458 | and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) | ||
| 459 | and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) | ||
| 460 | and assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) | ||
| 461 | and assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) | ||
| 462 | end, | ||
| 463 | |||
| 464 | -- Tests for https://github.com/keplerproject/luarocks/issues/552 | ||
| 465 | test_install_break_dependencies_warning = function() | ||
| 466 | need_luasocket() | ||
| 467 | return run "$luarocks install say ${new_version_say}" | ||
| 468 | and run "$luarocks install luassert" | ||
| 469 | and run "$luarocks install say ${old_version_say}" | ||
| 470 | end, | ||
| 471 | test_install_break_dependencies_force = function() | ||
| 472 | need_luasocket() | ||
| 473 | return run "$luarocks install say ${new_version_say}" | ||
| 474 | and run "$luarocks install luassert" | ||
| 475 | and run "$luarocks install --force say ${old_version_say}" | ||
| 476 | end, | ||
| 477 | test_install_break_dependencies_force = function() | ||
| 478 | need_luasocket() | ||
| 479 | return run "$luarocks install say ${new_version_say}" | ||
| 480 | and run "$luarocks install luassert" | ||
| 481 | and run "$luarocks install --force-fast say ${old_version_say}" | ||
| 482 | end | ||
| 483 | } | ||
diff --git a/test/testing.sh b/test/testing.sh deleted file mode 100755 index 0dd34bf1..00000000 --- a/test/testing.sh +++ /dev/null | |||
| @@ -1,698 +0,0 @@ | |||
| 1 | #!/bin/bash -e | ||
| 2 | |||
| 3 | # Setup ######################################### | ||
| 4 | |||
| 5 | [ -e ../configure ] || { | ||
| 6 | echo "Please run this from the test/ directory." | ||
| 7 | exit 1 | ||
| 8 | } | ||
| 9 | |||
| 10 | if [ -z "$*" ] | ||
| 11 | then | ||
| 12 | ps aux | grep -q '[s]shd' || { | ||
| 13 | echo "Run sudo /bin/sshd in order to perform all tests." | ||
| 14 | exit 1 | ||
| 15 | } | ||
| 16 | fi | ||
| 17 | |||
| 18 | if [ "$1" == "--travis" ] | ||
| 19 | then | ||
| 20 | travis=true | ||
| 21 | shift | ||
| 22 | fi | ||
| 23 | |||
| 24 | luaversion=5.1.5 | ||
| 25 | |||
| 26 | if [ "$1" == "--lua" ] | ||
| 27 | then | ||
| 28 | shift | ||
| 29 | luaversion=$1 | ||
| 30 | shift | ||
| 31 | fi | ||
| 32 | |||
| 33 | is_jit=`[ "${luaversion::3}" = "jit" ] && echo 1 || echo 0` | ||
| 34 | |||
| 35 | if [ "$is_jit" = 1 ] | ||
| 36 | then | ||
| 37 | luashortversion=5.1 | ||
| 38 | luajitversion=${luaversion:4} | ||
| 39 | else | ||
| 40 | luashortversion=`echo $luaversion | cut -d. -f 1-2` | ||
| 41 | fi | ||
| 42 | |||
| 43 | testing_dir="$PWD" | ||
| 44 | |||
| 45 | testing_lrprefix="$testing_dir/testing_lrprefix-$luaversion" | ||
| 46 | testing_tree="$testing_dir/testing-$luaversion" | ||
| 47 | testing_sys_tree="$testing_dir/testing_sys-$luaversion" | ||
| 48 | testing_tree_copy="$testing_dir/testing_copy-$luaversion" | ||
| 49 | testing_sys_tree_copy="$testing_dir/testing_sys_copy-$luaversion" | ||
| 50 | testing_cache="$testing_dir/testing_cache-$luaversion" | ||
| 51 | testing_server="$testing_dir/testing_server-$luaversion" | ||
| 52 | |||
| 53 | if [ "$1" == "--clean" ] | ||
| 54 | then | ||
| 55 | shift | ||
| 56 | rm -rf "$testing_cache" | ||
| 57 | rm -rf "$testing_server" | ||
| 58 | fi | ||
| 59 | |||
| 60 | [ "$1" ] || rm -f luacov.stats.out | ||
| 61 | rm -f luacov.report.out | ||
| 62 | rm -rf /tmp/luarocks_testing | ||
| 63 | mkdir /tmp/luarocks_testing | ||
| 64 | rm -rf "$testing_lrprefix" | ||
| 65 | rm -rf "$testing_tree" | ||
| 66 | rm -rf "$testing_sys_tree" | ||
| 67 | rm -rf "$testing_tree_copy" | ||
| 68 | rm -rf "$testing_sys_tree_copy" | ||
| 69 | rm -rf "$testing_dir/testing_config.lua" | ||
| 70 | rm -rf "$testing_dir/testing_config_show_downloads.lua" | ||
| 71 | rm -rf "$testing_dir/testing_config_sftp.lua" | ||
| 72 | rm -rf "$testing_dir/luacov.config" | ||
| 73 | |||
| 74 | mkdir -p "$testing_cache" | ||
| 75 | |||
| 76 | [ "$1" = "clean" ] && { | ||
| 77 | rm -f luacov.stats.out | ||
| 78 | exit 0 | ||
| 79 | } | ||
| 80 | |||
| 81 | cat <<EOF > $testing_dir/testing_config.lua | ||
| 82 | rocks_trees = { | ||
| 83 | "$testing_tree", | ||
| 84 | { name = "system", root = "$testing_sys_tree" }, | ||
| 85 | } | ||
| 86 | rocks_servers = { | ||
| 87 | "$testing_server" | ||
| 88 | } | ||
| 89 | local_cache = "$testing_cache" | ||
| 90 | upload_server = "testing" | ||
| 91 | upload_user = "$USER" | ||
| 92 | upload_servers = { | ||
| 93 | testing = { | ||
| 94 | rsync = "localhost/tmp/luarocks_testing", | ||
| 95 | }, | ||
| 96 | } | ||
| 97 | external_deps_dirs = { | ||
| 98 | "/usr/local", | ||
| 99 | "/usr", | ||
| 100 | -- These are used for a test that fails, so it | ||
| 101 | -- can point to invalid paths: | ||
| 102 | { | ||
| 103 | prefix = "/opt", | ||
| 104 | bin = "bin", | ||
| 105 | include = "include", | ||
| 106 | lib = { "lib", "lib64" }, | ||
| 107 | } | ||
| 108 | } | ||
| 109 | EOF | ||
| 110 | ( | ||
| 111 | cat $testing_dir/testing_config.lua | ||
| 112 | echo "show_downloads = true" | ||
| 113 | ) > $testing_dir/testing_config_show_downloads.lua | ||
| 114 | cat <<EOF > $testing_dir/testing_config_sftp.lua | ||
| 115 | rocks_trees = { | ||
| 116 | "$testing_tree", | ||
| 117 | "$testing_sys_tree", | ||
| 118 | } | ||
| 119 | local_cache = "$testing_cache" | ||
| 120 | upload_server = "testing" | ||
| 121 | upload_user = "$USER" | ||
| 122 | upload_servers = { | ||
| 123 | testing = { | ||
| 124 | sftp = "localhost/tmp/luarocks_testing", | ||
| 125 | }, | ||
| 126 | } | ||
| 127 | EOF | ||
| 128 | cat <<EOF > $testing_dir/luacov.config | ||
| 129 | return { | ||
| 130 | statsfile = "$testing_dir/luacov.stats.out", | ||
| 131 | reportfile = "$testing_dir/luacov.report.out", | ||
| 132 | modules = { | ||
| 133 | ["luarocks"] = "src/bin/luarocks", | ||
| 134 | ["luarocks-admin"] = "src/bin/luarocks-admin", | ||
| 135 | ["luarocks.*"] = "src", | ||
| 136 | ["luarocks.*.*"] = "src", | ||
| 137 | ["luarocks.*.*.*"] = "src" | ||
| 138 | } | ||
| 139 | } | ||
| 140 | EOF | ||
| 141 | |||
| 142 | export LUAROCKS_CONFIG="$testing_dir/testing_config.lua" | ||
| 143 | export LUA_PATH= | ||
| 144 | export LUA_CPATH= | ||
| 145 | |||
| 146 | if [ "$travis" ] | ||
| 147 | then | ||
| 148 | luadir=/tmp/lua-$luaversion | ||
| 149 | pushd /tmp | ||
| 150 | if [ ! -e "$luadir/bin/lua" ] | ||
| 151 | then | ||
| 152 | mkdir -p lua | ||
| 153 | cd lua | ||
| 154 | if [ "$is_jit" = 1 ] | ||
| 155 | then | ||
| 156 | echo "Downloading LuaJIT $luajitversion..." | ||
| 157 | #rm -f "LuaJIT-$luajitversion.tar.gz" | ||
| 158 | wget -c "https://github.com/LuaJIT/LuaJIT/archive/v$luajitversion.tar.gz" &> /dev/null | ||
| 159 | tar zxpf "v$luajitversion.tar.gz" | ||
| 160 | cd "LuaJIT-$luajitversion" | ||
| 161 | echo "Building LuaJIT $luajitversion..." | ||
| 162 | make PREFIX="$luadir" &> /dev/null | ||
| 163 | make install PREFIX="$luadir" &> /dev/null | ||
| 164 | else | ||
| 165 | echo "Downloading Lua $luaversion..." | ||
| 166 | #rm -f "lua-$luaversion.tar.gz" | ||
| 167 | wget -c "http://www.lua.org/ftp/lua-$luaversion.tar.gz" &> /dev/null | ||
| 168 | tar zxpf "lua-$luaversion.tar.gz" | ||
| 169 | cd "lua-$luaversion" | ||
| 170 | echo "Building Lua $luaversion..." | ||
| 171 | make linux INSTALL_TOP="$luadir" &> /dev/null | ||
| 172 | make install INSTALL_TOP="$luadir" &> /dev/null | ||
| 173 | fi | ||
| 174 | fi | ||
| 175 | popd | ||
| 176 | [ -e ~/.ssh/id_rsa.pub ] || ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa | ||
| 177 | cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys | ||
| 178 | chmod og-wx ~/.ssh/authorized_keys | ||
| 179 | ssh-keyscan localhost >> ~/.ssh/known_hosts | ||
| 180 | else | ||
| 181 | if [ "$is_jit" = 1 ] | ||
| 182 | then | ||
| 183 | luadir="/Programs/LuaJIT/$luajitversion" | ||
| 184 | echo HELLO $luadir | ||
| 185 | else | ||
| 186 | luadir="/Programs/Lua/$luaversion" | ||
| 187 | fi | ||
| 188 | if [ ! -e "$luadir" ] | ||
| 189 | then | ||
| 190 | luadir="/usr/local" | ||
| 191 | fi | ||
| 192 | fi | ||
| 193 | |||
| 194 | if [ `uname -m` = i686 ] | ||
| 195 | then | ||
| 196 | platform="linux-x86" | ||
| 197 | else | ||
| 198 | platform="linux-x86_64" | ||
| 199 | fi | ||
| 200 | |||
| 201 | if [ "$is_jit" = 1 ] | ||
| 202 | then | ||
| 203 | lua="$luadir/bin/luajit" | ||
| 204 | luarocks_configure_extra_args="--lua-suffix=jit --with-lua-include=$luadir/include/luajit-2.0" | ||
| 205 | else | ||
| 206 | lua="$luadir/bin/lua" | ||
| 207 | fi | ||
| 208 | |||
| 209 | version_luasocket=3.0rc1 | ||
| 210 | verrev_luasocket=${version_luasocket}-1 | ||
| 211 | srcdir_luasocket=luasocket-3.0-rc1 | ||
| 212 | |||
| 213 | version_cprint=0.1 | ||
| 214 | verrev_cprint=0.1-2 | ||
| 215 | |||
| 216 | new_version_say=1.2-1 | ||
| 217 | old_version_say=1.0-1 | ||
| 218 | |||
| 219 | version_luacov=0.11.0 | ||
| 220 | verrev_luacov=${version_luacov}-1 | ||
| 221 | version_lxsh=0.8.6 | ||
| 222 | version_validate_args=1.5.4 | ||
| 223 | verrev_validate_args=1.5.4-1 | ||
| 224 | verrev_lxsh=${version_lxsh}-2 | ||
| 225 | version_abelhas=1.0 | ||
| 226 | verrev_abelhas=${version_abelhas}-1 | ||
| 227 | |||
| 228 | luasec=luasec | ||
| 229 | |||
| 230 | cd .. | ||
| 231 | ./configure --with-lua="$luadir" --prefix="$testing_lrprefix" $luarocks_configure_extra_args | ||
| 232 | make clean | ||
| 233 | make src/luarocks/site_config.lua | ||
| 234 | make dev | ||
| 235 | cd src | ||
| 236 | basedir=$PWD | ||
| 237 | run_lua() { | ||
| 238 | if [ "$1" = "--noecho" ]; then shift; noecho=1; else noecho=0; fi | ||
| 239 | if [ "$1" = "--nocov" ]; then shift; nocov=1; else nocov=0; fi | ||
| 240 | if [ "$noecho" = 0 ] | ||
| 241 | then | ||
| 242 | echo $* | ||
| 243 | fi | ||
| 244 | cmd=$1 | ||
| 245 | shift | ||
| 246 | if [ "$nocov" = 0 ] | ||
| 247 | then | ||
| 248 | "$lua" -e"require('luacov.runner')('$testing_dir/luacov.config')" "$basedir/bin/$cmd" "$@" | ||
| 249 | else | ||
| 250 | "$lua" "$basedir/bin/$cmd" "$@" | ||
| 251 | fi | ||
| 252 | } | ||
| 253 | luarocks="run_lua luarocks" | ||
| 254 | luarocks_nocov="run_lua --nocov luarocks" | ||
| 255 | luarocks_noecho="run_lua --noecho luarocks" | ||
| 256 | luarocks_noecho_nocov="run_lua --noecho --nocov luarocks" | ||
| 257 | luarocks_admin="run_lua luarocks-admin" | ||
| 258 | luarocks_admin_nocov="run_lua --nocov luarocks-admin" | ||
| 259 | luajit_luarocks="luajit -e require('luacov.runner')('$testing_dir/luacov.config') $basedir/bin/luarocks" | ||
| 260 | |||
| 261 | ################################################### | ||
| 262 | |||
| 263 | mkdir -p "$testing_server" | ||
| 264 | ( | ||
| 265 | cd "$testing_server" | ||
| 266 | luarocks_repo="https://luarocks.org" | ||
| 267 | get() { [ -e `basename "$1"` ] || wget -c "$1"; } | ||
| 268 | get "$luarocks_repo/luacov-${verrev_luacov}.src.rock" | ||
| 269 | get "$luarocks_repo/luacov-${verrev_luacov}.rockspec" | ||
| 270 | get "$luarocks_repo/luadoc-3.0.1-1.src.rock" | ||
| 271 | get "$luarocks_repo/lualogging-1.3.0-1.src.rock" | ||
| 272 | get "$luarocks_repo/luasocket-${verrev_luasocket}.src.rock" | ||
| 273 | get "$luarocks_repo/luasocket-${verrev_luasocket}.rockspec" | ||
| 274 | get "$luarocks_repo/luafilesystem-1.6.3-1.src.rock" | ||
| 275 | get "$luarocks_repo/stdlib-41.0.0-1.src.rock" | ||
| 276 | get "$luarocks_repo/luarepl-0.4-1.src.rock" | ||
| 277 | get "$luarocks_repo/validate-args-1.5.4-1.rockspec" | ||
| 278 | get "$luarocks_repo/luasec-0.6-1.rockspec" | ||
| 279 | get "$luarocks_repo/luabitop-1.0.2-1.rockspec" | ||
| 280 | get "$luarocks_repo/luabitop-1.0.2-1.src.rock" | ||
| 281 | get "$luarocks_repo/lpty-1.0.1-1.src.rock" | ||
| 282 | get "$luarocks_repo/cprint-${verrev_cprint}.src.rock" | ||
| 283 | get "$luarocks_repo/cprint-${verrev_cprint}.rockspec" | ||
| 284 | get "$luarocks_repo/wsapi-1.6-1.src.rock" | ||
| 285 | get "$luarocks_repo/lxsh-${verrev_lxsh}.src.rock" | ||
| 286 | get "$luarocks_repo/lxsh-${verrev_lxsh}.rockspec" | ||
| 287 | get "$luarocks_repo/abelhas-${verrev_abelhas}.rockspec" | ||
| 288 | get "$luarocks_repo/lzlib-0.4.1.53-1.src.rock" | ||
| 289 | get "$luarocks_repo/lpeg-0.12-1.src.rock" | ||
| 290 | get "$luarocks_repo/luaposix-33.2.1-1.src.rock" | ||
| 291 | get "$luarocks_repo/md5-1.2-1.src.rock" | ||
| 292 | get "$luarocks_repo/lmathx-20120430.51-1.src.rock" | ||
| 293 | get "$luarocks_repo/lmathx-20120430.51-1.rockspec" | ||
| 294 | get "$luarocks_repo/lmathx-20120430.52-1.src.rock" | ||
| 295 | get "$luarocks_repo/lmathx-20120430.52-1.rockspec" | ||
| 296 | get "$luarocks_repo/lmathx-20150505-1.src.rock" | ||
| 297 | get "$luarocks_repo/lmathx-20150505-1.rockspec" | ||
| 298 | get "$luarocks_repo/lua-path-0.2.3-1.src.rock" | ||
| 299 | get "$luarocks_repo/lua-cjson-2.1.0-1.src.rock" | ||
| 300 | get "$luarocks_repo/luacov-coveralls-0.1.1-1.src.rock" | ||
| 301 | get "$luarocks_repo/say-1.2-1.src.rock" | ||
| 302 | get "$luarocks_repo/say-1.0-1.src.rock" | ||
| 303 | get "$luarocks_repo/luassert-1.7.0-1.src.rock" | ||
| 304 | ) | ||
| 305 | $luarocks_admin_nocov make_manifest "$testing_server" | ||
| 306 | |||
| 307 | ################################################### | ||
| 308 | |||
| 309 | checksum_path() { | ||
| 310 | ( cd "$1"; find . -printf "%s %p\n" | md5sum ) | ||
| 311 | } | ||
| 312 | |||
| 313 | build_environment() { | ||
| 314 | rm -rf "$testing_tree" | ||
| 315 | rm -rf "$testing_sys_tree" | ||
| 316 | rm -rf "$testing_tree_copy" | ||
| 317 | rm -rf "$testing_sys_tree_copy" | ||
| 318 | mkdir -p "$testing_tree" | ||
| 319 | mkdir -p "$testing_sys_tree" | ||
| 320 | $luarocks_admin_nocov make_manifest "$testing_cache" | ||
| 321 | for package in "$@" | ||
| 322 | do | ||
| 323 | $luarocks_nocov install --only-server="$testing_cache" --tree="$testing_sys_tree" $package || { | ||
| 324 | $luarocks_nocov build --tree="$testing_sys_tree" $package | ||
| 325 | $luarocks_nocov pack --tree="$testing_sys_tree" $package; mv $package-*.rock "$testing_cache" | ||
| 326 | } | ||
| 327 | done | ||
| 328 | export LUA_PATH= | ||
| 329 | export LUA_CPATH= | ||
| 330 | eval `$luarocks_noecho_nocov path --bin` | ||
| 331 | cp -a "$testing_tree" "$testing_tree_copy" | ||
| 332 | cp -a "$testing_sys_tree" "$testing_sys_tree_copy" | ||
| 333 | testing_tree_copy_md5=`checksum_path "$testing_tree_copy"` | ||
| 334 | testing_sys_tree_copy_md5=`checksum_path "$testing_sys_tree_copy"` | ||
| 335 | } | ||
| 336 | |||
| 337 | reset_environment() { | ||
| 338 | testing_tree_md5=`checksum_path "$testing_tree"` | ||
| 339 | testing_sys_tree_md5=`checksum_path "$testing_sys_tree"` | ||
| 340 | if [ "$testing_tree_md5" != "$testing_tree_copy_md5" ] | ||
| 341 | then | ||
| 342 | rm -rf "$testing_tree" | ||
| 343 | cp -a "$testing_tree_copy" "$testing_tree" | ||
| 344 | fi | ||
| 345 | if [ "$testing_sys_tree_md5" != "$testing_sys_tree_copy_md5" ] | ||
| 346 | then | ||
| 347 | rm -rf "$testing_sys_tree" | ||
| 348 | cp -a "$testing_sys_tree_copy" "$testing_sys_tree" | ||
| 349 | fi | ||
| 350 | } | ||
| 351 | |||
| 352 | need() { | ||
| 353 | echo "Obtaining $1 $2..." | ||
| 354 | if $luarocks show $1 &> /dev/null | ||
| 355 | then | ||
| 356 | echo "Already available" | ||
| 357 | return | ||
| 358 | fi | ||
| 359 | platrock="$1-$2.$platform.rock" | ||
| 360 | if [ ! -e "$testing_cache/$platrock" ] | ||
| 361 | then | ||
| 362 | echo "Building $1 $2..." | ||
| 363 | $luarocks_nocov build --pack-binary-rock $1 $2 | ||
| 364 | mv "$platrock" "$testing_cache" | ||
| 365 | fi | ||
| 366 | echo "Installing $1 $2..." | ||
| 367 | $luarocks_nocov install "$testing_cache/$platrock" | ||
| 368 | return | ||
| 369 | } | ||
| 370 | need_luasocket() { need luasocket $verrev_luasocket; } | ||
| 371 | |||
| 372 | # Tests ######################################### | ||
| 373 | test_version() { $luarocks --version; } | ||
| 374 | |||
| 375 | fail_unknown_command() { $luarocks unknown_command; } | ||
| 376 | |||
| 377 | fail_arg_boolean_parameter() { $luarocks --porcelain=invalid; } | ||
| 378 | fail_arg_boolean_unknown() { $luarocks --invalid-flag; } | ||
| 379 | fail_arg_string_no_parameter() { $luarocks --server; } | ||
| 380 | fail_arg_string_followed_by_flag() { $luarocks --server --porcelain; } | ||
| 381 | fail_arg_string_unknown() { $luarocks --invalid-flag=abc; } | ||
| 382 | |||
| 383 | fail_invalid_assignment() { $luarocks invalid=5; } | ||
| 384 | |||
| 385 | test_empty_list() { $luarocks list; } | ||
| 386 | test_list_outdated() { $luarocks list --outdated; } | ||
| 387 | |||
| 388 | fail_sysconfig_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; } | ||
| 389 | fail_sysconfig_default_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config-$luashortversion.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; } | ||
| 390 | |||
| 391 | fail_build_noarg() { $luarocks build; } | ||
| 392 | fail_download_noarg() { $luarocks download; } | ||
| 393 | fail_install_noarg() { $luarocks install; } | ||
| 394 | fail_lint_noarg() { $luarocks lint; } | ||
| 395 | fail_search_noarg() { $luarocks search; } | ||
| 396 | fail_show_noarg() { $luarocks show; } | ||
| 397 | fail_unpack_noarg() { $luarocks unpack; } | ||
| 398 | fail_upload_noarg() { $luarocks upload; } | ||
| 399 | fail_remove_noarg() { $luarocks remove; } | ||
| 400 | fail_doc_noarg() { $luarocks doc; } | ||
| 401 | |||
| 402 | fail_build_invalid() { $luarocks build invalid; } | ||
| 403 | fail_download_invalid() { $luarocks download invalid; } | ||
| 404 | fail_install_invalid() { $luarocks install invalid; } | ||
| 405 | fail_lint_invalid() { $luarocks lint invalid; } | ||
| 406 | fail_show_invalid() { $luarocks show invalid; } | ||
| 407 | fail_new_version_invalid() { $luarocks new_version invalid; } | ||
| 408 | |||
| 409 | test_list_invalidtree() { $luarocks --tree=/some/invalid/tree list; } | ||
| 410 | |||
| 411 | fail_inexistent_dir() { mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err; } | ||
| 412 | |||
| 413 | fail_make_norockspec() { $luarocks make; } | ||
| 414 | |||
| 415 | fail_build_permissions() { $luarocks build --tree=/usr lpeg; } | ||
| 416 | fail_build_permissions_parent() { $luarocks build --tree=/usr/invalid lpeg; } | ||
| 417 | |||
| 418 | test_build_verbose() { $luarocks build --verbose lpeg; } | ||
| 419 | test_build_timeout() { $luarocks --timeout=10; } | ||
| 420 | fail_build_timeout_invalid() { $luarocks --timeout=abc; } | ||
| 421 | test_build_branch() { $luarocks build --branch=master lpeg; } | ||
| 422 | fail_build_invalid_entry_deps_mode() { $luarocks build --deps-mode=123 lpeg; } | ||
| 423 | test_build_only_server() { $luarocks --only-server=testing; } | ||
| 424 | test_build_only_sources() { $luarocks build --only-sources="http://example.com" lpeg; } | ||
| 425 | fail_build_blank_arg() { $luarocks build --tree="" lpeg; } | ||
| 426 | test_build_withpatch() { need_luasocket; $luarocks build luadoc; } | ||
| 427 | test_build_diffversion() { $luarocks build luacov ${version_luacov}; } | ||
| 428 | test_build_command() { $luarocks build stdlib; } | ||
| 429 | test_build_install_bin() { $luarocks build luarepl; } | ||
| 430 | test_build_nohttps() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks build ./validate-args-${version_validate_args}-1.rockspec && rm ./validate-args-${version_validate_args}-1.rockspec; } | ||
| 431 | test_build_https() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks install $luasec && $luarocks build ./validate-args-${verrev_validate_args}.rockspec && rm ./validate-args-${verrev_validate_args}.rockspec; } | ||
| 432 | test_build_supported_platforms() { $luarocks build lpty; } | ||
| 433 | test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } | ||
| 434 | test_build_only_deps_src_rock() { $luarocks download --source lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } | ||
| 435 | test_build_only_deps() { $luarocks build luasec --only-deps && { $luarocks show luasec; [ $? -ne 0 ]; }; } | ||
| 436 | test_install_only_deps() { $luarocks install lxsh ${verrev_lxsh} --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } | ||
| 437 | test_build_no_deps() { $luarocks build luasec --nodeps; } | ||
| 438 | test_install_no_deps() { $luarocks install luasec --nodeps; } | ||
| 439 | fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; } | ||
| 440 | fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } | ||
| 441 | |||
| 442 | test_build_deps_partial_match() { $luarocks build lmathx; } | ||
| 443 | test_build_show_downloads() { export LUAROCKS_CONFIG="$testing_dir/testing_config_show_downloads.lua" && $luarocks build alien; export LUAROCKS_CONFIG="$testing_dir/testing_config.lua"; } | ||
| 444 | |||
| 445 | test_download_all() { $luarocks download --all validate-args && rm validate-args-*; } | ||
| 446 | test_download_rockspecversion() { $luarocks download --rockspec validate-args ${verrev_validate_args} && rm validate-args-*; } | ||
| 447 | |||
| 448 | test_help() { $luarocks help; } | ||
| 449 | fail_help_invalid() { $luarocks help invalid; } | ||
| 450 | |||
| 451 | test_install_only_deps() { $luarocks install --only-deps "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; } | ||
| 452 | test_install_binaryrock() { $luarocks build --pack-binary-rock cprint && $luarocks install ./cprint-${verrev_cprint}.${platform}.rock && rm ./cprint-${verrev_cprint}.${platform}.rock; } | ||
| 453 | test_install_with_bin() { $luarocks install wsapi; } | ||
| 454 | fail_install_notazipfile() { $luarocks install "$testing_dir/testfiles/not_a_zipfile-1.0-1.src.rock"; } | ||
| 455 | fail_install_invalidpatch() { need_luasocket; $luarocks install "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } | ||
| 456 | fail_install_invalid_filename() { $luarocks install "invalid.rock"; } | ||
| 457 | fail_install_invalid_arch() { $luarocks install "foo-1.0-1.impossible-x86.rock"; } | ||
| 458 | test_install_reinstall() { $luarocks install "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; $luarocks install --deps-mode=none "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; } | ||
| 459 | |||
| 460 | fail_local_root() { USER=root $luarocks install --local luasocket; } | ||
| 461 | |||
| 462 | test_site_config() { mv ../src/luarocks/site_config.lua ../src/luarocks/site_config.lua.tmp; $luarocks; mv ../src/luarocks/site_config.lua.tmp ../src/luarocks/site_config.lua; } | ||
| 463 | |||
| 464 | test_lint_ok() { $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks lint ./validate-args-${verrev_validate_args}.rockspec && rm ./validate-args-${verrev_validate_args}.rockspec; } | ||
| 465 | fail_lint_type_mismatch_string() { $luarocks lint "$testing_dir/testfiles/type_mismatch_string-1.0-1.rockspec"; } | ||
| 466 | fail_lint_type_mismatch_version() { $luarocks lint "$testing_dir/testfiles/type_mismatch_version-1.0-1.rockspec"; } | ||
| 467 | fail_lint_type_mismatch_table() { $luarocks lint "$testing_dir/testfiles/type_mismatch_table-1.0-1.rockspec"; } | ||
| 468 | fail_lint_no_build_table() { $luarocks lint "$testing_dir/testfiles/no_build_table-0.1-1.rockspec"; } | ||
| 469 | |||
| 470 | test_list() { $luarocks list; } | ||
| 471 | test_list_porcelain() { $luarocks list --porcelain; } | ||
| 472 | |||
| 473 | test_make_with_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make luasocket-${verrev_luasocket}.rockspec && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; } | ||
| 474 | test_make_default_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks new_version lxsh-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | ||
| 475 | test_make_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | ||
| 476 | fail_make_ambiguous_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec lxsh2-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | ||
| 477 | fail_make_ambiguous_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && mv lxsh-${verrev_lxsh}.rockspec 1_rockspec && cp 1_rockspec 2_rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | ||
| 478 | test_make_pack_binary_rock() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --deps-mode=none --pack-binary-rock && [ -e ./lxsh-${verrev_lxsh}.all.rock ] && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | ||
| 479 | |||
| 480 | test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } | ||
| 481 | test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; } | ||
| 482 | test_new_version_tag() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec --tag v0.3 && rm ./luacov-0.3-1.rockspec; } | ||
| 483 | test_new_version_tag_without_arg() { rm -rf ./*rockspec && $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version --tag v0.3 && rm ./luacov-0.3-1.rockspec; } | ||
| 484 | |||
| 485 | test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; } | ||
| 486 | test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; } | ||
| 487 | |||
| 488 | test_path() { $luarocks path --bin; } | ||
| 489 | test_path_lr_path() { $luarocks path --lr-path; } | ||
| 490 | test_path_lr_cpath() { $luarocks path --lr-cpath; } | ||
| 491 | test_path_lr_bin() { $luarocks path --lr-bin; } | ||
| 492 | test_path_with_tree() { $luarocks path --tree=lua_modules; } | ||
| 493 | |||
| 494 | fail_purge_missing_tree() { $luarocks purge --tree="$testing_tree"; } | ||
| 495 | fail_purge_tree_notstring() { $luarocks purge --tree=1; } | ||
| 496 | test_purge() { $luarocks purge --tree="$testing_sys_tree"; } | ||
| 497 | test_purge_oldversions() { $luarocks purge --old-versions --tree="$testing_sys_tree"; } | ||
| 498 | |||
| 499 | test_remove() { $luarocks build abelhas ${version_abelhas} && $luarocks remove abelhas ${version_abelhas}; } | ||
| 500 | test_remove_force() { need_luasocket; $luarocks build lualogging && $luarocks remove --force luasocket; } | ||
| 501 | test_remove_force_fast() { need_luasocket; $luarocks build lualogging && $luarocks remove --force-fast luasocket; } | ||
| 502 | fail_remove_deps() { need_luasocket; $luarocks build lualogging && $luarocks remove luasocket; } | ||
| 503 | fail_remove_missing() { $luarocks remove missing_rock; } | ||
| 504 | fail_remove_invalid_name() { $luarocks remove invalid.rock; } | ||
| 505 | |||
| 506 | test_search_found() { $luarocks search zlib; } | ||
| 507 | test_search_missing() { $luarocks search missing_rock; } | ||
| 508 | test_search_version() { $luarocks search zlib 1.1; } | ||
| 509 | test_search_all() { $luarocks search --all; } | ||
| 510 | fail_search_nostring() { $var=123; $luarocks search $var; } | ||
| 511 | |||
| 512 | test_show() { $luarocks show luacov; } | ||
| 513 | test_show_modules() { $luarocks show --modules luacov; } | ||
| 514 | test_show_home() { $luarocks show --home luacov; } | ||
| 515 | test_show_deps() { $luarocks show --deps luacov; } | ||
| 516 | test_show_rockspec() { $luarocks show --rockspec luacov; } | ||
| 517 | test_show_mversion() { $luarocks show --mversion luacov; } | ||
| 518 | test_show_rocktree() { $luarocks show --rock-tree luacov; } | ||
| 519 | test_show_rockdir() { $luarocks show --rock-dir luacov; } | ||
| 520 | test_show_depends() { need_luasocket; $luarocks install $luasec && $luarocks show luasec; } | ||
| 521 | test_show_oldversion() { $luarocks install luacov ${version_luacov} && $luarocks show luacov ${version_luacov}; } | ||
| 522 | |||
| 523 | test_unpack_download() { rm -rf ./cprint-${verrev_cprint} && $luarocks unpack cprint && rm -rf ./cprint-${verrev_cprint}; } | ||
| 524 | test_unpack_src() { rm -rf ./cprint-${verrev_cprint} && $luarocks download --source cprint && $luarocks unpack ./cprint-${verrev_cprint}.src.rock && rm -rf ./cprint-${verrev_cprint}; } | ||
| 525 | test_unpack_rockspec() { rm -rf ./cprint-${verrev_cprint} && $luarocks download --rockspec cprint && $luarocks unpack ./cprint-${verrev_cprint}.rockspec && rm -rf ./cprint-${verrev_cprint}; } | ||
| 526 | test_unpack_binary() { rm -rf ./cprint-${verrev_cprint} && $luarocks build cprint && $luarocks pack cprint && $luarocks unpack ./cprint-${verrev_cprint}.${platform}.rock && rm -rf ./cprint-${verrev_cprint}; } | ||
| 527 | fail_unpack_invalidpatch() { need_luasocket; $luarocks unpack "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } | ||
| 528 | fail_unpack_invalidrockspec() { need_luasocket; $luarocks unpack "invalid.rockspec"; } | ||
| 529 | |||
| 530 | fail_upload_invalidrockspec() { $luarocks upload "invalid.rockspec"; } | ||
| 531 | fail_upload_invalidkey() { $luarocks upload --api-key="invalid" "invalid.rockspec"; } | ||
| 532 | fail_upload_skippack() { $luarocks upload --api-key="invalid" --skip-pack "luacov-${verrev_luacov}.rockspec"; } | ||
| 533 | fail_upload_force() { $luarocks install lua-cjson && $luarocks upload --api-key="invalid" --force "luacov-${verrev_luacov}.rockspec" && $luarocks remove lua-cjson; } | ||
| 534 | |||
| 535 | |||
| 536 | test_admin_help() { $luarocks_admin help; } | ||
| 537 | |||
| 538 | test_admin_make_manifest() { $luarocks_admin make_manifest; } | ||
| 539 | test_admin_add_rsync() { $luarocks_admin --server=testing add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; } | ||
| 540 | test_admin_add_sftp() { export LUAROCKS_CONFIG="$testing_dir/testing_config_sftp.lua" && $luarocks_admin --server=testing add ./luasocket-${verrev_luasocket}.src.rock; export LUAROCKS_CONFIG="$testing_dir/testing_config.lua"; } | ||
| 541 | fail_admin_add_missing() { $luarocks_admin --server=testing add; } | ||
| 542 | fail_admin_invalidserver() { $luarocks_admin --server=invalid add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; } | ||
| 543 | fail_admin_invalidrock() { $luarocks_admin --server=testing add invalid; } | ||
| 544 | test_admin_refresh_cache() { $luarocks_admin --server=testing refresh_cache; } | ||
| 545 | test_admin_remove() { $luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock; } | ||
| 546 | fail_admin_remove_missing() { $luarocks_admin --server=testing remove; } | ||
| 547 | fail_admin_split_server_url() { $luarocks_admin --server="localhost@/tmp/luarocks_testing" add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; } | ||
| 548 | |||
| 549 | fail_deps_mode_invalid_arg() { $luarocks remove luacov --deps-mode; } | ||
| 550 | test_deps_mode_one() { $luarocks build --tree="system" lpeg && $luarocks list && $luarocks build --deps-mode=one --tree="$testing_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ]; } | ||
| 551 | test_deps_mode_order() { $luarocks build --tree="system" lpeg && $luarocks build --deps-mode=order --tree="$testing_tree" lxsh && $luarocks_noecho list --tree="$testing_tree" --porcelain lpeg && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; } | ||
| 552 | test_deps_mode_order_sys() { $luarocks build --tree="$testing_tree" lpeg && $luarocks build --deps-mode=order --tree="$testing_sys_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg | wc -l` = 1 ]; } | ||
| 553 | test_deps_mode_all_sys() { $luarocks build --tree="$testing_tree" lpeg && $luarocks build --deps-mode=all --tree="$testing_sys_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg | wc -l` = 0 ]; } | ||
| 554 | test_deps_mode_none() { $luarocks build --tree="$testing_tree" --deps-mode=none lxsh; [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; } | ||
| 555 | test_deps_mode_nodeps_alias() { $luarocks build --tree="$testing_tree" --nodeps lxsh; [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; } | ||
| 556 | test_deps_mode_make_order() { $luarocks build --tree="$testing_sys_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ] && rm -rf ./lxsh-${verrev_lxsh}; } | ||
| 557 | test_deps_mode_make_order_sys() { $luarocks build --tree="$testing_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_sys_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ] && rm -rf ./lxsh-${verrev_lxsh}; } | ||
| 558 | |||
| 559 | test_write_rockspec() { $luarocks write_rockspec git://github.com/keplerproject/luarocks; } | ||
| 560 | test_write_rockspec_name() { $luarocks write_rockspec luarocks git://github.com/keplerproject/luarocks; } | ||
| 561 | test_write_rockspec_name_version() { $luarocks write_rockspec luarocks 7.8.9 git://github.com/keplerproject/luarocks; } | ||
| 562 | test_write_rockspec_current_dir() { $luarocks write_rockspec; } | ||
| 563 | test_write_rockspec_tag() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0; } | ||
| 564 | test_write_rockspec_lib() { $luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2; } | ||
| 565 | test_write_rockspec_format() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2; } | ||
| 566 | test_write_rockspec_fullargs() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --lua-version=5.1,5.2 --license="MIT/X11" --homepage="http://www.luarocks.org" --summary="A package manager for Lua modules"; } | ||
| 567 | fail_write_rockspec_args() { $luarocks write_rockspec invalid; } | ||
| 568 | fail_write_rockspec_args_url() { $luarocks write_rockspec http://example.com/invalid.zip; } | ||
| 569 | test_write_rockspec_http() { $luarocks write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1; } | ||
| 570 | test_write_rockspec_basedir() { $luarocks write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1; } | ||
| 571 | |||
| 572 | fail_config_noflags() { $luarocks config; } | ||
| 573 | test_config_lua_incdir() { $luarocks config --lua-incdir; } | ||
| 574 | test_config_lua_libdir() { $luarocks config --lua-libdir; } | ||
| 575 | test_config_lua_ver() { $luarocks config --lua-ver; } | ||
| 576 | fail_config_system_config() { rm -f "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; } | ||
| 577 | test_config_system_config() { mkdir -p "$testing_lrprefix/etc/luarocks"; touch "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; err=$?; rm -f "$testing_lrprefix/etc/luarocks/config.lua"; return $err; } | ||
| 578 | fail_config_system_config_invalid() { mkdir -p "$testing_lrprefix/etc/luarocks"; echo "if if if" > "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; err=$?; rm -f "$testing_lrprefix/etc/luarocks/config.lua"; return $err; } | ||
| 579 | test_config_user_config() { $luarocks config --user-config; } | ||
| 580 | test_config_rock_trees() { $luarocks config --rock-trees; } | ||
| 581 | test_config_help() { $luarocks help config; } | ||
| 582 | |||
| 583 | # Tests for https://github.com/keplerproject/luarocks/issues/375 | ||
| 584 | test_fetch_base_dir() { $lua <<EOF | ||
| 585 | local fetch = require "luarocks.fetch" | ||
| 586 | |||
| 587 | assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) | ||
| 588 | assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) | ||
| 589 | assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) | ||
| 590 | assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) | ||
| 591 | assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) | ||
| 592 | assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) | ||
| 593 | EOF | ||
| 594 | } | ||
| 595 | |||
| 596 | test_luajit_dependency() { | ||
| 597 | if [ "$is_jit" = 1 ] | ||
| 598 | then $luarocks build "$testing_dir/testfiles/luajit-success-1.0-1.rockspec" | ||
| 599 | else true | ||
| 600 | fi | ||
| 601 | } | ||
| 602 | fail_luajit_dependency() { | ||
| 603 | if [ "$is_jit" = 1 ] | ||
| 604 | then $luarocks build "$testing_dir/testfiles/luajit-fail-1.0-1.rockspec" | ||
| 605 | else false | ||
| 606 | fi | ||
| 607 | } | ||
| 608 | |||
| 609 | test_doc() { $luarocks install luarepl; $luarocks doc luarepl; } | ||
| 610 | test_doc_home() { $luarocks install luacov; $luarocks doc luacov --home; } | ||
| 611 | fail_doc_invalid() { $luarocks doc invalid; } | ||
| 612 | test_doc_list() { $luarocks install luacov; $luarocks doc luacov --list; } | ||
| 613 | test_doc_local() { $luarocks install luacov; $luarocks doc luacov --local; } | ||
| 614 | test_doc_porcelain() { $luarocks install luacov; $luarocks doc luacov --porcelain; } | ||
| 615 | |||
| 616 | # Tests for https://github.com/keplerproject/luarocks/pull/552 | ||
| 617 | test_install_break_dependencies_warning() { need_luasocket; $luarocks install say ${new_version_say} && $luarocks install luassert && $luarocks install say ${old_version_say}; } | ||
| 618 | test_install_break_dependencies_force() { need_luasocket; $luarocks install say ${new_version_say} && $luarocks install luassert && $luarocks install --force say ${old_version_say}; } | ||
| 619 | test_install_break_dependencies_forcefast() { need_luasocket; $luarocks install say ${new_version_say} && $luarocks install luassert && $luarocks install --force-fast say ${old_version_say}; } | ||
| 620 | |||
| 621 | # Driver ######################################### | ||
| 622 | run_tests() { | ||
| 623 | grep "^test_$1.*(" < $testing_dir/testing.sh | cut -d'(' -f1 | while read test | ||
| 624 | do | ||
| 625 | echo "-------------------------------------------" | ||
| 626 | echo "$test" | ||
| 627 | echo "-------------------------------------------" | ||
| 628 | reset_environment | ||
| 629 | if $test | ||
| 630 | then | ||
| 631 | echo "OK: Expected success." | ||
| 632 | else | ||
| 633 | if [ $? = 99 ] | ||
| 634 | then echo "FAIL: Unexpected crash!"; exit 99 | ||
| 635 | fi | ||
| 636 | echo "FAIL: Unexpected failure."; exit 1 | ||
| 637 | fi | ||
| 638 | done | ||
| 639 | grep "^fail_$1.*(" < $testing_dir/testing.sh | cut -d'(' -f1 | while read test | ||
| 640 | do | ||
| 641 | echo "-------------------------------------------" | ||
| 642 | echo "$test" | ||
| 643 | echo "-------------------------------------------" | ||
| 644 | reset_environment | ||
| 645 | if $test | ||
| 646 | then echo "FAIL: Unexpected success."; exit 1 | ||
| 647 | else | ||
| 648 | if [ $? = 99 ] | ||
| 649 | then echo "FAIL: Unexpected crash!"; exit 99 | ||
| 650 | fi | ||
| 651 | echo "OK: Expected failure." | ||
| 652 | fi | ||
| 653 | done | ||
| 654 | } | ||
| 655 | |||
| 656 | run_with_minimal_environment() { | ||
| 657 | echo "===========================================" | ||
| 658 | echo "Running with minimal environment" | ||
| 659 | echo "===========================================" | ||
| 660 | build_environment luacov | ||
| 661 | run_tests $1 | ||
| 662 | } | ||
| 663 | |||
| 664 | run_with_full_environment() { | ||
| 665 | echo "===========================================" | ||
| 666 | echo "Running with full environment" | ||
| 667 | echo "===========================================" | ||
| 668 | |||
| 669 | local bitop= | ||
| 670 | [ "$luaversion" = "5.1.5" ] && bitop=luabitop | ||
| 671 | |||
| 672 | build_environment luacov luafilesystem luasocket $bitop luaposix md5 lzlib | ||
| 673 | run_tests $1 | ||
| 674 | } | ||
| 675 | |||
| 676 | run_all_tests() { | ||
| 677 | run_with_minimal_environment $1 | ||
| 678 | run_with_full_environment $1 | ||
| 679 | } | ||
| 680 | |||
| 681 | run_all_tests $1 | ||
| 682 | #run_with_minimal_environment $1 | ||
| 683 | |||
| 684 | cd "$testing_dir/.." | ||
| 685 | |||
| 686 | if [ "$travis" ] | ||
| 687 | then | ||
| 688 | if [ "$TRAVIS" ] | ||
| 689 | then | ||
| 690 | build_environment luacov luafilesystem luacov-coveralls | ||
| 691 | $testing_sys_tree/bin/luacov-coveralls -c "$testing_dir/luacov.config" || echo "ok" | ||
| 692 | fi | ||
| 693 | $testing_sys_tree/bin/luacov -c "$testing_dir/luacov.config" | ||
| 694 | grep "Summary" -B1 -A1000 "$testing_dir/luacov.report.out" | ||
| 695 | else | ||
| 696 | $testing_sys_tree/bin/luacov -c "$testing_dir/luacov.config" | ||
| 697 | cat "$testing_dir/luacov.report.out" | ||
| 698 | fi | ||
