diff options
author | Hisham <hisham@gobolinux.org> | 2016-07-11 01:15:41 -0300 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2016-07-11 01:15:41 -0300 |
commit | 994a041b4f1348564f390f3f4d8ec040c8edb4b8 (patch) | |
tree | 128d264d86576e0b62225056769b7097a745b822 | |
parent | 41eccd4ca6fe51f8174dd43744e7a4bab4daf2cb (diff) | |
parent | 77b41dd05a870feeb519e930472133f63cf94317 (diff) | |
download | luarocks-994a041b4f1348564f390f3f4d8ec040c8edb4b8.tar.gz luarocks-994a041b4f1348564f390f3f4d8ec040c8edb4b8.tar.bz2 luarocks-994a041b4f1348564f390f3f4d8ec040c8edb4b8.zip |
Merge branch 'master' of https://github.com/keplerproject/luarocks
33 files changed, 2253 insertions, 1146 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 69ec28f3..02bdb6c9 100644 --- a/.travis.yml +++ b/.travis.yml | |||
@@ -1,13 +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 | 47 | ||
13 | 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..1ce99089 --- /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_true(run.luarocks_bool("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 | |||
86 | it("LuaRocks build luadoc", function() | ||
87 | assert.is_true(run.luarocks_bool("build luadoc")) | ||
88 | end) | ||
89 | |||
90 | it("LuaRocks build luacov diff version", function() | ||
91 | assert.is_true(run.luarocks_bool("build luacov 0.11.0-1")) | ||
92 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luacov")) | ||
93 | end) | ||
94 | |||
95 | it("LuaRocks build command stdlib", function() | ||
96 | assert.is_true(run.luarocks_bool("build stdlib")) | ||
97 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/stdlib")) | ||
98 | end) | ||
99 | |||
100 | it("LuaRocks build install bin luarepl", function() | ||
101 | assert.is_true(run.luarocks_bool("build luarepl")) | ||
102 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luarepl")) | ||
103 | end) | ||
104 | |||
105 | it("LuaRocks build supported platforms lpty", function() | ||
106 | assert.is_true(run.luarocks_bool("build lpty")) | ||
107 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpty")) | ||
108 | end) | ||
109 | |||
110 | it("LuaRocks build luasec with skipping dependency checks", function() | ||
111 | assert.is_true(run.luarocks_bool("build luasec --nodeps")) | ||
112 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec")) | ||
113 | end) | ||
114 | |||
115 | it("LuaRocks build lmathx deps partial match", function() | ||
116 | assert.is_true(run.luarocks_bool("build lmathx")) | ||
117 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lmathx")) | ||
118 | end) | ||
119 | end) | ||
120 | |||
121 | describe("LuaRocks build - more complex tests", function() | ||
122 | |||
123 | it("LuaRocks build luacheck show downloads test_config", function() | ||
124 | local out = run.luarocks("build luacheck", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_show_downloads.lua"} ) | ||
125 | print(out) | ||
126 | end) | ||
127 | |||
128 | it("LuaRocks build luasec only deps", function() | ||
129 | assert.is_true(run.luarocks_bool("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_true(run.luarocks_bool("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_true(os.remove("lxsh-0.8.6-2.rockspec")) | ||
140 | end) | ||
141 | |||
142 | it("LuaRocks build only deps of downloaded rock of lxsh", function() | ||
143 | assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6-2")) | ||
144 | assert.is_true(run.luarocks_bool("build lxsh-0.8.6-2.src.rock --only-deps")) | ||
145 | assert.is_false(run.luarocks_bool("show lxsh")) | ||
146 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) | ||
147 | assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) | ||
148 | end) | ||
149 | |||
150 | it("LuaRocks build no https", function() | ||
151 | assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) | ||
152 | assert.is_true(run.luarocks_bool("build validate-args-1.5.4-1.rockspec")) | ||
153 | |||
154 | assert.is_true(run.luarocks_bool("show validate-args")) | ||
155 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/validate-args")) | ||
156 | |||
157 | assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) | ||
158 | end) | ||
159 | |||
160 | it("LuaRocks build with https", function() | ||
161 | assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) | ||
162 | assert.is_true(run.luarocks_bool("install luasec")) | ||
163 | assert.is_true(run.luarocks_bool("build validate-args-1.5.4-1.rockspec")) | ||
164 | |||
165 | assert.is_true(run.luarocks_bool("show validate-args")) | ||
166 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/validate-args")) | ||
167 | |||
168 | assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) | ||
169 | end) | ||
170 | |||
171 | it("LuaRocks build missing external", function() | ||
172 | assert.is_true(test_env.need_luasocket()) | ||
173 | assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) | ||
174 | end) | ||
175 | |||
176 | it("LuaRocks build invalid patch", function() | ||
177 | assert.is_true(test_env.need_luasocket()) | ||
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..0d41e2e9 --- /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("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("help config")) | ||
22 | end) | ||
23 | |||
24 | it("LuaRocks-admin help with no flags/arguments", function() | ||
25 | assert.is_true(run.luarocks_admin_bool("help")) | ||
26 | end) | ||
27 | end) | ||
diff --git a/spec/install_spec.lua b/spec/install_spec.lua new file mode 100644 index 00000000..0e406e22 --- /dev/null +++ b/spec/install_spec.lua | |||
@@ -0,0 +1,128 @@ | |||
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(" install luasec --nodeps") | ||
77 | assert.is_true(run.luarocks_bool("show luasec")) | ||
78 | if env_variables.TYPE_TEST_ENV == "minimal" then | ||
79 | assert.is_false(run.luarocks_bool("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(test_env.need_luasocket()) | ||
87 | local output = run.luarocks("install --only-deps " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. test_env.platform .. ".rock") | ||
88 | assert.are.same(output, "Successfully installed dependencies for luasocket 3.0rc1-1") | ||
89 | end) | ||
90 | |||
91 | it("LuaRocks install binary rock of cprint", function() | ||
92 | assert.is_true(test_env.need_luasocket()) | ||
93 | assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) | ||
94 | assert.is_true(run.luarocks_bool("install cprint-0.1-2." .. test_env.platform .. ".rock")) | ||
95 | assert.is_true(os.remove("cprint-0.1-2." .. test_env.platform .. ".rock")) | ||
96 | end) | ||
97 | |||
98 | it("LuaRocks install reinstall", function() | ||
99 | assert.is_true(test_env.need_luasocket()) | ||
100 | assert.is_true(run.luarocks_bool("install " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) | ||
101 | assert.is_true(run.luarocks_bool("install --deps-mode=none " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) | ||
102 | end) | ||
103 | end) | ||
104 | |||
105 | describe("New install functionality based on pull request 552", function() | ||
106 | it("LuaRocks install break dependencies warning", function() | ||
107 | assert.is_true(run.luarocks_bool("install say 1.2")) | ||
108 | assert.is_true(run.luarocks_bool("install luassert")) | ||
109 | assert.is_true(run.luarocks_bool("install say 1.0")) | ||
110 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.2-1")) | ||
111 | end) | ||
112 | it("LuaRocks install break dependencies force", function() | ||
113 | assert.is_true(run.luarocks_bool("install say 1.2")) | ||
114 | assert.is_true(run.luarocks_bool("install luassert")) | ||
115 | local output = run.luarocks("install --force say 1.0") | ||
116 | assert.is.truthy(output:find("Checking stability of dependencies")) | ||
117 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.2-1")) | ||
118 | end) | ||
119 | it("LuaRocks install break dependencies force fast", function() | ||
120 | assert.is_true(run.luarocks_bool("install say 1.2")) | ||
121 | assert.is_true(run.luarocks_bool("install luassert")) | ||
122 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.2-1")) | ||
123 | local output = run.luarocks("install --force-fast say 1.0") | ||
124 | assert.is.falsy(output:find("Checking stability of dependencies")) | ||
125 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.0-1")) | ||
126 | end) | ||
127 | end) | ||
128 | 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..2821c143 --- /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")) | ||
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("make luasocket-3.0rc1-1.rockspec")) | ||
34 | |||
35 | -- test it | ||
36 | assert.is_true(run.luarocks_bool("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("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("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("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..4e4d5d27 --- /dev/null +++ b/spec/new_version_spec.lua | |||
@@ -0,0 +1,65 @@ | |||
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 | test_env.remove_files(lfs.currentdir(), "abelhas--") | ||
34 | end) | ||
35 | end) | ||
36 | |||
37 | describe("LuaRocks new_version more complex tests", function() | ||
38 | it("LuaRocks new_version of luacov", function() | ||
39 | assert.is_true(run.luarocks_bool("download --rockspec luacov 0.11.0")) | ||
40 | assert.is_true(run.luarocks_bool("new_version luacov-0.11.0-1.rockspec 0.2")) | ||
41 | assert.is.truthy(lfs.attributes("luacov-0.2-1.rockspec")) | ||
42 | test_env.remove_files(lfs.currentdir(), "luacov--") | ||
43 | end) | ||
44 | |||
45 | it("LuaRocks new_version url of abelhas", function() | ||
46 | assert.is_true(run.luarocks_bool("download --rockspec abelhas 1.0")) | ||
47 | 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")) | ||
48 | assert.is.truthy(lfs.attributes("abelhas-1.1-1.rockspec")) | ||
49 | test_env.remove_files(lfs.currentdir(), "abelhas--") | ||
50 | end) | ||
51 | |||
52 | it("LuaRocks new_version of luacov with tag", function() | ||
53 | assert.is_true(run.luarocks_bool("download --rockspec luacov 0.11.0")) | ||
54 | assert.is_true(run.luarocks_bool("new_version luacov-0.11.0-1.rockspec --tag v0.3")) | ||
55 | assert.is.truthy(lfs.attributes("luacov-0.3-1.rockspec")) | ||
56 | test_env.remove_files(lfs.currentdir(), "luacov--") | ||
57 | end) | ||
58 | |||
59 | it("LuaRocks new version updating md5", function() | ||
60 | assert.is_true(run.luarocks_bool("download --rockspec lpeg 0.12")) | ||
61 | 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")) | ||
62 | test_env.remove_files(lfs.currentdir(), "lpeg--") | ||
63 | end) | ||
64 | end) | ||
65 | end) | ||
diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua new file mode 100644 index 00000000..416184a8 --- /dev/null +++ b/spec/pack_spec.lua | |||
@@ -0,0 +1,33 @@ | |||
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 | "/luasec-0.6-1.rockspec", | ||
9 | "/luasocket-3.0rc1-1.src.rock", | ||
10 | "/luasocket-3.0rc1-1.rockspec" | ||
11 | } | ||
12 | |||
13 | describe("LuaRocks pack tests #blackbox #b_pack", function() | ||
14 | |||
15 | before_each(function() | ||
16 | test_env.setup_specs(extra_rocks) | ||
17 | end) | ||
18 | |||
19 | it("LuaRocks pack basic", function() | ||
20 | assert.is_true(run.luarocks_bool("list")) | ||
21 | assert.is_true(run.luarocks_bool("pack luacov")) | ||
22 | assert.is_true(test_env.remove_files(lfs.currentdir(), "luacov-")) | ||
23 | end) | ||
24 | |||
25 | it("LuaRocks pack src", function() | ||
26 | assert.is_true(run.luarocks_bool("install luasec")) | ||
27 | assert.is_true(run.luarocks_bool("download --rockspec luasocket")) | ||
28 | assert.is_true(run.luarocks_bool("pack luasocket-3.0rc1-1.rockspec")) | ||
29 | assert.is_true(test_env.remove_files(lfs.currentdir(), "luasocket-")) | ||
30 | end) | ||
31 | end) | ||
32 | |||
33 | |||
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..41c6348a --- /dev/null +++ b/spec/remove_spec.lua | |||
@@ -0,0 +1,84 @@ | |||
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 | it("LuaRocks remove fail, break dependencies", function() | ||
48 | assert.is_true(test_env.need_luasocket()) | ||
49 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
50 | assert.is_true(run.luarocks_bool("build lualogging")) | ||
51 | |||
52 | assert.is_false(run.luarocks_bool("remove luasocket")) | ||
53 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
54 | end) | ||
55 | |||
56 | it("LuaRocks remove force", function() | ||
57 | assert.is_true(test_env.need_luasocket()) | ||
58 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
59 | assert.is_true(run.luarocks_bool("build lualogging")) | ||
60 | |||
61 | local output = run.luarocks("remove --force luasocket") | ||
62 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
63 | assert.is.truthy(output:find("Checking stability of dependencies")) | ||
64 | end) | ||
65 | |||
66 | it("LuaRocks remove force fast", function() | ||
67 | assert.is_true(test_env.need_luasocket()) | ||
68 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
69 | assert.is_true(run.luarocks_bool("build lualogging")) | ||
70 | |||
71 | local output = run.luarocks("remove --force-fast luasocket") | ||
72 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) | ||
73 | assert.is.falsy(output:find("Checking stability of dependencies")) | ||
74 | end) | ||
75 | end) | ||
76 | |||
77 | it("LuaRocks-admin remove #ssh", function() | ||
78 | assert.is_true(run.luarocks_admin_bool("--server=testing remove luasocket-3.0rc1-1.src.rock")) | ||
79 | end) | ||
80 | |||
81 | it("LuaRocks-admin remove missing", function() | ||
82 | assert.is_false(run.luarocks_admin_bool("--server=testing remove")) | ||
83 | end) | ||
84 | end) | ||
diff --git a/spec/search_spec.lua b/spec/search_spec.lua new file mode 100644 index 00000000..33c49856 --- /dev/null +++ b/spec/search_spec.lua | |||
@@ -0,0 +1,40 @@ | |||
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("search --all")) | ||
34 | end) | ||
35 | |||
36 | it("LuaRocks search zlib", function() | ||
37 | local num = 123 | ||
38 | assert.is_true(run.luarocks_bool("search " .. num)) | ||
39 | end) | ||
40 | 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..76e9e5a8 --- /dev/null +++ b/spec/unpack_spec.lua | |||
@@ -0,0 +1,58 @@ | |||
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 | "/cprint-0.1-2.src.rock", | ||
9 | "/cprint-0.1-2.rockspec" | ||
10 | } | ||
11 | |||
12 | describe("LuaRocks unpack tests #blackbox #b_unpack", function() | ||
13 | |||
14 | before_each(function() | ||
15 | test_env.setup_specs(extra_rocks) | ||
16 | end) | ||
17 | |||
18 | describe("LuaRocks unpack basic fail tests", function() | ||
19 | it("LuaRocks unpack with no flags/arguments", function() | ||
20 | assert.is_false(run.luarocks_bool("unpack")) | ||
21 | end) | ||
22 | it("LuaRocks unpack with invalid rockspec", function() | ||
23 | assert.is_false(run.luarocks_bool("unpack invalid.rockspec")) | ||
24 | end) | ||
25 | it("LuaRocks unpack with invalid patch", function() | ||
26 | assert.is_false(run.luarocks_bool("unpack " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) | ||
27 | end) | ||
28 | end) | ||
29 | |||
30 | describe("LuaRocks unpack more complex tests", function() | ||
31 | it("LuaRocks unpack download", function() | ||
32 | assert.is_true(run.luarocks_bool("unpack cprint")) | ||
33 | test_env.remove_dir("cprint-0.1-2") | ||
34 | end) | ||
35 | it("LuaRocks unpack src", function() | ||
36 | assert.is_true(run.luarocks_bool("download --source cprint")) | ||
37 | assert.is_true(run.luarocks_bool("unpack cprint-0.1-2.src.rock")) | ||
38 | os.remove("cprint-0.1-2.src.rock") | ||
39 | test_env.remove_dir("cprint-0.1-2") | ||
40 | end) | ||
41 | it("LuaRocks unpack src", function() | ||
42 | assert.is_true(run.luarocks_bool("download --rockspec cprint")) | ||
43 | assert.is_true(run.luarocks_bool("unpack cprint-0.1-2.rockspec")) | ||
44 | os.remove("cprint-0.1-2.rockspec") | ||
45 | os.remove("lua-cprint") | ||
46 | test_env.remove_dir("cprint-0.1-2") | ||
47 | end) | ||
48 | it("LuaRocks unpack binary", function() | ||
49 | assert.is_true(run.luarocks_bool("build cprint")) | ||
50 | assert.is_true(run.luarocks_bool("pack cprint")) | ||
51 | assert.is_true(run.luarocks_bool("unpack cprint-0.1-2." .. test_env.platform .. ".rock")) | ||
52 | test_env.remove_dir("cprint-0.1-2") | ||
53 | os.remove("cprint-0.1-2." .. test_env.platform .. ".rock") | ||
54 | end) | ||
55 | end) | ||
56 | end) | ||
57 | |||
58 | |||
diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua new file mode 100644 index 00000000..c10ef0e9 --- /dev/null +++ b/spec/upload_spec.lua | |||
@@ -0,0 +1,39 @@ | |||
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 | "/lua-cjson-2.1.0-1.src.rock" | ||
8 | } | ||
9 | |||
10 | describe("LuaRocks upload tests #blackbox #b_upload", function() | ||
11 | |||
12 | before_each(function() | ||
13 | test_env.setup_specs(extra_rocks) | ||
14 | end) | ||
15 | |||
16 | it("LuaRocks upload with no flags/arguments", function() | ||
17 | assert.is_false(run.luarocks_bool("upload")) | ||
18 | end) | ||
19 | |||
20 | it("LuaRocks upload invalid rockspec", function() | ||
21 | assert.is_false(run.luarocks_bool("upload invalid.rockspec")) | ||
22 | end) | ||
23 | |||
24 | it("LuaRocks upload api key invalid", function() | ||
25 | assert.is_false(run.luarocks_bool("upload --api-key=invalid invalid.rockspec")) | ||
26 | end) | ||
27 | |||
28 | it("LuaRocks upload api key invalid and skip-pack", function() | ||
29 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --skip-pack luacov-0.11.0-1.rockspec")) | ||
30 | end) | ||
31 | |||
32 | it("LuaRocks upload force", function() | ||
33 | assert.is_true(run.luarocks_bool("install lua-cjson")) | ||
34 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force luacov-0.11.0-1.rockspec")) | ||
35 | assert.is_true(run.luarocks_bool("install lua-cjson")) | ||
36 | end) | ||
37 | end) | ||
38 | |||
39 | |||
diff --git a/spec/util_spec.lua b/spec/util_spec.lua new file mode 100644 index 00000000..9118ffc9 --- /dev/null +++ b/spec/util_spec.lua | |||
@@ -0,0 +1,96 @@ | |||
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 | assert.is_false(run.luarocks_bool(" ")) | ||
38 | assert.is_true(lfs.chdir(main_path)) | ||
39 | assert.is_true(run.luarocks_bool(" ")) | ||
40 | end) | ||
41 | |||
42 | it("LuaRocks timeout", function() | ||
43 | assert.is_true(run.luarocks_bool("--timeout=10")) | ||
44 | end) | ||
45 | |||
46 | it("LuaRocks timeout invalid", function() | ||
47 | assert.is_false(run.luarocks_bool("--timeout=abc")) | ||
48 | end) | ||
49 | |||
50 | it("LuaRocks only server=testing", function() | ||
51 | assert.is_true(run.luarocks_bool("--only-server=testing")) | ||
52 | end) | ||
53 | |||
54 | it("LuaRocks test site config", function() | ||
55 | assert.is.truthy(os.rename("src/luarocks/site_config.lua", "src/luarocks/site_config.lua.tmp")) | ||
56 | assert.is.falsy(lfs.attributes("src/luarocks/site_config.lua")) | ||
57 | assert.is.truthy(lfs.attributes("src/luarocks/site_config.lua.tmp")) | ||
58 | |||
59 | assert.is_true(run.luarocks_bool("")) | ||
60 | |||
61 | assert.is.truthy(os.rename("src/luarocks/site_config.lua.tmp", "src/luarocks/site_config.lua")) | ||
62 | assert.is.falsy(lfs.attributes("src/luarocks/site_config.lua.tmp")) | ||
63 | assert.is.truthy(lfs.attributes("src/luarocks/site_config.lua")) | ||
64 | end) | ||
65 | |||
66 | describe("LuaRocks sysconfig fails", function() | ||
67 | local scdir = "" | ||
68 | |||
69 | before_each(function() | ||
70 | scdir = testing_paths.testing_lrprefix .. "/etc/luarocks/" | ||
71 | lfs.mkdir(testing_paths.testing_lrprefix) | ||
72 | lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") | ||
73 | lfs.mkdir(scdir) | ||
74 | end) | ||
75 | |||
76 | after_each(function() | ||
77 | test_env.remove_dir(testing_paths.testing_lrprefix) | ||
78 | end) | ||
79 | |||
80 | it("LuaRocks sysconfig fail", function() | ||
81 | local sysconfig = io.open(scdir .. "/config.lua", "w+") | ||
82 | sysconfig:write("aoeui") | ||
83 | sysconfig:close() | ||
84 | |||
85 | assert.is_false(run.luarocks_bool("list")) | ||
86 | end) | ||
87 | |||
88 | it("LuaRocks sysconfig fail", function() | ||
89 | local sysconfig = io.open(scdir .. "/config-" .. env_variables.LUA_VERSION .. ".lua", "w+") | ||
90 | sysconfig:write("aoeui") | ||
91 | sysconfig:close() | ||
92 | |||
93 | assert.is_false(run.luarocks_bool("list")) | ||
94 | end) | ||
95 | end) | ||
96 | end) | ||
diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua new file mode 100644 index 00000000..85e345d5 --- /dev/null +++ b/spec/write_rockspec_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 | |||
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\" " | ||
68 | .. "--lua-version=5.1,5.2")) | ||
69 | assert.is.truthy(lfs.attributes("luafcgi-scm-1.rockspec")) -- TODO maybe read it content and find arguments from flags? | ||
70 | assert.is_true(os.remove("luafcgi-scm-1.rockspec")) | ||
71 | end) | ||
72 | end) | ||
73 | end) | ||
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 28f97702..871e97e9 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
@@ -65,7 +65,7 @@ function help.command(flags, command) | |||
65 | --verbose Display verbose output of commands executed. | 65 | --verbose Display verbose output of commands executed. |
66 | --timeout=<seconds> Timeout on network operations, in seconds. | 66 | --timeout=<seconds> Timeout on network operations, in seconds. |
67 | 0 means no timeout (wait forever). | 67 | 0 means no timeout (wait forever). |
68 | Default is ]]..cfg.connection_timeout..[[.]]) | 68 | Default is ]]..tostring(cfg.connection_timeout)..[[.]]) |
69 | print_section("VARIABLES") | 69 | print_section("VARIABLES") |
70 | util.printout([[ | 70 | util.printout([[ |
71 | Variables from the "variables" table of the configuration file | 71 | Variables from the "variables" table of the configuration file |
diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 82763401..63c59ca2 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua | |||
@@ -234,9 +234,12 @@ end | |||
234 | 234 | ||
235 | local function mkfield(context, field) | 235 | local function mkfield(context, field) |
236 | if context == "" then | 236 | if context == "" then |
237 | return field | 237 | return tostring(field) |
238 | elseif type(field) == "string" then | ||
239 | return context.."."..field | ||
240 | else | ||
241 | return context.."["..tostring(field).."]" | ||
238 | end | 242 | end |
239 | return context.."."..field | ||
240 | end | 243 | end |
241 | 244 | ||
242 | --- Type check the contents of a table. | 245 | --- Type check the contents of a table. |
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/test_environment.lua b/test/test_environment.lua new file mode 100644 index 00000000..6de7a4e2 --- /dev/null +++ b/test/test_environment.lua | |||
@@ -0,0 +1,599 @@ | |||
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 | clean Remove existing testing environment. | ||
18 | travis Add if running on TravisCI. | ||
19 | os=<type> Set OS ("linux", "osx", or "windows"). | ||
20 | ]] | ||
21 | |||
22 | local function help() | ||
23 | print(help_message) | ||
24 | os.exit(1) | ||
25 | end | ||
26 | |||
27 | local function title(str) | ||
28 | print() | ||
29 | print(("-"):rep(#str)) | ||
30 | print(str) | ||
31 | print(("-"):rep(#str)) | ||
32 | end | ||
33 | |||
34 | local function exists(path) | ||
35 | return lfs.attributes(path, "mode") ~= nil | ||
36 | end | ||
37 | |||
38 | --- Helper function for execute_bool and execute_output | ||
39 | -- @param command string: command to execute | ||
40 | -- @param print_command boolean: print command if 'true' | ||
41 | -- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"} | ||
42 | -- @return final_command string: concatenated command to execution | ||
43 | local function execute_helper(command, print_command, env_variables) | ||
44 | local final_command = "" | ||
45 | |||
46 | if print_command then | ||
47 | print("\n[EXECUTING]: " .. command) | ||
48 | end | ||
49 | |||
50 | if env_variables then | ||
51 | final_command = "export " | ||
52 | for k,v in pairs(env_variables) do | ||
53 | final_command = final_command .. k .. "='" .. v .. "' " | ||
54 | end | ||
55 | -- remove last space and add ';' to separate exporting variables from command | ||
56 | final_command = final_command:sub(1, -2) .. "; " | ||
57 | end | ||
58 | |||
59 | final_command = final_command .. command | ||
60 | |||
61 | return final_command | ||
62 | end | ||
63 | |||
64 | --- Execute command and returns true/false | ||
65 | -- In Lua5.1 os.execute returns numeric value, but in Lua5.2+ returns boolean | ||
66 | -- @return true/false boolean: status of the command execution | ||
67 | local function execute_bool(command, print_command, env_variables) | ||
68 | command = execute_helper(command, print_command, env_variables) | ||
69 | |||
70 | local ok = os.execute(command) | ||
71 | return ok == true or ok == 0 | ||
72 | end | ||
73 | |||
74 | --- Execute command and returns output of command | ||
75 | -- @return output string: output the command execution | ||
76 | local function execute_output(command, print_command, env_variables) | ||
77 | command = execute_helper(command, print_command, env_variables) | ||
78 | |||
79 | local file = assert(io.popen(command)) | ||
80 | local output = file:read('*all') | ||
81 | file:close() | ||
82 | return output:gsub("\n","") -- output adding new line, need to be removed | ||
83 | end | ||
84 | |||
85 | --- Set test_env.LUA_V or test_env.LUAJIT_V based | ||
86 | -- on version of Lua used to run this script. | ||
87 | function test_env.set_lua_version() | ||
88 | if _G.jit then | ||
89 | test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d") | ||
90 | else | ||
91 | test_env.LUA_V = _VERSION:match("5%.%d") | ||
92 | end | ||
93 | end | ||
94 | |||
95 | --- Set all arguments from input into global variables | ||
96 | function test_env.set_args() | ||
97 | -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables | ||
98 | test_env.TYPE_TEST_ENV = "minimal" | ||
99 | |||
100 | for _, argument in ipairs(arg) do | ||
101 | if argument:find("^env=") then | ||
102 | test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$") | ||
103 | elseif argument == "clean" then | ||
104 | test_env.TEST_ENV_CLEAN = true | ||
105 | elseif argument == "travis" then | ||
106 | test_env.TRAVIS = true | ||
107 | elseif argument:find("^os=") then | ||
108 | test_env.TEST_TARGET_OS = argument:match("^os=(.*)$") | ||
109 | else | ||
110 | help() | ||
111 | end | ||
112 | end | ||
113 | |||
114 | if not test_env.TEST_TARGET_OS then | ||
115 | title("OS CHECK") | ||
116 | |||
117 | if execute_bool("sw_vers") then | ||
118 | test_env.TEST_TARGET_OS = "osx" | ||
119 | elseif execute_bool("uname -s") then | ||
120 | test_env.TEST_TARGET_OS = "linux" | ||
121 | else | ||
122 | test_env.TEST_TARGET_OS = "windows" | ||
123 | end | ||
124 | end | ||
125 | return true | ||
126 | end | ||
127 | |||
128 | --- Remove directory recursively | ||
129 | -- @param path string: directory path to delete | ||
130 | function test_env.remove_dir(path) | ||
131 | if exists(path) then | ||
132 | for file in lfs.dir(path) do | ||
133 | if file ~= "." and file ~= ".." then | ||
134 | local full_path = path..'/'..file | ||
135 | |||
136 | if lfs.attributes(full_path, "mode") == "directory" then | ||
137 | test_env.remove_dir(full_path) | ||
138 | else | ||
139 | os.remove(full_path) | ||
140 | end | ||
141 | end | ||
142 | end | ||
143 | end | ||
144 | os.remove(path) | ||
145 | end | ||
146 | |||
147 | --- Remove subdirectories of a directory that match a pattern | ||
148 | -- @param path string: path to directory | ||
149 | -- @param pattern string: pattern matching basenames of subdirectories to be removed | ||
150 | function test_env.remove_subdirs(path, pattern) | ||
151 | if exists(path) then | ||
152 | for file in lfs.dir(path) do | ||
153 | if file ~= "." and file ~= ".." then | ||
154 | local full_path = path..'/'..file | ||
155 | |||
156 | if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then | ||
157 | test_env.remove_dir(full_path) | ||
158 | end | ||
159 | end | ||
160 | end | ||
161 | end | ||
162 | end | ||
163 | |||
164 | --- Remove files matching a pattern | ||
165 | -- @param path string: directory where to delete files | ||
166 | -- @param pattern string: pattern matching basenames of files to be deleted | ||
167 | -- @return result_check boolean: true if one or more files deleted | ||
168 | function test_env.remove_files(path, pattern) | ||
169 | local result_check = false | ||
170 | if exists(path) then | ||
171 | for file in lfs.dir(path) do | ||
172 | if file ~= "." and file ~= ".." then | ||
173 | if file:find(pattern) then | ||
174 | if os.remove(path .. "/" .. file) then | ||
175 | result_check = true | ||
176 | end | ||
177 | end | ||
178 | end | ||
179 | end | ||
180 | end | ||
181 | return result_check | ||
182 | end | ||
183 | |||
184 | |||
185 | --- Function for downloading rocks and rockspecs | ||
186 | -- @param urls table: array of full names of rocks/rockspecs to download | ||
187 | -- @param save_path string: path to directory, where to download rocks/rockspecs | ||
188 | -- @return make_manifest boolean: true if new rocks downloaded | ||
189 | local function download_rocks(urls, save_path) | ||
190 | local luarocks_repo = "https://luarocks.org" | ||
191 | local make_manifest = false | ||
192 | |||
193 | for _, url in ipairs(urls) do | ||
194 | -- check if already downloaded | ||
195 | if not exists(save_path .. url) then | ||
196 | execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) | ||
197 | make_manifest = true | ||
198 | end | ||
199 | end | ||
200 | return make_manifest | ||
201 | end | ||
202 | |||
203 | --- Create a file containing a string. | ||
204 | -- @param path string: path to file. | ||
205 | -- @param str string: content of the file. | ||
206 | local function write_file(path, str) | ||
207 | local file = assert(io.open(path, "w")) | ||
208 | file:write(str) | ||
209 | file:close() | ||
210 | end | ||
211 | |||
212 | --- Create md5sum of directory structure recursively, based on filename and size | ||
213 | -- @param path string: path to directory for generate md5sum | ||
214 | -- @return md5sum string: md5sum of directory | ||
215 | local function hash_environment(path) | ||
216 | if test_env.TEST_TARGET_OS == "linux" then | ||
217 | return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") | ||
218 | elseif test_env.TEST_TARGET_OS == "osx" then | ||
219 | return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") | ||
220 | else | ||
221 | -- TODO: Windows | ||
222 | return "" | ||
223 | end | ||
224 | end | ||
225 | |||
226 | --- Create environment variables needed for tests | ||
227 | -- @param testing_paths table: table with paths to testing directory | ||
228 | -- @return env_variables table: table with created environment variables | ||
229 | local function create_env(testing_paths) | ||
230 | local luaversion_short = _VERSION:gsub("Lua ", "") | ||
231 | |||
232 | if test_env.LUAJIT_V then | ||
233 | luaversion_short="5.1" | ||
234 | end | ||
235 | |||
236 | local env_variables = {} | ||
237 | env_variables.LUA_VERSION = luaversion_short | ||
238 | env_variables.LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua" | ||
239 | env_variables.LUA_PATH = testing_paths.testing_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" | ||
240 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" | ||
241 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" | ||
242 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" | ||
243 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" | ||
244 | env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" | ||
245 | .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" | ||
246 | env_variables.PATH = os.getenv("PATH") .. ":" .. testing_paths.testing_tree .. "/bin:" .. testing_paths.testing_sys_tree .. "/bin" | ||
247 | |||
248 | return env_variables | ||
249 | end | ||
250 | |||
251 | --- Create md5sums of origin system and system-copy testing directory | ||
252 | -- @param testing_paths table: table with paths to testing directory | ||
253 | -- @return md5sums table: table of md5sums of system and system-copy testing directory | ||
254 | local function create_md5sums(testing_paths) | ||
255 | local md5sums = {} | ||
256 | md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy) | ||
257 | md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy) | ||
258 | |||
259 | return md5sums | ||
260 | end | ||
261 | |||
262 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) | ||
263 | local cmd_prefix = test_env.testing_paths.lua .. " " | ||
264 | |||
265 | if with_coverage then | ||
266 | cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testing_dir .. "/luacov.config')\" " | ||
267 | end | ||
268 | |||
269 | cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " | ||
270 | |||
271 | return function(cmd, new_vars) | ||
272 | local temp_vars = {} | ||
273 | for k, v in pairs(test_env.env_variables) do | ||
274 | temp_vars[k] = v | ||
275 | end | ||
276 | if new_vars then | ||
277 | for k, v in pairs(new_vars) do | ||
278 | temp_vars[k] = v | ||
279 | end | ||
280 | end | ||
281 | return exec_function(cmd_prefix .. cmd, do_print, temp_vars) | ||
282 | end | ||
283 | end | ||
284 | |||
285 | local function make_run_functions() | ||
286 | return { | ||
287 | luarocks = make_run_function("luarocks", execute_output, true, true), | ||
288 | luarocks_bool = make_run_function("luarocks", execute_bool, true, true), | ||
289 | luarocks_noprint = make_run_function("luarocks", execute_bool, true, false), | ||
290 | luarocks_nocov = make_run_function("luarocks", execute_bool, false, true), | ||
291 | luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false), | ||
292 | luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true), | ||
293 | luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true), | ||
294 | luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false) | ||
295 | } | ||
296 | end | ||
297 | |||
298 | --- Rebuild environment. | ||
299 | -- Remove old installed rocks and install new ones, | ||
300 | -- updating manifests and tree copies. | ||
301 | local function build_environment(rocks, env_variables) | ||
302 | title("BUILDING ENVIRONMENT") | ||
303 | local testing_paths = test_env.testing_paths | ||
304 | test_env.remove_dir(testing_paths.testing_tree) | ||
305 | test_env.remove_dir(testing_paths.testing_sys_tree) | ||
306 | test_env.remove_dir(testing_paths.testing_tree_copy) | ||
307 | test_env.remove_dir(testing_paths.testing_sys_tree_copy) | ||
308 | |||
309 | lfs.mkdir(testing_paths.testing_tree) | ||
310 | lfs.mkdir(testing_paths.testing_sys_tree) | ||
311 | |||
312 | test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) | ||
313 | test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) | ||
314 | |||
315 | for _, rock in ipairs(rocks) do | ||
316 | if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) then | ||
317 | test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) | ||
318 | test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) | ||
319 | execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) | ||
320 | end | ||
321 | end | ||
322 | |||
323 | execute_bool("cp -a " .. testing_paths.testing_tree .. "/. " .. testing_paths.testing_tree_copy) | ||
324 | execute_bool("cp -a " .. testing_paths.testing_sys_tree .. "/. " .. testing_paths.testing_sys_tree_copy) | ||
325 | end | ||
326 | |||
327 | --- Reset testing environment | ||
328 | local function reset_environment(testing_paths, md5sums) | ||
329 | local testing_tree_md5 = hash_environment(testing_paths.testing_tree) | ||
330 | local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree) | ||
331 | |||
332 | if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then | ||
333 | test_env.remove_dir(testing_paths.testing_tree) | ||
334 | execute_bool("cp -a " .. testing_paths.testing_tree_copy .. "/. " .. testing_paths.testing_tree) | ||
335 | end | ||
336 | if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then | ||
337 | test_env.remove_dir(testing_paths.testing_sys_tree) | ||
338 | execute_bool("cp -a " .. testing_paths.testing_sys_tree_copy .. "/. " .. testing_paths.testing_sys_tree) | ||
339 | end | ||
340 | |||
341 | print("\n[ENVIRONMENT RESET]") | ||
342 | end | ||
343 | |||
344 | local function create_paths(luaversion_full) | ||
345 | local cfg = require("luarocks.cfg") | ||
346 | |||
347 | local testing_paths = {} | ||
348 | testing_paths.luadir = cfg.variables.LUA_BINDIR:gsub("/bin/?$", "") | ||
349 | testing_paths.lua = cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter | ||
350 | |||
351 | testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows? | ||
352 | |||
353 | testing_paths.luarocks_dir = lfs.currentdir() | ||
354 | testing_paths.testing_dir = testing_paths.luarocks_dir .. "/test" | ||
355 | testing_paths.src_dir = testing_paths.luarocks_dir .. "/src" | ||
356 | testing_paths.testing_lrprefix = testing_paths.testing_dir .. "/testing_lrprefix-" .. luaversion_full | ||
357 | testing_paths.testing_tree = testing_paths.testing_dir .. "/testing-" .. luaversion_full | ||
358 | testing_paths.testing_tree_copy = testing_paths.testing_dir .. "/testing_copy-" .. luaversion_full | ||
359 | testing_paths.testing_sys_tree = testing_paths.testing_dir .. "/testing_sys-" .. luaversion_full | ||
360 | testing_paths.testing_sys_tree_copy = testing_paths.testing_dir .. "/testing_sys_copy-" .. luaversion_full | ||
361 | testing_paths.testing_cache = testing_paths.testing_dir .. "/testing_cache-" .. luaversion_full | ||
362 | testing_paths.testing_server = testing_paths.testing_dir .. "/testing_server-" .. luaversion_full | ||
363 | |||
364 | return testing_paths | ||
365 | end | ||
366 | |||
367 | --- Helper function to unload luarocks modules from global table package.loaded | ||
368 | -- Needed to load our local (testing) version of LuaRocks | ||
369 | function test_env.unload_luarocks() | ||
370 | for modname, _ in pairs(package.loaded) do | ||
371 | if modname:match("^luarocks%.") then | ||
372 | package.loaded[modname] = nil | ||
373 | end | ||
374 | end | ||
375 | end | ||
376 | |||
377 | --- Function for initially setup of environment, variables, md5sums for spec files | ||
378 | function test_env.setup_specs(extra_rocks) | ||
379 | -- if global variable about successful creation of testing environment doesn't exists, build environment | ||
380 | if not test_env.setup_done then | ||
381 | if test_env.TRAVIS then | ||
382 | if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then | ||
383 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") | ||
384 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") | ||
385 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") | ||
386 | execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts") | ||
387 | end | ||
388 | end | ||
389 | |||
390 | test_env.main() | ||
391 | package.path = test_env.env_variables.LUA_PATH | ||
392 | |||
393 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) | ||
394 | test_env.md5sums = create_md5sums(test_env.testing_paths) | ||
395 | test_env.setup_done = true | ||
396 | title("RUNNING TESTS") | ||
397 | end | ||
398 | |||
399 | if extra_rocks then | ||
400 | local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) | ||
401 | if make_manifest then | ||
402 | test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) | ||
403 | end | ||
404 | end | ||
405 | |||
406 | reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) | ||
407 | end | ||
408 | |||
409 | --- Helper function for tests which needs luasocket installed | ||
410 | function test_env.need_luasocket() | ||
411 | if test_env.run.luarocks_nocov("show luasocket") then | ||
412 | return true | ||
413 | else | ||
414 | local testing_cache = test_env.testing_paths.testing_cache .. "/" | ||
415 | local luasocket_rock = "luasocket-3.0rc1-1." .. test_env.platform .. ".rock" | ||
416 | if not exists(testing_cache .. luasocket_rock) then | ||
417 | test_env.run.luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") | ||
418 | os.rename(luasocket_rock, testing_cache .. luasocket_rock) | ||
419 | end | ||
420 | return test_env.run.luarocks_nocov("install " .. testing_cache .. luasocket_rock) | ||
421 | end | ||
422 | end | ||
423 | |||
424 | --- For each key-value pair in replacements table | ||
425 | -- replace %{key} in given string with value. | ||
426 | local function substitute(str, replacements) | ||
427 | return (str:gsub("%%%b{}", function(marker) | ||
428 | return replacements[marker:sub(3, -2)] | ||
429 | end)) | ||
430 | end | ||
431 | |||
432 | |||
433 | --- Create configs for luacov and several versions of Luarocks | ||
434 | -- configs needed for some tests. | ||
435 | local function create_configs() | ||
436 | -- testing_config.lua and testing_config_show_downloads.lua | ||
437 | local config_content = substitute([[ | ||
438 | rocks_trees = { | ||
439 | "%{testing_tree}", | ||
440 | { name = "system", root = "%{testing_sys_tree}" }, | ||
441 | } | ||
442 | rocks_servers = { | ||
443 | "%{testing_server}" | ||
444 | } | ||
445 | local_cache = "%{testing_cache}" | ||
446 | upload_server = "testing" | ||
447 | upload_user = "%{user}" | ||
448 | upload_servers = { | ||
449 | testing = { | ||
450 | rsync = "localhost/tmp/luarocks_testing", | ||
451 | }, | ||
452 | } | ||
453 | external_deps_dirs = { | ||
454 | "/usr/local", | ||
455 | "/usr", | ||
456 | -- These are used for a test that fails, so it | ||
457 | -- can point to invalid paths: | ||
458 | { | ||
459 | prefix = "/opt", | ||
460 | bin = "bin", | ||
461 | include = "include", | ||
462 | lib = { "lib", "lib64" }, | ||
463 | } | ||
464 | } | ||
465 | ]], { | ||
466 | user = os.getenv("USER"), | ||
467 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | ||
468 | testing_tree = test_env.testing_paths.testing_tree, | ||
469 | testing_server = test_env.testing_paths.testing_server, | ||
470 | testing_cache = test_env.testing_paths.testing_cache | ||
471 | }) | ||
472 | |||
473 | write_file(test_env.testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") | ||
474 | write_file(test_env.testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content | ||
475 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") | ||
476 | |||
477 | -- testing_config_sftp.lua | ||
478 | config_content = substitute([[ | ||
479 | rocks_trees = { | ||
480 | "%{testing_tree}", | ||
481 | "%{testing_sys_tree}", | ||
482 | } | ||
483 | local_cache = "%{testing_cache}" | ||
484 | upload_server = "testing" | ||
485 | upload_user = "%{user}" | ||
486 | upload_servers = { | ||
487 | testing = { | ||
488 | sftp = "localhost/tmp/luarocks_testing", | ||
489 | }, | ||
490 | } | ||
491 | ]], { | ||
492 | user = os.getenv("USER"), | ||
493 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | ||
494 | testing_tree = test_env.testing_paths.testing_tree, | ||
495 | testing_cache = test_env.testing_paths.testing_cache | ||
496 | }) | ||
497 | |||
498 | write_file(test_env.testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) | ||
499 | |||
500 | -- luacov.config | ||
501 | config_content = substitute([[ | ||
502 | return { | ||
503 | statsfile = "%{testing_dir}/luacov.stats.out", | ||
504 | reportfile = "%{testing_dir}/luacov.report.out", | ||
505 | modules = { | ||
506 | ["luarocks"] = "src/bin/luarocks", | ||
507 | ["luarocks-admin"] = "src/bin/luarocks-admin", | ||
508 | ["luarocks.*"] = "src", | ||
509 | ["luarocks.*.*"] = "src", | ||
510 | ["luarocks.*.*.*"] = "src" | ||
511 | } | ||
512 | } | ||
513 | ]], { | ||
514 | testing_dir = test_env.testing_paths.testing_dir | ||
515 | }) | ||
516 | |||
517 | write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content) | ||
518 | end | ||
519 | |||
520 | --- Remove testing directories. | ||
521 | local function clean() | ||
522 | print("Cleaning testing directory...") | ||
523 | test_env.remove_dir(test_env.testing_paths.luarocks_tmp) | ||
524 | test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]") | ||
525 | test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") | ||
526 | test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") | ||
527 | print("Cleaning done!") | ||
528 | end | ||
529 | |||
530 | --- Install luarocks into testing prefix. | ||
531 | local function install_luarocks(install_env_vars) | ||
532 | -- Configure LuaRocks testing environment | ||
533 | local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. | ||
534 | " --prefix=" .. test_env.testing_paths.testing_lrprefix .. | ||
535 | " && make clean" | ||
536 | |||
537 | assert(execute_bool(configure_cmd, false, install_env_vars)) | ||
538 | assert(execute_bool("make src/luarocks/site_config.lua && make dev", false, install_env_vars)) | ||
539 | end | ||
540 | |||
541 | --- | ||
542 | -- Main function to create config files and testing environment | ||
543 | function test_env.main() | ||
544 | local testing_paths = test_env.testing_paths | ||
545 | |||
546 | if test_env.TEST_ENV_CLEAN then | ||
547 | clean() | ||
548 | end | ||
549 | |||
550 | lfs.mkdir(testing_paths.testing_cache) | ||
551 | lfs.mkdir(testing_paths.luarocks_tmp) | ||
552 | |||
553 | create_configs() | ||
554 | |||
555 | local install_env_vars = { | ||
556 | LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua", | ||
557 | LUA_PATH = "", | ||
558 | LUA_CPATH = "" | ||
559 | } | ||
560 | |||
561 | install_luarocks(install_env_vars) | ||
562 | |||
563 | -- Preparation of rocks for building environment | ||
564 | local rocks = {} -- names of rocks, required for building environment | ||
565 | local urls = {} -- names of rock and rockspec files to be downloaded | ||
566 | table.insert(urls, "/luacov-0.11.0-1.rockspec") | ||
567 | table.insert(urls, "/luacov-0.11.0-1.src.rock") | ||
568 | |||
569 | if test_env.TYPE_TEST_ENV == "full" then | ||
570 | table.insert(urls, "/luafilesystem-1.6.3-1.src.rock") | ||
571 | table.insert(urls, "/luasocket-3.0rc1-1.src.rock") | ||
572 | table.insert(urls, "/luasocket-3.0rc1-1.rockspec") | ||
573 | table.insert(urls, "/luaposix-33.2.1-1.src.rock") | ||
574 | table.insert(urls, "/md5-1.2-1.src.rock") | ||
575 | table.insert(urls, "/lzlib-0.4.1.53-1.src.rock") | ||
576 | rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} | ||
577 | |||
578 | if test_env.LUA_V ~= "5.1" then | ||
579 | table.insert(urls, "/luabitop-1.0.2-1.rockspec") | ||
580 | table.insert(urls, "/luabitop-1.0.2-1.src.rock") | ||
581 | table.insert(rocks, "luabitop") | ||
582 | end | ||
583 | end | ||
584 | |||
585 | table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment | ||
586 | |||
587 | -- Download rocks needed for LuaRocks testing environment | ||
588 | lfs.mkdir(testing_paths.testing_server) | ||
589 | download_rocks(urls, testing_paths.testing_server) | ||
590 | build_environment(rocks, install_env_vars) | ||
591 | end | ||
592 | |||
593 | test_env.set_lua_version() | ||
594 | test_env.set_args() | ||
595 | test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) | ||
596 | test_env.env_variables = create_env(test_env.testing_paths) | ||
597 | test_env.run = make_run_functions() | ||
598 | |||
599 | return test_env | ||
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 cb10441c..00000000 --- a/test/testing.sh +++ /dev/null | |||
@@ -1,651 +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 | luashortversion=`echo $luaversion | cut -d. -f 1-2` | ||
34 | |||
35 | testing_dir="$PWD" | ||
36 | |||
37 | testing_lrprefix="$testing_dir/testing_lrprefix-$luaversion" | ||
38 | testing_tree="$testing_dir/testing-$luaversion" | ||
39 | testing_sys_tree="$testing_dir/testing_sys-$luaversion" | ||
40 | testing_tree_copy="$testing_dir/testing_copy-$luaversion" | ||
41 | testing_sys_tree_copy="$testing_dir/testing_sys_copy-$luaversion" | ||
42 | testing_cache="$testing_dir/testing_cache-$luaversion" | ||
43 | testing_server="$testing_dir/testing_server-$luaversion" | ||
44 | |||
45 | if [ "$1" == "--clean" ] | ||
46 | then | ||
47 | shift | ||
48 | rm -rf "$testing_cache" | ||
49 | rm -rf "$testing_server" | ||
50 | fi | ||
51 | |||
52 | [ "$1" ] || rm -f luacov.stats.out | ||
53 | rm -f luacov.report.out | ||
54 | rm -rf /tmp/luarocks_testing | ||
55 | mkdir /tmp/luarocks_testing | ||
56 | rm -rf "$testing_lrprefix" | ||
57 | rm -rf "$testing_tree" | ||
58 | rm -rf "$testing_sys_tree" | ||
59 | rm -rf "$testing_tree_copy" | ||
60 | rm -rf "$testing_sys_tree_copy" | ||
61 | rm -rf "$testing_dir/testing_config.lua" | ||
62 | rm -rf "$testing_dir/testing_config_show_downloads.lua" | ||
63 | rm -rf "$testing_dir/testing_config_sftp.lua" | ||
64 | rm -rf "$testing_dir/luacov.config" | ||
65 | |||
66 | mkdir -p "$testing_cache" | ||
67 | |||
68 | [ "$1" = "clean" ] && { | ||
69 | rm -f luacov.stats.out | ||
70 | exit 0 | ||
71 | } | ||
72 | |||
73 | cat <<EOF > $testing_dir/testing_config.lua | ||
74 | rocks_trees = { | ||
75 | "$testing_tree", | ||
76 | { name = "system", root = "$testing_sys_tree" }, | ||
77 | } | ||
78 | rocks_servers = { | ||
79 | "$testing_server" | ||
80 | } | ||
81 | local_cache = "$testing_cache" | ||
82 | upload_server = "testing" | ||
83 | upload_user = "$USER" | ||
84 | upload_servers = { | ||
85 | testing = { | ||
86 | rsync = "localhost/tmp/luarocks_testing", | ||
87 | }, | ||
88 | } | ||
89 | external_deps_dirs = { | ||
90 | "/usr/local", | ||
91 | "/usr", | ||
92 | -- These are used for a test that fails, so it | ||
93 | -- can point to invalid paths: | ||
94 | { | ||
95 | prefix = "/opt", | ||
96 | bin = "bin", | ||
97 | include = "include", | ||
98 | lib = { "lib", "lib64" }, | ||
99 | } | ||
100 | } | ||
101 | EOF | ||
102 | ( | ||
103 | cat $testing_dir/testing_config.lua | ||
104 | echo "show_downloads = true" | ||
105 | ) > $testing_dir/testing_config_show_downloads.lua | ||
106 | cat <<EOF > $testing_dir/testing_config_sftp.lua | ||
107 | rocks_trees = { | ||
108 | "$testing_tree", | ||
109 | "$testing_sys_tree", | ||
110 | } | ||
111 | local_cache = "$testing_cache" | ||
112 | upload_server = "testing" | ||
113 | upload_user = "$USER" | ||
114 | upload_servers = { | ||
115 | testing = { | ||
116 | sftp = "localhost/tmp/luarocks_testing", | ||
117 | }, | ||
118 | } | ||
119 | EOF | ||
120 | cat <<EOF > $testing_dir/luacov.config | ||
121 | return { | ||
122 | statsfile = "$testing_dir/luacov.stats.out", | ||
123 | reportfile = "$testing_dir/luacov.report.out", | ||
124 | modules = { | ||
125 | ["luarocks"] = "src/bin/luarocks", | ||
126 | ["luarocks-admin"] = "src/bin/luarocks-admin", | ||
127 | ["luarocks.*"] = "src", | ||
128 | ["luarocks.*.*"] = "src", | ||
129 | ["luarocks.*.*.*"] = "src" | ||
130 | } | ||
131 | } | ||
132 | EOF | ||
133 | |||
134 | export LUAROCKS_CONFIG="$testing_dir/testing_config.lua" | ||
135 | export LUA_PATH= | ||
136 | export LUA_CPATH= | ||
137 | |||
138 | if [ "$travis" ] | ||
139 | then | ||
140 | luadir=/tmp/lua-$luaversion | ||
141 | pushd /tmp | ||
142 | if [ ! -e "$luadir/bin/lua" ] | ||
143 | then | ||
144 | mkdir -p lua | ||
145 | echo "Downloading lua $luaversion..." | ||
146 | wget "http://www.lua.org/ftp/lua-$luaversion.tar.gz" &> /dev/null | ||
147 | tar zxpf "lua-$luaversion.tar.gz" | ||
148 | cd "lua-$luaversion" | ||
149 | echo "Building lua $luaversion..." | ||
150 | make linux INSTALL_TOP="$luadir" &> /dev/null | ||
151 | make install INSTALL_TOP="$luadir" &> /dev/null | ||
152 | fi | ||
153 | popd | ||
154 | [ -e ~/.ssh/id_rsa.pub ] || ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa | ||
155 | cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys | ||
156 | chmod og-wx ~/.ssh/authorized_keys | ||
157 | ssh-keyscan localhost >> ~/.ssh/known_hosts | ||
158 | else | ||
159 | luadir="/Programs/Lua/Current" | ||
160 | if [ ! -e "$luadir" ] | ||
161 | then | ||
162 | luadir="/usr/local" | ||
163 | fi | ||
164 | fi | ||
165 | |||
166 | if [ `uname -m` = i686 ] | ||
167 | then | ||
168 | platform="linux-x86" | ||
169 | else | ||
170 | platform="linux-x86_64" | ||
171 | fi | ||
172 | |||
173 | lua="$luadir/bin/lua" | ||
174 | |||
175 | version_luasocket=3.0rc1 | ||
176 | verrev_luasocket=${version_luasocket}-1 | ||
177 | srcdir_luasocket=luasocket-3.0-rc1 | ||
178 | |||
179 | version_cprint=0.1 | ||
180 | verrev_cprint=0.1-2 | ||
181 | |||
182 | new_version_say=1.2-1 | ||
183 | old_version_say=1.0-1 | ||
184 | |||
185 | version_luacov=0.11.0 | ||
186 | verrev_luacov=${version_luacov}-1 | ||
187 | version_lxsh=0.8.6 | ||
188 | version_validate_args=1.5.4 | ||
189 | verrev_validate_args=1.5.4-1 | ||
190 | verrev_lxsh=${version_lxsh}-2 | ||
191 | version_abelhas=1.0 | ||
192 | verrev_abelhas=${version_abelhas}-1 | ||
193 | |||
194 | luasec=luasec | ||
195 | |||
196 | cd .. | ||
197 | ./configure --with-lua="$luadir" --prefix="$testing_lrprefix" | ||
198 | make clean | ||
199 | make src/luarocks/site_config.lua | ||
200 | make dev | ||
201 | cd src | ||
202 | basedir=$PWD | ||
203 | run_lua() { | ||
204 | if [ "$1" = "--noecho" ]; then shift; noecho=1; else noecho=0; fi | ||
205 | if [ "$1" = "--nocov" ]; then shift; nocov=1; else nocov=0; fi | ||
206 | if [ "$noecho" = 0 ] | ||
207 | then | ||
208 | echo $* | ||
209 | fi | ||
210 | cmd=$1 | ||
211 | shift | ||
212 | if [ "$nocov" = 0 ] | ||
213 | then | ||
214 | "$lua" -e"require('luacov.runner')('$testing_dir/luacov.config')" "$basedir/bin/$cmd" "$@" | ||
215 | else | ||
216 | "$lua" "$basedir/bin/$cmd" "$@" | ||
217 | fi | ||
218 | } | ||
219 | luarocks="run_lua luarocks" | ||
220 | luarocks_nocov="run_lua --nocov luarocks" | ||
221 | luarocks_noecho="run_lua --noecho luarocks" | ||
222 | luarocks_noecho_nocov="run_lua --noecho --nocov luarocks" | ||
223 | luarocks_admin="run_lua luarocks-admin" | ||
224 | luarocks_admin_nocov="run_lua --nocov luarocks-admin" | ||
225 | |||
226 | ################################################### | ||
227 | |||
228 | mkdir -p "$testing_server" | ||
229 | ( | ||
230 | cd "$testing_server" | ||
231 | luarocks_repo="https://luarocks.org" | ||
232 | get() { [ -e `basename "$1"` ] || wget -c "$1"; } | ||
233 | get "$luarocks_repo/luacov-${verrev_luacov}.src.rock" | ||
234 | get "$luarocks_repo/luacov-${verrev_luacov}.rockspec" | ||
235 | get "$luarocks_repo/luadoc-3.0.1-1.src.rock" | ||
236 | get "$luarocks_repo/lualogging-1.3.0-1.src.rock" | ||
237 | get "$luarocks_repo/luasocket-${verrev_luasocket}.src.rock" | ||
238 | get "$luarocks_repo/luasocket-${verrev_luasocket}.rockspec" | ||
239 | get "$luarocks_repo/luafilesystem-1.6.3-1.src.rock" | ||
240 | get "$luarocks_repo/stdlib-41.0.0-1.src.rock" | ||
241 | get "$luarocks_repo/luarepl-0.4-1.src.rock" | ||
242 | get "$luarocks_repo/validate-args-1.5.4-1.rockspec" | ||
243 | get "$luarocks_repo/luasec-0.6-1.rockspec" | ||
244 | get "$luarocks_repo/luabitop-1.0.2-1.rockspec" | ||
245 | get "$luarocks_repo/luabitop-1.0.2-1.src.rock" | ||
246 | get "$luarocks_repo/lpty-1.0.1-1.src.rock" | ||
247 | get "$luarocks_repo/cprint-${verrev_cprint}.src.rock" | ||
248 | get "$luarocks_repo/cprint-${verrev_cprint}.rockspec" | ||
249 | get "$luarocks_repo/wsapi-1.6-1.src.rock" | ||
250 | get "$luarocks_repo/lxsh-${verrev_lxsh}.src.rock" | ||
251 | get "$luarocks_repo/lxsh-${verrev_lxsh}.rockspec" | ||
252 | get "$luarocks_repo/abelhas-${verrev_abelhas}.rockspec" | ||
253 | get "$luarocks_repo/lzlib-0.4.1.53-1.src.rock" | ||
254 | get "$luarocks_repo/lpeg-0.12-1.src.rock" | ||
255 | get "$luarocks_repo/luaposix-33.2.1-1.src.rock" | ||
256 | get "$luarocks_repo/md5-1.2-1.src.rock" | ||
257 | get "$luarocks_repo/lmathx-20120430.51-1.src.rock" | ||
258 | get "$luarocks_repo/lmathx-20120430.51-1.rockspec" | ||
259 | get "$luarocks_repo/lmathx-20120430.52-1.src.rock" | ||
260 | get "$luarocks_repo/lmathx-20120430.52-1.rockspec" | ||
261 | get "$luarocks_repo/lmathx-20150505-1.src.rock" | ||
262 | get "$luarocks_repo/lmathx-20150505-1.rockspec" | ||
263 | get "$luarocks_repo/lua-path-0.2.3-1.src.rock" | ||
264 | get "$luarocks_repo/lua-cjson-2.1.0-1.src.rock" | ||
265 | get "$luarocks_repo/luacov-coveralls-0.1.1-1.src.rock" | ||
266 | get "$luarocks_repo/say-1.2-1.src.rock" | ||
267 | get "$luarocks_repo/say-1.0-1.src.rock" | ||
268 | get "$luarocks_repo/luassert-1.7.0-1.src.rock" | ||
269 | ) | ||
270 | $luarocks_admin_nocov make_manifest "$testing_server" | ||
271 | |||
272 | ################################################### | ||
273 | |||
274 | checksum_path() { | ||
275 | ( cd "$1"; find . -printf "%s %p\n" | md5sum ) | ||
276 | } | ||
277 | |||
278 | build_environment() { | ||
279 | rm -rf "$testing_tree" | ||
280 | rm -rf "$testing_sys_tree" | ||
281 | rm -rf "$testing_tree_copy" | ||
282 | rm -rf "$testing_sys_tree_copy" | ||
283 | mkdir -p "$testing_tree" | ||
284 | mkdir -p "$testing_sys_tree" | ||
285 | $luarocks_admin_nocov make_manifest "$testing_cache" | ||
286 | for package in "$@" | ||
287 | do | ||
288 | $luarocks_nocov install --only-server="$testing_cache" --tree="$testing_sys_tree" $package || { | ||
289 | $luarocks_nocov build --tree="$testing_sys_tree" $package | ||
290 | $luarocks_nocov pack --tree="$testing_sys_tree" $package; mv $package-*.rock "$testing_cache" | ||
291 | } | ||
292 | done | ||
293 | export LUA_PATH= | ||
294 | export LUA_CPATH= | ||
295 | eval `$luarocks_noecho_nocov path --bin` | ||
296 | cp -a "$testing_tree" "$testing_tree_copy" | ||
297 | cp -a "$testing_sys_tree" "$testing_sys_tree_copy" | ||
298 | testing_tree_copy_md5=`checksum_path "$testing_tree_copy"` | ||
299 | testing_sys_tree_copy_md5=`checksum_path "$testing_sys_tree_copy"` | ||
300 | } | ||
301 | |||
302 | reset_environment() { | ||
303 | testing_tree_md5=`checksum_path "$testing_tree"` | ||
304 | testing_sys_tree_md5=`checksum_path "$testing_sys_tree"` | ||
305 | if [ "$testing_tree_md5" != "$testing_tree_copy_md5" ] | ||
306 | then | ||
307 | rm -rf "$testing_tree" | ||
308 | cp -a "$testing_tree_copy" "$testing_tree" | ||
309 | fi | ||
310 | if [ "$testing_sys_tree_md5" != "$testing_sys_tree_copy_md5" ] | ||
311 | then | ||
312 | rm -rf "$testing_sys_tree" | ||
313 | cp -a "$testing_sys_tree_copy" "$testing_sys_tree" | ||
314 | fi | ||
315 | } | ||
316 | |||
317 | need() { | ||
318 | echo "Obtaining $1 $2..." | ||
319 | if $luarocks show $1 &> /dev/null | ||
320 | then | ||
321 | echo "Already available" | ||
322 | return | ||
323 | fi | ||
324 | platrock="$1-$2.$platform.rock" | ||
325 | if [ ! -e "$testing_cache/$platrock" ] | ||
326 | then | ||
327 | echo "Building $1 $2..." | ||
328 | $luarocks_nocov build --pack-binary-rock $1 $2 | ||
329 | mv "$platrock" "$testing_cache" | ||
330 | fi | ||
331 | echo "Installing $1 $2..." | ||
332 | $luarocks_nocov install "$testing_cache/$platrock" | ||
333 | return | ||
334 | } | ||
335 | need_luasocket() { need luasocket $verrev_luasocket; } | ||
336 | |||
337 | # Tests ######################################### | ||
338 | test_version() { $luarocks --version; } | ||
339 | |||
340 | fail_unknown_command() { $luarocks unknown_command; } | ||
341 | |||
342 | fail_arg_boolean_parameter() { $luarocks --porcelain=invalid; } | ||
343 | fail_arg_boolean_unknown() { $luarocks --invalid-flag; } | ||
344 | fail_arg_string_no_parameter() { $luarocks --server; } | ||
345 | fail_arg_string_followed_by_flag() { $luarocks --server --porcelain; } | ||
346 | fail_arg_string_unknown() { $luarocks --invalid-flag=abc; } | ||
347 | |||
348 | fail_invalid_assignment() { $luarocks invalid=5; } | ||
349 | |||
350 | test_empty_list() { $luarocks list; } | ||
351 | test_list_outdated() { $luarocks list --outdated; } | ||
352 | |||
353 | 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"; } | ||
354 | 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"; } | ||
355 | |||
356 | fail_build_noarg() { $luarocks build; } | ||
357 | fail_download_noarg() { $luarocks download; } | ||
358 | fail_install_noarg() { $luarocks install; } | ||
359 | fail_lint_noarg() { $luarocks lint; } | ||
360 | fail_search_noarg() { $luarocks search; } | ||
361 | fail_show_noarg() { $luarocks show; } | ||
362 | fail_unpack_noarg() { $luarocks unpack; } | ||
363 | fail_upload_noarg() { $luarocks upload; } | ||
364 | fail_remove_noarg() { $luarocks remove; } | ||
365 | fail_doc_noarg() { $luarocks doc; } | ||
366 | |||
367 | fail_build_invalid() { $luarocks build invalid; } | ||
368 | fail_download_invalid() { $luarocks download invalid; } | ||
369 | fail_install_invalid() { $luarocks install invalid; } | ||
370 | fail_lint_invalid() { $luarocks lint invalid; } | ||
371 | fail_show_invalid() { $luarocks show invalid; } | ||
372 | fail_new_version_invalid() { $luarocks new_version invalid; } | ||
373 | |||
374 | test_list_invalidtree() { $luarocks --tree=/some/invalid/tree list; } | ||
375 | |||
376 | fail_inexistent_dir() { mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err; } | ||
377 | |||
378 | fail_make_norockspec() { $luarocks make; } | ||
379 | |||
380 | fail_build_permissions() { $luarocks build --tree=/usr lpeg; } | ||
381 | fail_build_permissions_parent() { $luarocks build --tree=/usr/invalid lpeg; } | ||
382 | |||
383 | test_build_verbose() { $luarocks build --verbose lpeg; } | ||
384 | test_build_timeout() { $luarocks --timeout=10; } | ||
385 | fail_build_timeout_invalid() { $luarocks --timeout=abc; } | ||
386 | test_build_branch() { $luarocks build --branch=master lpeg; } | ||
387 | fail_build_invalid_entry_deps_mode() { $luarocks build --deps-mode=123 lpeg; } | ||
388 | test_build_only_server() { $luarocks --only-server=testing; } | ||
389 | test_build_only_sources() { $luarocks build --only-sources="http://example.com" lpeg; } | ||
390 | fail_build_blank_arg() { $luarocks build --tree="" lpeg; } | ||
391 | test_build_withpatch() { need_luasocket; $luarocks build luadoc; } | ||
392 | test_build_diffversion() { $luarocks build luacov ${version_luacov}; } | ||
393 | test_build_command() { $luarocks build stdlib; } | ||
394 | test_build_install_bin() { $luarocks build luarepl; } | ||
395 | 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; } | ||
396 | 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; } | ||
397 | test_build_supported_platforms() { $luarocks build lpty; } | ||
398 | test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } | ||
399 | 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 ]; }; } | ||
400 | test_build_only_deps() { $luarocks build luasec --only-deps && { $luarocks show luasec; [ $? -ne 0 ]; }; } | ||
401 | test_install_only_deps() { $luarocks install lxsh ${verrev_lxsh} --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } | ||
402 | test_build_no_deps() { $luarocks build luasec --nodeps; } | ||
403 | test_install_no_deps() { $luarocks install luasec --nodeps; } | ||
404 | fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; } | ||
405 | fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } | ||
406 | |||
407 | test_build_deps_partial_match() { $luarocks build lmathx; } | ||
408 | 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"; } | ||
409 | |||
410 | test_download_all() { $luarocks download --all validate-args && rm validate-args-*; } | ||
411 | test_download_rockspecversion() { $luarocks download --rockspec validate-args ${verrev_validate_args} && rm validate-args-*; } | ||
412 | |||
413 | test_help() { $luarocks help; } | ||
414 | fail_help_invalid() { $luarocks help invalid; } | ||
415 | |||
416 | test_install_only_deps() { $luarocks install --only-deps "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; } | ||
417 | test_install_binaryrock() { $luarocks build --pack-binary-rock cprint && $luarocks install ./cprint-${verrev_cprint}.${platform}.rock && rm ./cprint-${verrev_cprint}.${platform}.rock; } | ||
418 | test_install_with_bin() { $luarocks install wsapi; } | ||
419 | fail_install_notazipfile() { $luarocks install "$testing_dir/testfiles/not_a_zipfile-1.0-1.src.rock"; } | ||
420 | fail_install_invalidpatch() { need_luasocket; $luarocks install "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } | ||
421 | fail_install_invalid_filename() { $luarocks install "invalid.rock"; } | ||
422 | fail_install_invalid_arch() { $luarocks install "foo-1.0-1.impossible-x86.rock"; } | ||
423 | test_install_reinstall() { $luarocks install "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; $luarocks install --deps-mode=none "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; } | ||
424 | |||
425 | fail_local_root() { USER=root $luarocks install --local luasocket; } | ||
426 | |||
427 | 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; } | ||
428 | |||
429 | 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; } | ||
430 | fail_lint_type_mismatch_string() { $luarocks lint "$testing_dir/testfiles/type_mismatch_string-1.0-1.rockspec"; } | ||
431 | fail_lint_type_mismatch_version() { $luarocks lint "$testing_dir/testfiles/type_mismatch_version-1.0-1.rockspec"; } | ||
432 | fail_lint_type_mismatch_table() { $luarocks lint "$testing_dir/testfiles/type_mismatch_table-1.0-1.rockspec"; } | ||
433 | fail_lint_no_build_table() { $luarocks lint "$testing_dir/testfiles/no_build_table-0.1-1.rockspec"; } | ||
434 | |||
435 | test_list() { $luarocks list; } | ||
436 | test_list_porcelain() { $luarocks list --porcelain; } | ||
437 | |||
438 | 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}; } | ||
439 | 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}; } | ||
440 | 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}; } | ||
441 | 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}; } | ||
442 | 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}; } | ||
443 | 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}; } | ||
444 | |||
445 | test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } | ||
446 | 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-*; } | ||
447 | 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; } | ||
448 | 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; } | ||
449 | |||
450 | test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; } | ||
451 | test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; } | ||
452 | |||
453 | test_path() { $luarocks path --bin; } | ||
454 | test_path_lr_path() { $luarocks path --lr-path; } | ||
455 | test_path_lr_cpath() { $luarocks path --lr-cpath; } | ||
456 | test_path_lr_bin() { $luarocks path --lr-bin; } | ||
457 | test_path_with_tree() { $luarocks path --tree=lua_modules; } | ||
458 | |||
459 | fail_purge_missing_tree() { $luarocks purge --tree="$testing_tree"; } | ||
460 | fail_purge_tree_notstring() { $luarocks purge --tree=1; } | ||
461 | test_purge() { $luarocks purge --tree="$testing_sys_tree"; } | ||
462 | test_purge_oldversions() { $luarocks purge --old-versions --tree="$testing_sys_tree"; } | ||
463 | |||
464 | test_remove() { $luarocks build abelhas ${version_abelhas} && $luarocks remove abelhas ${version_abelhas}; } | ||
465 | test_remove_force() { need_luasocket; $luarocks build lualogging && $luarocks remove --force luasocket; } | ||
466 | test_remove_force_fast() { need_luasocket; $luarocks build lualogging && $luarocks remove --force-fast luasocket; } | ||
467 | fail_remove_deps() { need_luasocket; $luarocks build lualogging && $luarocks remove luasocket; } | ||
468 | fail_remove_missing() { $luarocks remove missing_rock; } | ||
469 | fail_remove_invalid_name() { $luarocks remove invalid.rock; } | ||
470 | |||
471 | test_search_found() { $luarocks search zlib; } | ||
472 | test_search_missing() { $luarocks search missing_rock; } | ||
473 | test_search_version() { $luarocks search zlib 1.1; } | ||
474 | test_search_all() { $luarocks search --all; } | ||
475 | fail_search_nostring() { $var=123; $luarocks search $var; } | ||
476 | |||
477 | test_show() { $luarocks show luacov; } | ||
478 | test_show_modules() { $luarocks show --modules luacov; } | ||
479 | test_show_home() { $luarocks show --home luacov; } | ||
480 | test_show_deps() { $luarocks show --deps luacov; } | ||
481 | test_show_rockspec() { $luarocks show --rockspec luacov; } | ||
482 | test_show_mversion() { $luarocks show --mversion luacov; } | ||
483 | test_show_rocktree() { $luarocks show --rock-tree luacov; } | ||
484 | test_show_rockdir() { $luarocks show --rock-dir luacov; } | ||
485 | test_show_depends() { need_luasocket; $luarocks install $luasec && $luarocks show luasec; } | ||
486 | test_show_oldversion() { $luarocks install luacov ${version_luacov} && $luarocks show luacov ${version_luacov}; } | ||
487 | |||
488 | test_unpack_download() { rm -rf ./cprint-${verrev_cprint} && $luarocks unpack cprint && rm -rf ./cprint-${verrev_cprint}; } | ||
489 | test_unpack_src() { rm -rf ./cprint-${verrev_cprint} && $luarocks download --source cprint && $luarocks unpack ./cprint-${verrev_cprint}.src.rock && rm -rf ./cprint-${verrev_cprint}; } | ||
490 | test_unpack_rockspec() { rm -rf ./cprint-${verrev_cprint} && $luarocks download --rockspec cprint && $luarocks unpack ./cprint-${verrev_cprint}.rockspec && rm -rf ./cprint-${verrev_cprint}; } | ||
491 | 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}; } | ||
492 | fail_unpack_invalidpatch() { need_luasocket; $luarocks unpack "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } | ||
493 | fail_unpack_invalidrockspec() { need_luasocket; $luarocks unpack "invalid.rockspec"; } | ||
494 | |||
495 | fail_upload_invalidrockspec() { $luarocks upload "invalid.rockspec"; } | ||
496 | fail_upload_invalidkey() { $luarocks upload --api-key="invalid" "invalid.rockspec"; } | ||
497 | fail_upload_skippack() { $luarocks upload --api-key="invalid" --skip-pack "luacov-${verrev_luacov}.rockspec"; } | ||
498 | fail_upload_force() { $luarocks install lua-cjson && $luarocks upload --api-key="invalid" --force "luacov-${verrev_luacov}.rockspec" && $luarocks remove lua-cjson; } | ||
499 | |||
500 | |||
501 | test_admin_help() { $luarocks_admin help; } | ||
502 | |||
503 | test_admin_make_manifest() { $luarocks_admin make_manifest; } | ||
504 | test_admin_add_rsync() { $luarocks_admin --server=testing add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; } | ||
505 | 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"; } | ||
506 | fail_admin_add_missing() { $luarocks_admin --server=testing add; } | ||
507 | fail_admin_invalidserver() { $luarocks_admin --server=invalid add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; } | ||
508 | fail_admin_invalidrock() { $luarocks_admin --server=testing add invalid; } | ||
509 | test_admin_refresh_cache() { $luarocks_admin --server=testing refresh_cache; } | ||
510 | test_admin_remove() { $luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock; } | ||
511 | fail_admin_remove_missing() { $luarocks_admin --server=testing remove; } | ||
512 | fail_admin_split_server_url() { $luarocks_admin --server="localhost@/tmp/luarocks_testing" add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; } | ||
513 | |||
514 | fail_deps_mode_invalid_arg() { $luarocks remove luacov --deps-mode; } | ||
515 | 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 ]; } | ||
516 | 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 ]; } | ||
517 | 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 ]; } | ||
518 | 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 ]; } | ||
519 | test_deps_mode_none() { $luarocks build --tree="$testing_tree" --deps-mode=none lxsh; [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; } | ||
520 | test_deps_mode_nodeps_alias() { $luarocks build --tree="$testing_tree" --nodeps lxsh; [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; } | ||
521 | 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}; } | ||
522 | 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}; } | ||
523 | |||
524 | test_write_rockspec() { $luarocks write_rockspec git://github.com/keplerproject/luarocks; } | ||
525 | test_write_rockspec_name() { $luarocks write_rockspec luarocks git://github.com/keplerproject/luarocks; } | ||
526 | test_write_rockspec_name_version() { $luarocks write_rockspec luarocks 7.8.9 git://github.com/keplerproject/luarocks; } | ||
527 | test_write_rockspec_current_dir() { $luarocks write_rockspec; } | ||
528 | test_write_rockspec_tag() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0; } | ||
529 | test_write_rockspec_lib() { $luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2; } | ||
530 | test_write_rockspec_format() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2; } | ||
531 | 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"; } | ||
532 | fail_write_rockspec_args() { $luarocks write_rockspec invalid; } | ||
533 | fail_write_rockspec_args_url() { $luarocks write_rockspec http://example.com/invalid.zip; } | ||
534 | test_write_rockspec_http() { $luarocks write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1; } | ||
535 | test_write_rockspec_basedir() { $luarocks write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1; } | ||
536 | |||
537 | fail_config_noflags() { $luarocks config; } | ||
538 | test_config_lua_incdir() { $luarocks config --lua-incdir; } | ||
539 | test_config_lua_libdir() { $luarocks config --lua-libdir; } | ||
540 | test_config_lua_ver() { $luarocks config --lua-ver; } | ||
541 | fail_config_system_config() { rm -f "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; } | ||
542 | 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; } | ||
543 | 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; } | ||
544 | test_config_user_config() { $luarocks config --user-config; } | ||
545 | fail_config_user_config() { LUAROCKS_CONFIG="/missing_file.lua" $luarocks config --user-config; } | ||
546 | test_config_rock_trees() { $luarocks config --rock-trees; } | ||
547 | test_config_help() { $luarocks help config; } | ||
548 | |||
549 | # Tests for https://github.com/keplerproject/luarocks/issues/375 | ||
550 | test_fetch_base_dir() { $lua <<EOF | ||
551 | local fetch = require "luarocks.fetch" | ||
552 | |||
553 | assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) | ||
554 | assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) | ||
555 | assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) | ||
556 | assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) | ||
557 | assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) | ||
558 | assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) | ||
559 | EOF | ||
560 | } | ||
561 | |||
562 | test_doc() { $luarocks install luarepl; $luarocks doc luarepl; } | ||
563 | test_doc_home() { $luarocks install luacov; $luarocks doc luacov --home; } | ||
564 | fail_doc_invalid() { $luarocks doc invalid; } | ||
565 | test_doc_list() { $luarocks install luacov; $luarocks doc luacov --list; } | ||
566 | test_doc_local() { $luarocks install luacov; $luarocks doc luacov --local; } | ||
567 | test_doc_porcelain() { $luarocks install luacov; $luarocks doc luacov --porcelain; } | ||
568 | |||
569 | # Tests for https://github.com/keplerproject/luarocks/pull/552 | ||
570 | test_install_break_dependencies_warning() { need_luasocket; $luarocks install say ${new_version_say} && $luarocks install luassert && $luarocks install say ${old_version_say}; } | ||
571 | test_install_break_dependencies_force() { need_luasocket; $luarocks install say ${new_version_say} && $luarocks install luassert && $luarocks install --force say ${old_version_say}; } | ||
572 | test_install_break_dependencies_forcefast() { need_luasocket; $luarocks install say ${new_version_say} && $luarocks install luassert && $luarocks install --force-fast say ${old_version_say}; } | ||
573 | |||
574 | # Driver ######################################### | ||
575 | run_tests() { | ||
576 | grep "^test_$1.*(" < $testing_dir/testing.sh | cut -d'(' -f1 | while read test | ||
577 | do | ||
578 | echo "-------------------------------------------" | ||
579 | echo "$test" | ||
580 | echo "-------------------------------------------" | ||
581 | reset_environment | ||
582 | if $test | ||
583 | then | ||
584 | echo "OK: Expected success." | ||
585 | else | ||
586 | if [ $? = 99 ] | ||
587 | then echo "FAIL: Unexpected crash!"; exit 99 | ||
588 | fi | ||
589 | echo "FAIL: Unexpected failure."; exit 1 | ||
590 | fi | ||
591 | done | ||
592 | grep "^fail_$1.*(" < $testing_dir/testing.sh | cut -d'(' -f1 | while read test | ||
593 | do | ||
594 | echo "-------------------------------------------" | ||
595 | echo "$test" | ||
596 | echo "-------------------------------------------" | ||
597 | reset_environment | ||
598 | if $test | ||
599 | then echo "FAIL: Unexpected success."; exit 1 | ||
600 | else | ||
601 | if [ $? = 99 ] | ||
602 | then echo "FAIL: Unexpected crash!"; exit 99 | ||
603 | fi | ||
604 | echo "OK: Expected failure." | ||
605 | fi | ||
606 | done | ||
607 | } | ||
608 | |||
609 | run_with_minimal_environment() { | ||
610 | echo "===========================================" | ||
611 | echo "Running with minimal environment" | ||
612 | echo "===========================================" | ||
613 | build_environment luacov | ||
614 | run_tests $1 | ||
615 | } | ||
616 | |||
617 | run_with_full_environment() { | ||
618 | echo "===========================================" | ||
619 | echo "Running with full environment" | ||
620 | echo "===========================================" | ||
621 | |||
622 | local bitop= | ||
623 | [ "$luaversion" = "5.1.5" ] && bitop=luabitop | ||
624 | |||
625 | build_environment luacov luafilesystem luasocket $bitop luaposix md5 lzlib | ||
626 | run_tests $1 | ||
627 | } | ||
628 | |||
629 | run_all_tests() { | ||
630 | run_with_minimal_environment $1 | ||
631 | run_with_full_environment $1 | ||
632 | } | ||
633 | |||
634 | run_all_tests $1 | ||
635 | #run_with_minimal_environment $1 | ||
636 | |||
637 | cd "$testing_dir/.." | ||
638 | |||
639 | if [ "$travis" ] | ||
640 | then | ||
641 | if [ "$TRAVIS" ] | ||
642 | then | ||
643 | build_environment luacov luafilesystem luacov-coveralls | ||
644 | $testing_sys_tree/bin/luacov-coveralls -c "$testing_dir/luacov.config" || echo "ok" | ||
645 | fi | ||
646 | $testing_sys_tree/bin/luacov -c "$testing_dir/luacov.config" | ||
647 | grep "Summary" -B1 -A1000 "$testing_dir/luacov.report.out" | ||
648 | else | ||
649 | $testing_sys_tree/bin/luacov -c "$testing_dir/luacov.config" | ||
650 | cat "$testing_dir/luacov.report.out" | ||
651 | fi | ||