aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-01-08 16:26:48 -0200
committerHisham Muhammad <hisham@gobolinux.org>2018-01-08 16:26:48 -0200
commitd80124af9cd929b395b4d4c353b51ccc902a3f9e (patch)
treea738a509039b286697819db762916cfda0384413 /spec
parent98a0bd9a97190be8ba10f14a3d67e42de827b04a (diff)
downloadluarocks-d80124af9cd929b395b4d4c353b51ccc902a3f9e.tar.gz
luarocks-d80124af9cd929b395b4d4c353b51ccc902a3f9e.tar.bz2
luarocks-d80124af9cd929b395b4d4c353b51ccc902a3f9e.zip
Reorganize test suite files
Diffstat (limited to 'spec')
-rw-r--r--spec/add_spec.lua4
-rw-r--r--spec/build_spec.lua12
-rw-r--r--spec/config_spec.lua2
-rw-r--r--spec/deps_spec.lua2
-rw-r--r--spec/doc_spec.lua2
-rw-r--r--spec/download_spec.lua2
-rw-r--r--spec/fetch_spec.lua2
-rw-r--r--spec/fixtures/a_rock-1.0-1.rockspec17
-rw-r--r--spec/fixtures/a_rock.lua1
-rw-r--r--spec/fixtures/invalid_patch-0.1-1.rockspec29
-rw-r--r--spec/fixtures/invalid_validate-args-1.5.4-1.rockspec35
-rw-r--r--spec/fixtures/luajit-fail-1.0-1.rockspec22
-rw-r--r--spec/fixtures/luajit-success-1.0-1.rockspec23
-rw-r--r--spec/fixtures/missing_external-0.1-1.rockspec24
-rw-r--r--spec/fixtures/mixed_deploy_type/mdt.c6
-rw-r--r--spec/fixtures/mixed_deploy_type/mdt.lua1
-rw-r--r--spec/fixtures/mixed_deploy_type/mdt_file1
-rw-r--r--spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec21
-rw-r--r--spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec21
-rw-r--r--spec/fixtures/no_build_table-0.1-1.rockspec12
-rw-r--r--spec/fixtures/not_a_zipfile-1.0-1.src.rock1
-rw-r--r--spec/fixtures/patch_create_delete-0.1-1.rockspec34
-rw-r--r--spec/fixtures/patch_create_delete/a_file.txt1
-rw-r--r--spec/fixtures/type_mismatch_string-1.0-1.rockspec4
-rw-r--r--spec/fixtures/type_mismatch_table-1.0-1.rockspec5
-rw-r--r--spec/fixtures/type_mismatch_version-1.0-1.rockspec4
-rw-r--r--spec/fixtures/with_external_dep-0.1-1.rockspec25
-rw-r--r--spec/fixtures/with_external_dep.c10
-rw-r--r--spec/fixtures/with_external_dep/foo/foo.h1
-rw-r--r--spec/fixtures/with_external_dep/foo/foo.h.gchbin0 -> 1503664 bytes
-rw-r--r--spec/fs_spec.lua2
-rw-r--r--spec/help_spec.lua2
-rw-r--r--spec/install_spec.lua6
-rw-r--r--spec/lint_spec.lua10
-rw-r--r--spec/list_spec.lua2
-rw-r--r--spec/make_manifest_spec.lua2
-rw-r--r--spec/make_spec.lua4
-rw-r--r--spec/new_version_spec.lua2
-rw-r--r--spec/pack_spec.lua4
-rw-r--r--spec/path_spec.lua2
-rw-r--r--spec/persist.lua2
-rw-r--r--spec/purge_spec.lua2
-rw-r--r--spec/refresh_cache_spec.lua2
-rw-r--r--spec/remove_spec.lua2
-rw-r--r--spec/search_spec.lua2
-rw-r--r--spec/show_spec.lua2
-rw-r--r--spec/unpack_spec.lua4
-rw-r--r--spec/upload_spec.lua6
-rw-r--r--spec/util/mock-server.lua97
-rw-r--r--spec/util/test_env.lua795
-rw-r--r--spec/util_spec.lua2
-rw-r--r--spec/write_rockspec_spec.lua26
52 files changed, 1246 insertions, 56 deletions
diff --git a/spec/add_spec.lua b/spec/add_spec.lua
index d42a97d0..1bc9e2a3 100644
--- a/spec/add_spec.lua
+++ b/spec/add_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3local testing_paths = test_env.testing_paths 3local testing_paths = test_env.testing_paths
4 4
@@ -34,7 +34,7 @@ describe("LuaRocks add tests #blackbox #b_add", function()
34 34
35 --TODO This test fails, sftp support not yet implemented 35 --TODO This test fails, sftp support not yet implemented
36 it("LuaRocks-admin add invalid server", function() 36 it("LuaRocks-admin add invalid server", function()
37 assert.is_false(run.luarocks_admin_bool("--server=testing add luasocket-3.0rc1-2.src.rock", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_sftp.lua" } )) 37 assert.is_false(run.luarocks_admin_bool("--server=testing add luasocket-3.0rc1-2.src.rock", { LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config_sftp.lua" } ))
38 end) 38 end)
39 39
40 it("LuaRocks-admin add, split server url", function() 40 it("LuaRocks-admin add, split server url", function()
diff --git a/spec/build_spec.lua b/spec/build_spec.lua
index 459a7292..2de05879 100644
--- a/spec/build_spec.lua
+++ b/spec/build_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
@@ -140,7 +140,7 @@ describe("LuaRocks build tests #blackbox #b_build", function()
140 describe("LuaRocks build - more complex tests", function() 140 describe("LuaRocks build - more complex tests", function()
141 if test_env.TYPE_TEST_ENV == "full" then 141 if test_env.TYPE_TEST_ENV == "full" then
142 it("LuaRocks build luacheck show downloads test_config", function() 142 it("LuaRocks build luacheck show downloads test_config", function()
143 local output = run.luarocks("build luacheck", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_show_downloads.lua"} ) 143 local output = run.luarocks("build luacheck", { LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config_show_downloads.lua"} )
144 assert.is.truthy(output:match("%.%.%.")) 144 assert.is.truthy(output:match("%.%.%."))
145 end) 145 end)
146 end 146 end
@@ -190,7 +190,7 @@ describe("LuaRocks build tests #blackbox #b_build", function()
190 end) 190 end)
191 191
192 it("LuaRocks build invalid patch", function() 192 it("LuaRocks build invalid patch", function()
193 assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) 193 assert.is_false(run.luarocks_bool("build " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec"))
194 end) 194 end)
195 end) 195 end)
196 196
@@ -204,12 +204,12 @@ describe("LuaRocks build tests #blackbox #b_build", function()
204 end) 204 end)
205 205
206 it("fails when missing external dependency", function() 206 it("fails when missing external dependency", function()
207 assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) 207 assert.is_false(run.luarocks_bool("build " .. testing_paths.fixtures_dir .. "/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\""))
208 end) 208 end)
209 209
210 it("builds with external dependency", function() 210 it("builds with external dependency", function()
211 local rockspec = testing_paths.testing_dir .. "/testfiles/with_external_dep-0.1-1.rockspec" 211 local rockspec = testing_paths.fixtures_dir .. "/with_external_dep-0.1-1.rockspec"
212 local foo_incdir = testing_paths.testing_dir .. "/testfiles/with_external_dep" 212 local foo_incdir = testing_paths.fixtures_dir .. "/with_external_dep"
213 assert.is_truthy(run.luarocks_bool("build " .. rockspec .. " FOO_INCDIR=\"" .. foo_incdir .. "\"")) 213 assert.is_truthy(run.luarocks_bool("build " .. rockspec .. " FOO_INCDIR=\"" .. foo_incdir .. "\""))
214 assert.is.truthy(run.luarocks("show with_external_dep")) 214 assert.is.truthy(run.luarocks("show with_external_dep"))
215 end) 215 end)
diff --git a/spec/config_spec.lua b/spec/config_spec.lua
index 6be586c2..fae68474 100644
--- a/spec/config_spec.lua
+++ b/spec/config_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua
index 8c4effcd..76ee68a7 100644
--- a/spec/deps_spec.lua
+++ b/spec/deps_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua
index ea42cd6b..5f503af2 100644
--- a/spec/doc_spec.lua
+++ b/spec/doc_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3local testing_paths = test_env.testing_paths 3local testing_paths = test_env.testing_paths
4 4
diff --git a/spec/download_spec.lua b/spec/download_spec.lua
index 320d9304..64443922 100644
--- a/spec/download_spec.lua
+++ b/spec/download_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4 4
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua
index ab2cd54e..59f73b57 100644
--- a/spec/fetch_spec.lua
+++ b/spec/fetch_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2 2
3test_env.unload_luarocks() 3test_env.unload_luarocks()
4local fetch = require("luarocks.fetch") 4local fetch = require("luarocks.fetch")
diff --git a/spec/fixtures/a_rock-1.0-1.rockspec b/spec/fixtures/a_rock-1.0-1.rockspec
new file mode 100644
index 00000000..9f15e87a
--- /dev/null
+++ b/spec/fixtures/a_rock-1.0-1.rockspec
@@ -0,0 +1,17 @@
1package = "a_rock"
2version = "1.0-1"
3source = {
4 url = "http://localhost:8080/file/a_rock.lua"
5}
6description = {
7 summary = "An example rockspec",
8}
9dependencies = {
10 "lua >= 5.1"
11}
12build = {
13 type = "builtin",
14 modules = {
15 build = "a_rock.lua"
16 },
17}
diff --git a/spec/fixtures/a_rock.lua b/spec/fixtures/a_rock.lua
new file mode 100644
index 00000000..a5647075
--- /dev/null
+++ b/spec/fixtures/a_rock.lua
@@ -0,0 +1 @@
return {}
diff --git a/spec/fixtures/invalid_patch-0.1-1.rockspec b/spec/fixtures/invalid_patch-0.1-1.rockspec
new file mode 100644
index 00000000..c2ecd160
--- /dev/null
+++ b/spec/fixtures/invalid_patch-0.1-1.rockspec
@@ -0,0 +1,29 @@
1package = "invalid_patch"
2version = "0.1-1"
3source = {
4 -- any valid URL
5 url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua"
6}
7description = {
8 summary = "A rockspec with an invalid patch",
9}
10dependencies = {
11 "lua >= 5.1"
12}
13build = {
14 type = "builtin",
15 modules = {
16 build = "build.lua"
17 },
18 patches = {
19 ["I_am_an_invalid_patch.patch"] =
20[[
21diff -Naur luadoc-3.0.1/src/luadoc/doclet/html.lua luadoc-3.0.1-new/src/luadoc/doclet/html.lua
22--- luadoc-3.0.1/src/luadoc/doclet/html.lua2007-12-21 15:50:48.000000000 -0200
23+++ luadoc-3.0.1-new/src/luadoc/doclet/html.lua2008-02-28 01:59:53.000000000 -0300
24@@ -18,6 +18,7 @@
25- gabba gabba gabba
26+ gobo gobo gobo
27]]
28 }
29}
diff --git a/spec/fixtures/invalid_validate-args-1.5.4-1.rockspec b/spec/fixtures/invalid_validate-args-1.5.4-1.rockspec
new file mode 100644
index 00000000..0b4d807d
--- /dev/null
+++ b/spec/fixtures/invalid_validate-args-1.5.4-1.rockspec
@@ -0,0 +1,35 @@
1package = 'validate-args'
2version = '1.5.4-1'
3source = {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{++{
4 url = "https://bitbucket.org/djerius/validate.args/downloads/validate-args-1.5.4.tar.gz"
5}
6
7description = {
8 summary = "Function argument validation",
9 detailed = [[
10 validate.args is a Lua module that provides a framework for
11 validation of arguments to Lua functions as well as complex data
12 structures. The included validate.inplace module provides "live"
13 validation during assignment of values to elements in tables. ]],
14 license = "GPL-3",
15
16}
17
18dependencies = {
19 "lua >= 5.1"
20}
21
22build = {
23
24 type = "builtin",
25
26 modules = {
27 ["validate.args"] = "validate/args.lua",
28 ["validate.inplace"] = "validate/inplace.lua",
29 },
30
31 copy_directories = {
32 "doc", "tests"
33 }
34
35}
diff --git a/spec/fixtures/luajit-fail-1.0-1.rockspec b/spec/fixtures/luajit-fail-1.0-1.rockspec
new file mode 100644
index 00000000..f8204600
--- /dev/null
+++ b/spec/fixtures/luajit-fail-1.0-1.rockspec
@@ -0,0 +1,22 @@
1package = "luajit-fail"
2version = "1.0-1"
3source = {
4 url = "https://raw.githubusercontent.com/keplerproject/luarocks/master/test/testing.lua",
5}
6description = {
7 summary = "Test luajit dependency fail",
8 detailed = [[
9Fail luajit dependency when running with rockspec_format < 3.0.
10]],
11 homepage = "http://luarocks.org/",
12 license = "MIT/X license"
13}
14dependencies = {
15 "luajit >= 2.0"
16}
17build = {
18 type = "builtin",
19 modules = {
20 testing = "testing.lua"
21 }
22}
diff --git a/spec/fixtures/luajit-success-1.0-1.rockspec b/spec/fixtures/luajit-success-1.0-1.rockspec
new file mode 100644
index 00000000..31c930c3
--- /dev/null
+++ b/spec/fixtures/luajit-success-1.0-1.rockspec
@@ -0,0 +1,23 @@
1rockspec_format = "3.0"
2package = "luajit-success"
3version = "1.0-1"
4source = {
5 url = "https://raw.githubusercontent.com/keplerproject/luarocks/master/test/testing.lua",
6}
7description = {
8 summary = "Test luajit dependency fail",
9 detailed = [[
10Use luajit dependency when running with rockspec_format >= 3.0.
11]],
12 homepage = "http://luarocks.org/",
13 license = "MIT/X license"
14}
15dependencies = {
16 "luajit >= 2.0"
17}
18build = {
19 type = "builtin",
20 modules = {
21 testing = "testing.lua"
22 }
23}
diff --git a/spec/fixtures/missing_external-0.1-1.rockspec b/spec/fixtures/missing_external-0.1-1.rockspec
new file mode 100644
index 00000000..5f8e6219
--- /dev/null
+++ b/spec/fixtures/missing_external-0.1-1.rockspec
@@ -0,0 +1,24 @@
1package = "missing_external"
2version = "0.1-1"
3source = {
4 -- any valid URL
5 url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua"
6}
7description = {
8 summary = "Missing external dependency",
9}
10external_dependencies = {
11 INEXISTENT = {
12 library = "inexistentlib*",
13 header = "inexistentheader*.h",
14 }
15}
16dependencies = {
17 "lua >= 5.1"
18}
19build = {
20 type = "builtin",
21 modules = {
22 build = "build.lua"
23 }
24}
diff --git a/spec/fixtures/mixed_deploy_type/mdt.c b/spec/fixtures/mixed_deploy_type/mdt.c
new file mode 100644
index 00000000..a162ce23
--- /dev/null
+++ b/spec/fixtures/mixed_deploy_type/mdt.c
@@ -0,0 +1,6 @@
1#include "lua.h"
2
3int luaopen_mdt(lua_State *L) {
4 lua_pushstring(L, "mdt.c");
5 return 1;
6}
diff --git a/spec/fixtures/mixed_deploy_type/mdt.lua b/spec/fixtures/mixed_deploy_type/mdt.lua
new file mode 100644
index 00000000..c9ca9c68
--- /dev/null
+++ b/spec/fixtures/mixed_deploy_type/mdt.lua
@@ -0,0 +1 @@
return "mdt.lua"
diff --git a/spec/fixtures/mixed_deploy_type/mdt_file b/spec/fixtures/mixed_deploy_type/mdt_file
new file mode 100644
index 00000000..1a15f7d7
--- /dev/null
+++ b/spec/fixtures/mixed_deploy_type/mdt_file
@@ -0,0 +1 @@
return "mdt_file"
diff --git a/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec b/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec
new file mode 100644
index 00000000..91b725da
--- /dev/null
+++ b/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.1.0-1.rockspec
@@ -0,0 +1,21 @@
1package = "mixed_deploy_type"
2version = "0.1.0-1"
3source = {
4 url = "http://example.com"
5}
6description = {
7 homepage = "http://example.com",
8 license = "*** please specify a license ***"
9}
10dependencies = {}
11build = {
12 type = "builtin",
13 modules = {
14 mdt = "mdt/mdt.lua"
15 },
16 install = {
17 lua = {
18 mdt_file = "mdt/mdt_file"
19 }
20 }
21}
diff --git a/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec b/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec
new file mode 100644
index 00000000..9ca03180
--- /dev/null
+++ b/spec/fixtures/mixed_deploy_type/mixed_deploy_type-0.2.0-1.rockspec
@@ -0,0 +1,21 @@
1package = "mixed_deploy_type"
2version = "0.2.0-1"
3source = {
4 url = "http://example.com"
5}
6description = {
7 homepage = "http://example.com",
8 license = "*** please specify a license ***"
9}
10dependencies = {}
11build = {
12 type = "builtin",
13 modules = {
14 mdt = "mdt/mdt.c"
15 },
16 install = {
17 lib = {
18 mdt_file = "mdt/mdt_file"
19 }
20 }
21}
diff --git a/spec/fixtures/no_build_table-0.1-1.rockspec b/spec/fixtures/no_build_table-0.1-1.rockspec
new file mode 100644
index 00000000..5d79e9a0
--- /dev/null
+++ b/spec/fixtures/no_build_table-0.1-1.rockspec
@@ -0,0 +1,12 @@
1package = "no_build_table"
2version = "0.1-1"
3source = {
4 -- any valid URL
5 url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua"
6}
7description = {
8 summary = "A rockspec with no build field",
9}
10dependencies = {
11 "lua >= 5.1"
12}
diff --git a/spec/fixtures/not_a_zipfile-1.0-1.src.rock b/spec/fixtures/not_a_zipfile-1.0-1.src.rock
new file mode 100644
index 00000000..e36f8bbe
--- /dev/null
+++ b/spec/fixtures/not_a_zipfile-1.0-1.src.rock
@@ -0,0 +1 @@
I am not a .zip file!
diff --git a/spec/fixtures/patch_create_delete-0.1-1.rockspec b/spec/fixtures/patch_create_delete-0.1-1.rockspec
new file mode 100644
index 00000000..3d55da58
--- /dev/null
+++ b/spec/fixtures/patch_create_delete-0.1-1.rockspec
@@ -0,0 +1,34 @@
1rockspec_format = "3.0"
2package = "patch_create_delete"
3version = "0.1-1"
4source = {
5 -- any valid URL
6 url = "git://github.com/luarocks/luarocks"
7}
8description = {
9 summary = "A rockspec with a patch that creates and deletes files",
10}
11dependencies = {
12 "lua >= 5.1"
13}
14build = {
15 type = "builtin",
16 modules = {
17 ["luarocks.loader"] = "src/luarocks/loader.lua"
18 },
19 patches = {
20 ["create_delete.patch"] =
21[[
22diff -Naur luarocks/spec/fixtures/patch_create_delete/a_file.txt luarocks-patch/spec/fixtures/patch_create_delete/a_file.txt
23--- luarocks/spec/fixtures/patch_create_delete/a_file.txt 2017-10-04 15:39:44.179306674 -0300
24+++ luarocks-patch/spec/fixtures/patch_create_delete/a_file.txt 1969-12-31 21:00:00.000000000 -0300
25@@ -1 +0,0 @@
26-I am a file.
27diff -Naur luarocks/spec/fixtures/patch_create_delete/another_file.txt luarocks-patch/spec/fixtures/patch_create_delete/another_file.txt
28--- luarocks/spec/fixtures/patch_create_delete/another_file.txt 1969-12-31 21:00:00.000000000 -0300
29+++ luarocks-patch/spec/fixtures/patch_create_delete/another_file.txt 2017-10-04 15:40:12.836306564 -0300
30@@ -0,0 +1 @@
31+I am another file.
32]]
33 }
34}
diff --git a/spec/fixtures/patch_create_delete/a_file.txt b/spec/fixtures/patch_create_delete/a_file.txt
new file mode 100644
index 00000000..6539c24e
--- /dev/null
+++ b/spec/fixtures/patch_create_delete/a_file.txt
@@ -0,0 +1 @@
I am a file.
diff --git a/spec/fixtures/type_mismatch_string-1.0-1.rockspec b/spec/fixtures/type_mismatch_string-1.0-1.rockspec
new file mode 100644
index 00000000..7a607cfd
--- /dev/null
+++ b/spec/fixtures/type_mismatch_string-1.0-1.rockspec
@@ -0,0 +1,4 @@
1
2package="type_mismatch_version"
3version=1.0
4
diff --git a/spec/fixtures/type_mismatch_table-1.0-1.rockspec b/spec/fixtures/type_mismatch_table-1.0-1.rockspec
new file mode 100644
index 00000000..f348b798
--- /dev/null
+++ b/spec/fixtures/type_mismatch_table-1.0-1.rockspec
@@ -0,0 +1,5 @@
1
2package="type_mismatch_table"
3version="1.0-1"
4
5source = "not a table"
diff --git a/spec/fixtures/type_mismatch_version-1.0-1.rockspec b/spec/fixtures/type_mismatch_version-1.0-1.rockspec
new file mode 100644
index 00000000..5e30dae6
--- /dev/null
+++ b/spec/fixtures/type_mismatch_version-1.0-1.rockspec
@@ -0,0 +1,4 @@
1
2package="type_mismatch_version"
3version="1.0"
4
diff --git a/spec/fixtures/with_external_dep-0.1-1.rockspec b/spec/fixtures/with_external_dep-0.1-1.rockspec
new file mode 100644
index 00000000..45fea4bd
--- /dev/null
+++ b/spec/fixtures/with_external_dep-0.1-1.rockspec
@@ -0,0 +1,25 @@
1package = "with_external_dep"
2version = "0.1-1"
3source = {
4 url = "http://localhost:8080/file/with_external_dep.c"
5}
6description = {
7 summary = "An example rockspec",
8}
9external_dependencies = {
10 FOO = {
11 header = "foo/foo.h"
12 }
13}
14dependencies = {
15 "lua >= 5.1"
16}
17build = {
18 type = "builtin",
19 modules = {
20 with_external_dep = {
21 sources = "with_external_dep.c",
22 incdirs = "$(FOO_INCDIR)",
23 }
24 }
25}
diff --git a/spec/fixtures/with_external_dep.c b/spec/fixtures/with_external_dep.c
new file mode 100644
index 00000000..16435d8f
--- /dev/null
+++ b/spec/fixtures/with_external_dep.c
@@ -0,0 +1,10 @@
1#include <foo/foo.h>
2#include <lua.h>
3#include <lauxlib.h>
4
5int luaopen_with_external_dep(lua_State* L) {
6 lua_newtable(L);
7 lua_pushinteger(L, FOO);
8 lua_setfield(L, -2, "foo");
9 return 1;
10}
diff --git a/spec/fixtures/with_external_dep/foo/foo.h b/spec/fixtures/with_external_dep/foo/foo.h
new file mode 100644
index 00000000..eedd558f
--- /dev/null
+++ b/spec/fixtures/with_external_dep/foo/foo.h
@@ -0,0 +1 @@
#define FOO 42
diff --git a/spec/fixtures/with_external_dep/foo/foo.h.gch b/spec/fixtures/with_external_dep/foo/foo.h.gch
new file mode 100644
index 00000000..66165c9e
--- /dev/null
+++ b/spec/fixtures/with_external_dep/foo/foo.h.gch
Binary files differ
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua
index c76f47a4..17ac90ab 100644
--- a/spec/fs_spec.lua
+++ b/spec/fs_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2 2
3test_env.unload_luarocks() 3test_env.unload_luarocks()
4local fs = require("luarocks.fs") 4local fs = require("luarocks.fs")
diff --git a/spec/help_spec.lua b/spec/help_spec.lua
index 71b1b9f6..f7bb79b3 100644
--- a/spec/help_spec.lua
+++ b/spec/help_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
diff --git a/spec/install_spec.lua b/spec/install_spec.lua
index 92b780d3..d72d88ba 100644
--- a/spec/install_spec.lua
+++ b/spec/install_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
@@ -43,7 +43,7 @@ describe("LuaRocks install tests #blackbox #b_install", function()
43 end) 43 end)
44 44
45 it("LuaRocks install invalid patch", function() 45 it("LuaRocks install invalid patch", function()
46 assert.is_false(run.luarocks_bool("install " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) 46 assert.is_false(run.luarocks_bool("install " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec"))
47 end) 47 end)
48 48
49 it("LuaRocks install invalid rock", function() 49 it("LuaRocks install invalid rock", function()
@@ -55,7 +55,7 @@ describe("LuaRocks install tests #blackbox #b_install", function()
55 end) 55 end)
56 56
57 it("LuaRocks install not a zip file", function() 57 it("LuaRocks install not a zip file", function()
58 assert.is_false(run.luarocks_bool("install " .. testing_paths.testing_dir .. "/testfiles/not_a_zipfile-1.0-1.src.rock")) 58 assert.is_false(run.luarocks_bool("install " .. testing_paths.fixtures_dir .. "/not_a_zipfile-1.0-1.src.rock"))
59 end) 59 end)
60 60
61 it("LuaRocks install only-deps of lxsh show there is no lxsh", function() 61 it("LuaRocks install only-deps of lxsh show there is no lxsh", function()
diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua
index f7496037..1c082b2a 100644
--- a/spec/lint_spec.lua
+++ b/spec/lint_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3local testing_paths = test_env.testing_paths 3local testing_paths = test_env.testing_paths
4 4
@@ -31,19 +31,19 @@ describe("LuaRocks lint tests #blackbox #b_lint", function()
31 31
32 describe("LuaRocks lint mismatch set", function() 32 describe("LuaRocks lint mismatch set", function()
33 it("LuaRocks lint mismatch string", 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")) 34 assert.is_false(run.luarocks_bool("lint " .. testing_paths.fixtures_dir .. "/type_mismatch_string-1.0-1.rockspec"))
35 end) 35 end)
36 36
37 it("LuaRocks lint mismatch version", function() 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")) 38 assert.is_false(run.luarocks_bool("lint " .. testing_paths.fixtures_dir .. "/type_mismatch_version-1.0-1.rockspec"))
39 end) 39 end)
40 40
41 it("LuaRocks lint mismatch table", function() 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")) 42 assert.is_false(run.luarocks_bool("lint " .. testing_paths.fixtures_dir .. "/type_mismatch_table-1.0-1.rockspec"))
43 end) 43 end)
44 44
45 it("LuaRocks lint mismatch no build table", function() 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")) 46 assert.is_false(run.luarocks_bool("lint " .. testing_paths.fixtures_dir .. "/no_build_table-1.0-1.rockspec"))
47 end) 47 end)
48 end) 48 end)
49end) 49end)
diff --git a/spec/list_spec.lua b/spec/list_spec.lua
index b9a8e4c4..9f221b90 100644
--- a/spec/list_spec.lua
+++ b/spec/list_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3local testing_paths = test_env.testing_paths 3local testing_paths = test_env.testing_paths
4 4
diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua
index 3e998cbf..2b109fa7 100644
--- a/spec/make_manifest_spec.lua
+++ b/spec/make_manifest_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
diff --git a/spec/make_spec.lua b/spec/make_spec.lua
index 4c406c68..88b35b22 100644
--- a/spec/make_spec.lua
+++ b/spec/make_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
@@ -102,7 +102,7 @@ describe("LuaRocks make tests #blackbox #b_make", function()
102 102
103 describe("LuaRocks make upgrading rockspecs with mixed deploy types", function() 103 describe("LuaRocks make upgrading rockspecs with mixed deploy types", function()
104 before_each(function() 104 before_each(function()
105 test_env.copy_dir(testing_paths.testing_dir .. "/testfiles/mixed_deploy_type", "mdt") 105 test_env.copy_dir(testing_paths.fixtures_dir .. "/mixed_deploy_type", "mdt")
106 end) 106 end)
107 107
108 after_each(function() 108 after_each(function()
diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua
index 2f67141d..65f60dd6 100644
--- a/spec/new_version_spec.lua
+++ b/spec/new_version_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua
index 0c6dd8f2..966195c5 100644
--- a/spec/pack_spec.lua
+++ b/spec/pack_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
@@ -30,7 +30,7 @@ describe("LuaRocks pack tests #blackbox #b_pack", function()
30 end) 30 end)
31 31
32 it("LuaRocks pack invalid rockspec", function() 32 it("LuaRocks pack invalid rockspec", function()
33 assert.is_false(run.luarocks_bool("pack " .. testing_paths.testing_dir .. "/testfiles/invaild_validate-args-1.5.4-1.rockspec")) 33 assert.is_false(run.luarocks_bool("pack " .. testing_paths.fixtures_dir .. "/invaild_validate-args-1.5.4-1.rockspec"))
34 end) 34 end)
35 35
36 it("LuaRocks pack not installed rock", function() 36 it("LuaRocks pack not installed rock", function()
diff --git a/spec/path_spec.lua b/spec/path_spec.lua
index 536233b1..bbc0cfc8 100644
--- a/spec/path_spec.lua
+++ b/spec/path_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
diff --git a/spec/persist.lua b/spec/persist.lua
index 6b69dab4..00a9b75d 100644
--- a/spec/persist.lua
+++ b/spec/persist.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2 2
3test_env.unload_luarocks() 3test_env.unload_luarocks()
4local persist = require("luarocks.persist") 4local persist = require("luarocks.persist")
diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua
index 20cee5f0..79ad0dfd 100644
--- a/spec/purge_spec.lua
+++ b/spec/purge_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3local testing_paths = test_env.testing_paths 3local testing_paths = test_env.testing_paths
4 4
diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua
index 09f5645e..51c1572f 100644
--- a/spec/refresh_cache_spec.lua
+++ b/spec/refresh_cache_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua
index 4d3f5cdc..c0e9beb0 100644
--- a/spec/remove_spec.lua
+++ b/spec/remove_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
diff --git a/spec/search_spec.lua b/spec/search_spec.lua
index 04f84eeb..952458dd 100644
--- a/spec/search_spec.lua
+++ b/spec/search_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
diff --git a/spec/show_spec.lua b/spec/show_spec.lua
index 0b046de0..d572be9b 100644
--- a/spec/show_spec.lua
+++ b/spec/show_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua
index d629e225..fc02d853 100644
--- a/spec/unpack_spec.lua
+++ b/spec/unpack_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3local testing_paths = test_env.testing_paths 3local testing_paths = test_env.testing_paths
4 4
@@ -26,7 +26,7 @@ describe("LuaRocks unpack tests #blackbox #b_unpack", function()
26 end) 26 end)
27 27
28 it("LuaRocks unpack with invalid patch", function() 28 it("LuaRocks unpack with invalid patch", function()
29 assert.is_false(run.luarocks_bool("unpack " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) 29 assert.is_false(run.luarocks_bool("unpack " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec"))
30 end) 30 end)
31 end) 31 end)
32 32
diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua
index b8e147e0..3adfa2dd 100644
--- a/spec/upload_spec.lua
+++ b/spec/upload_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3local testing_paths = test_env.testing_paths 3local testing_paths = test_env.testing_paths
4 4
@@ -39,10 +39,10 @@ describe("LuaRocks upload tests #blackbox #b_upload", function()
39 after_each(test_env.mock_server_done) 39 after_each(test_env.mock_server_done)
40 40
41 it("LuaRocks upload rockspec with api-key", function() 41 it("LuaRocks upload rockspec with api-key", function()
42 assert.is_true(run.luarocks_bool("upload " .. testing_paths.testing_dir .. "/testfiles/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) 42 assert.is_true(run.luarocks_bool("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"}))
43 end) 43 end)
44 it("LuaRocks upload rockspec with api-key and skip-pack", function() 44 it("LuaRocks upload rockspec with api-key and skip-pack", function()
45 assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.testing_dir .. "/testfiles/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) 45 assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"}))
46 end) 46 end)
47 end) 47 end)
48end) 48end)
diff --git a/spec/util/mock-server.lua b/spec/util/mock-server.lua
new file mode 100644
index 00000000..244aceae
--- /dev/null
+++ b/spec/util/mock-server.lua
@@ -0,0 +1,97 @@
1#!/usr/bin/env lua
2
3--- A simple LuaRocks mock-server for testing.
4local restserver = require("restserver")
5local server = restserver:new():port(8080)
6
7server:add_resource("api/tool_version", {
8 {
9 method = "GET",
10 path = "/",
11 produces = "application/json",
12 handler = function(query)
13 local json = { version = query.current }
14 return restserver.response():status(200):entity(json)
15 end
16 }
17})
18
19server:add_resource("api/1/{id:[0-9]+}/status", {
20 {
21 method = "GET",
22 path = "/",
23 produces = "application/json",
24 handler = function(query)
25 local json = { user_id = "123", created_at = "29.1.1993" }
26 return restserver.response():status(200):entity(json)
27 end
28 }
29})
30
31server:add_resource("/api/1/{id:[0-9]+}/check_rockspec", {
32 {
33 method = "GET",
34 path = "/",
35 produces = "application/json",
36 handler = function(query)
37 local json = {}
38 return restserver.response():status(200):entity(json)
39 end
40 }
41})
42
43server:add_resource("/api/1/{id:[0-9]+}/upload", {
44 {
45 method = "POST",
46 path = "/",
47 produces = "application/json",
48 handler = function(query)
49 local json = {module = "luasocket", version = {id = "1.0"}, module_url = "http://localhost/luasocket", manifests = "root", is_new = "is_new"}
50 return restserver.response():status(200):entity(json)
51 end
52 }
53})
54
55server:add_resource("/api/1/{id:[0-9]+}/upload_rock/{id:[0-9]+}", {
56 {
57 method = "POST",
58 path = "/",
59 produces = "application/json",
60 handler = function(query)
61 local json = {"rock","module_url"}
62 return restserver.response():status(200):entity(json)
63 end
64 }
65})
66
67server:add_resource("/file/{name:[^/]+}", {
68 {
69 method = "GET",
70 path = "/",
71 produces = "text/plain",
72 handler = function(query, name)
73 local fd = io.open("spec/fixtures/"..name, "r")
74 if not fd then
75 return restserver.response():status(404)
76 end
77 local data = fd:read("*a")
78 fd:close()
79 return restserver.response():status(200):entity(data)
80 end
81 }
82})
83
84-- SHUTDOWN this mock-server
85server:add_resource("/shutdown", {
86 {
87 method = "GET",
88 path = "/",
89 handler = function(query)
90 os.exit()
91 return restserver.response():status(200):entity()
92 end
93 }
94})
95
96-- This loads the restserver.xavante plugin
97server:enable("restserver.xavante"):start() \ No newline at end of file
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua
new file mode 100644
index 00000000..9d9ae843
--- /dev/null
+++ b/spec/util/test_env.lua
@@ -0,0 +1,795 @@
1local lfs = require("lfs")
2local test_env = {}
3
4local help_message = [[
5LuaRocks test-suite
6
7INFORMATION
8 New test-suite for LuaRocks project, using unit testing framework Busted.
9REQUIREMENTS
10 Be sure sshd is running on your system, or use '--exclude-tags=ssh',
11 to not execute tests which require sshd.
12USAGE
13 busted [-Xhelper <arguments>]
14ARGUMENTS
15 env=<type> Set type of environment to use ("minimal" or "full",
16 default: "minimal").
17 noreset Don't reset environment after each test
18 clean Remove existing testing environment.
19 travis Add if running on TravisCI.
20 appveyor Add if running on Appveyor.
21 os=<type> Set OS ("linux", "osx", or "windows").
22 lua_dir=<path> Path of Lua installation (default "/usr/local")
23 lua_interpreter=<lua> Name of the interpreter (default "lua")
24]]
25
26local function help()
27 print(help_message)
28 os.exit(1)
29end
30
31local function title(str)
32 print()
33 print(("-"):rep(#str))
34 print(str)
35 print(("-"):rep(#str))
36end
37
38function test_env.exists(path)
39 return lfs.attributes(path, "mode") ~= nil
40end
41
42--- Quote argument for shell processing. Fixes paths on Windows.
43-- Adds double quotes and escapes. Based on function in fs/win32.lua.
44-- @param arg string: Unquoted argument.
45-- @return string: Quoted argument.
46local function Q(arg)
47 if test_env.TEST_TARGET_OS == "windows" then
48 local drive_letter = "[%.a-zA-Z]?:?[\\/]"
49 -- Quote DIR for Windows
50 if arg:match("^"..drive_letter) then
51 arg = arg:gsub("/", "\\")
52 end
53
54 if arg == "\\" then
55 return '\\' -- CHDIR needs special handling for root dir
56 end
57
58 return '"' .. arg .. '"'
59 else
60 return "'" .. arg:gsub("'", "'\\''") .. "'"
61 end
62end
63
64function test_env.quiet(command)
65 if not test_env.VERBOSE then
66 if test_env.TEST_TARGET_OS == "windows" then
67 return command .. " 1> NUL 2> NUL"
68 else
69 return command .. " 1> /dev/null 2> /dev/null"
70 end
71 else
72 return command
73 end
74end
75
76function test_env.copy(source, destination)
77 local r_source, err = io.open(source, "r")
78 local r_destination, err = io.open(destination, "w")
79
80 while true do
81 local block = r_source:read(8192)
82 if not block then break end
83 r_destination:write(block)
84 end
85
86 r_source:close()
87 r_destination:close()
88end
89
90--- Helper function for execute_bool and execute_output
91-- @param command string: command to execute
92-- @param print_command boolean: print command if 'true'
93-- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"}
94-- @return final_command string: concatenated command to execution
95function test_env.execute_helper(command, print_command, env_variables)
96 local final_command = ""
97
98 if print_command then
99 print("[EXECUTING]: " .. command)
100 end
101
102 if env_variables then
103 if test_env.TEST_TARGET_OS == "windows" then
104 for k,v in pairs(env_variables) do
105 final_command = final_command .. "set " .. k .. "=" .. v .. "&"
106 end
107 final_command = final_command:sub(1, -2) .. "&"
108 else
109 final_command = "export "
110 for k,v in pairs(env_variables) do
111 final_command = final_command .. k .. "='" .. v .. "' "
112 end
113 -- remove last space and add ';' to separate exporting variables from command
114 final_command = final_command:sub(1, -2) .. "; "
115 end
116 end
117
118 final_command = final_command .. command .. " 2>&1"
119
120 return final_command
121end
122
123--- Execute command and returns true/false
124-- @return true/false boolean: status of the command execution
125local function execute_bool(command, print_command, env_variables)
126 command = test_env.execute_helper(command, print_command, env_variables)
127
128 local redirect_filename
129 local redirect = ""
130 if print_command ~= nil then
131 redirect_filename = test_env.testing_paths.luarocks_tmp.."/output.txt"
132 redirect = " > "..redirect_filename
133 os.remove(redirect_filename)
134 end
135 local ok = os.execute(command .. redirect)
136 ok = (ok == true or ok == 0) -- normalize Lua 5.1 output to boolean
137 if redirect ~= "" then
138 if not ok then
139 local fd = io.open(redirect_filename, "r")
140 if fd then
141 print(fd:read("*a"))
142 fd:close()
143 end
144 end
145 os.remove(redirect_filename)
146 end
147 return ok
148end
149
150--- Execute command and returns output of command
151-- @return output string: output the command execution
152local function execute_output(command, print_command, env_variables)
153 command = test_env.execute_helper(command, print_command, env_variables)
154
155 local file = assert(io.popen(command))
156 local output = file:read('*all')
157 file:close()
158 return output:gsub("\n","") -- output adding new line, need to be removed
159end
160
161--- Set test_env.LUA_V or test_env.LUAJIT_V based
162-- on version of Lua used to run this script.
163function test_env.set_lua_version()
164 if _G.jit then
165 test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d")
166 test_env.lua_version = "5.1"
167 else
168 test_env.LUA_V = _VERSION:match("5%.%d")
169 test_env.lua_version = test_env.LUA_V
170 end
171end
172
173--- Set all arguments from input into global variables
174function test_env.set_args()
175 -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables
176 test_env.TYPE_TEST_ENV = "minimal"
177 test_env.OPENSSL_DIRS = ""
178 test_env.RESET_ENV = true
179
180 for _, argument in ipairs(arg) do
181 if argument:find("^env=") then
182 test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$")
183 elseif argument == "noreset" then
184 test_env.RESET_ENV = false
185 elseif argument == "clean" then
186 test_env.TEST_ENV_CLEAN = true
187 elseif argument == "verbose" then
188 test_env.VERBOSE = true
189 elseif argument == "travis" then
190 test_env.TRAVIS = true
191 elseif argument == "appveyor" then
192 test_env.APPVEYOR = true
193 test_env.OPENSSL_DIRS = "OPENSSL_LIBDIR=C:\\OpenSSL-Win32\\lib OPENSSL_INCDIR=C:\\OpenSSL-Win32\\include"
194 elseif argument:find("^os=") then
195 test_env.TEST_TARGET_OS = argument:match("^os=(.*)$")
196 elseif argument == "mingw" then
197 test_env.MINGW = true
198 elseif argument == "vs" then
199 test_env.MINGW = false
200 elseif argument:find("^lua_dir=") then
201 test_env.LUA_DIR = argument:match("^lua_dir=(.*)$")
202 elseif argument:find("^lua_interpreter=") then
203 test_env.LUA_INTERPRETER = argument:match("^lua_interpreter=(.*)$")
204 else
205 help()
206 end
207 end
208
209 if not test_env.TEST_TARGET_OS then
210 title("OS CHECK")
211
212 if execute_bool("sw_vers") then
213 test_env.TEST_TARGET_OS = "osx"
214 if test_env.TRAVIS then
215 test_env.OPENSSL_DIRS = "OPENSSL_LIBDIR=/usr/local/opt/openssl/lib OPENSSL_INCDIR=/usr/local/opt/openssl/include"
216 end
217 elseif execute_output("uname -s") == "Linux" then
218 test_env.TEST_TARGET_OS = "linux"
219 else
220 test_env.TEST_TARGET_OS = "windows"
221 end
222 end
223 return true
224end
225
226function test_env.copy_dir(source_path, target_path)
227 local testing_paths = test_env.testing_paths
228 if test_env.TEST_TARGET_OS == "windows" then
229 execute_bool(testing_paths.win_tools .. "/cp -R ".. source_path .. "/. " .. target_path)
230 else
231 execute_bool("cp -a ".. source_path .. "/. " .. target_path)
232 end
233end
234
235--- Remove directory recursively
236-- @param path string: directory path to delete
237function test_env.remove_dir(path)
238 if test_env.exists(path) then
239 for file in lfs.dir(path) do
240 if file ~= "." and file ~= ".." then
241 local full_path = path..'/'..file
242
243 if lfs.attributes(full_path, "mode") == "directory" then
244 test_env.remove_dir(full_path)
245 else
246 os.remove(full_path)
247 end
248 end
249 end
250 end
251 lfs.rmdir(path)
252end
253
254--- Remove subdirectories of a directory that match a pattern
255-- @param path string: path to directory
256-- @param pattern string: pattern matching basenames of subdirectories to be removed
257function test_env.remove_subdirs(path, pattern)
258 if test_env.exists(path) then
259 for file in lfs.dir(path) do
260 if file ~= "." and file ~= ".." then
261 local full_path = path..'/'..file
262
263 if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then
264 test_env.remove_dir(full_path)
265 end
266 end
267 end
268 end
269end
270
271--- Remove files matching a pattern
272-- @param path string: directory where to delete files
273-- @param pattern string: pattern matching basenames of files to be deleted
274-- @return result_check boolean: true if one or more files deleted
275function test_env.remove_files(path, pattern)
276 local result_check = false
277 if test_env.exists(path) then
278 for file in lfs.dir(path) do
279 if file ~= "." and file ~= ".." then
280 if file:find(pattern) then
281 if os.remove(path .. "/" .. file) then
282 result_check = true
283 end
284 end
285 end
286 end
287 end
288 return result_check
289end
290
291
292--- Function for downloading rocks and rockspecs
293-- @param urls table: array of full names of rocks/rockspecs to download
294-- @param save_path string: path to directory, where to download rocks/rockspecs
295-- @return make_manifest boolean: true if new rocks downloaded
296local function download_rocks(urls, save_path)
297 local luarocks_repo = "https://luarocks.org"
298 local make_manifest = false
299
300 for _, url in ipairs(urls) do
301 -- check if already downloaded
302 if not test_env.exists(save_path .. url) then
303 if test_env.TEST_TARGET_OS == "windows" then
304 execute_bool(test_env.testing_paths.win_tools .. "/wget -cP " .. save_path .. " " .. luarocks_repo .. url .. " --no-check-certificate")
305 else
306 execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url)
307 end
308 make_manifest = true
309 end
310 end
311 return make_manifest
312end
313
314--- Create a file containing a string.
315-- @param path string: path to file.
316-- @param str string: content of the file.
317local function write_file(path, str)
318 local file = assert(io.open(path, "w"))
319 file:write(str)
320 file:close()
321end
322
323--- Create md5sum of directory structure recursively, based on filename and size
324-- @param path string: path to directory for generate md5sum
325-- @return md5sum string: md5sum of directory
326local function hash_environment(path)
327 if test_env.TEST_TARGET_OS == "linux" then
328 return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum")
329 elseif test_env.TEST_TARGET_OS == "osx" then
330 return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5")
331 elseif test_env.TEST_TARGET_OS == "windows" then
332 return execute_output("\"" .. Q(test_env.testing_paths.win_tools .. "/find") .. " " .. Q(path)
333 .. " -printf \"%s %p\"\" > temp_sum.txt && certUtil -hashfile temp_sum.txt && del temp_sum.txt")
334 end
335end
336
337--- Create environment variables needed for tests
338-- @param testing_paths table: table with paths to testing directory
339-- @return env_variables table: table with created environment variables
340local function create_env(testing_paths)
341 local luaversion_short = _VERSION:gsub("Lua ", "")
342
343 if test_env.LUAJIT_V then
344 luaversion_short="5.1"
345 end
346
347 local env_variables = {}
348 env_variables.LUA_VERSION = luaversion_short
349 env_variables.LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config.lua"
350 if test_env.TEST_TARGET_OS == "windows" then
351 env_variables.LUA_PATH = testing_paths.testing_lrprefix .. "\\lua\\?.lua;"
352 else
353 env_variables.LUA_PATH = testing_paths.testing_lrprefix .. "/share/lua/" .. luaversion_short .. "/?.lua;"
354 end
355 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;"
356 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;"
357 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;"
358 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;"
359 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;"
360 env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;"
361 .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;"
362 env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;"
363
364 return env_variables
365end
366
367--- Create md5sums of origin system and system-copy testing directory
368-- @param testing_paths table: table with paths to testing directory
369-- @return md5sums table: table of md5sums of system and system-copy testing directory
370local function create_md5sums(testing_paths)
371 local md5sums = {}
372 md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy)
373 md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy)
374
375 return md5sums
376end
377
378local function make_run_function(cmd_name, exec_function, with_coverage, do_print)
379 local cmd_prefix = Q(test_env.testing_paths.lua) .. " "
380
381 if with_coverage then
382 cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testrun_dir .. "/luacov.config')\" "
383 end
384
385 if test_env.TEST_TARGET_OS == "windows" then
386 cmd_prefix = cmd_prefix .. Q(test_env.testing_paths.testing_lrprefix .. "/" .. cmd_name .. ".lua") .. " "
387 else
388 cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " "
389 end
390
391 return function(cmd, new_vars)
392 local temp_vars = {}
393 for k, v in pairs(test_env.env_variables) do
394 temp_vars[k] = v
395 end
396 if new_vars then
397 for k, v in pairs(new_vars) do
398 temp_vars[k] = v
399 end
400 end
401 return exec_function(cmd_prefix .. cmd, do_print, temp_vars)
402 end
403end
404
405local function make_run_functions()
406 return {
407 luarocks = make_run_function("luarocks", execute_output, true, true),
408 luarocks_bool = make_run_function("luarocks", execute_bool, true, true),
409 luarocks_noprint = make_run_function("luarocks", execute_bool, true, false),
410 luarocks_nocov = make_run_function("luarocks", execute_bool, false, true),
411 luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false),
412 luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true),
413 luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true),
414 luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false)
415 }
416end
417
418--- Rebuild environment.
419-- Remove old installed rocks and install new ones,
420-- updating manifests and tree copies.
421local function build_environment(rocks, env_variables)
422 title("BUILDING ENVIRONMENT")
423 local testing_paths = test_env.testing_paths
424 test_env.remove_dir(testing_paths.testing_tree)
425 test_env.remove_dir(testing_paths.testing_sys_tree)
426 test_env.remove_dir(testing_paths.testing_tree_copy)
427 test_env.remove_dir(testing_paths.testing_sys_tree_copy)
428
429 lfs.mkdir(testing_paths.testing_tree)
430 lfs.mkdir(testing_paths.testing_sys_tree)
431
432 test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_server))
433 test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_cache))
434
435 for _, rock in ipairs(rocks) do
436 if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. Q(rock), env_variables) then
437 test_env.run.luarocks_nocov("build --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock) .. "", env_variables)
438 test_env.run.luarocks_nocov("pack --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables)
439 if test_env.TEST_TARGET_OS == "windows" then
440 execute_bool(testing_paths.win_tools .. "/mv " .. rock .. "-*.rock " .. testing_paths.testing_cache)
441 else
442 execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache)
443 end
444 end
445 end
446
447 test_env.copy_dir(testing_paths.testing_tree, testing_paths.testing_tree_copy)
448 test_env.copy_dir(testing_paths.testing_sys_tree, testing_paths.testing_sys_tree_copy)
449end
450
451--- Reset testing environment
452local function reset_environment(testing_paths, md5sums)
453 local testing_tree_md5 = hash_environment(testing_paths.testing_tree)
454 local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree)
455
456 if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then
457 test_env.remove_dir(testing_paths.testing_tree)
458 test_env.copy_dir(testing_paths.testing_tree_copy, testing_paths.testing_tree)
459 end
460
461 if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then
462 test_env.remove_dir(testing_paths.testing_sys_tree)
463 test_env.copy_dir(testing_paths.testing_sys_tree_copy, testing_paths.testing_sys_tree)
464 end
465end
466
467local function create_paths(luaversion_full)
468
469 local testing_paths = {}
470 testing_paths.luadir = (test_env.LUA_DIR or "/usr/local")
471 testing_paths.lua = testing_paths.luadir .. "/bin/" .. (test_env.LUA_INTERPRETER or "lua")
472
473 if test_env.TEST_TARGET_OS == "windows" then
474 testing_paths.luarocks_tmp = os.getenv("TEMP")
475 else
476 testing_paths.luarocks_tmp = "/tmp/luarocks_testing"
477 end
478
479 testing_paths.luarocks_dir = lfs.currentdir()
480
481 if test_env.TEST_TARGET_OS == "windows" then
482 testing_paths.luarocks_dir = testing_paths.luarocks_dir:gsub("\\","/")
483 end
484
485 testing_paths.fixtures_dir = testing_paths.luarocks_dir .. "/spec/fixtures"
486 testing_paths.util_dir = testing_paths.luarocks_dir .. "/spec/util"
487 testing_paths.testrun_dir = testing_paths.luarocks_dir .. "/testrun"
488 testing_paths.src_dir = testing_paths.luarocks_dir .. "/src"
489 testing_paths.testing_lrprefix = testing_paths.testrun_dir .. "/testing_lrprefix-" .. luaversion_full
490 testing_paths.testing_tree = testing_paths.testrun_dir .. "/testing-" .. luaversion_full
491 testing_paths.testing_tree_copy = testing_paths.testrun_dir .. "/testing_copy-" .. luaversion_full
492 testing_paths.testing_sys_tree = testing_paths.testrun_dir .. "/testing_sys-" .. luaversion_full
493 testing_paths.testing_sys_tree_copy = testing_paths.testrun_dir .. "/testing_sys_copy-" .. luaversion_full
494 testing_paths.testing_cache = testing_paths.testrun_dir .. "/testing_cache-" .. luaversion_full
495 testing_paths.testing_server = testing_paths.testrun_dir .. "/testing_server-" .. luaversion_full
496
497 testing_paths.testing_rocks = testing_paths.testing_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version
498 testing_paths.testing_sys_rocks = testing_paths.testing_sys_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version
499
500 if test_env.TEST_TARGET_OS == "windows" then
501 testing_paths.win_tools = testing_paths.testing_lrprefix .. "/tools"
502 end
503
504 return testing_paths
505end
506
507--- Helper function to unload luarocks modules from global table package.loaded
508-- Needed to load our local (testing) version of LuaRocks
509function test_env.unload_luarocks()
510 for modname, _ in pairs(package.loaded) do
511 if modname:match("^luarocks%.") then
512 package.loaded[modname] = nil
513 end
514 end
515end
516
517--- Function for initially setup of environment, variables, md5sums for spec files
518function test_env.setup_specs(extra_rocks)
519 -- if global variable about successful creation of testing environment doesn't exist, build environment
520 if not test_env.setup_done then
521 if test_env.TRAVIS then
522 if not test_env.exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then
523 execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa")
524 execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys")
525 execute_bool("chmod og-wx ~/.ssh/authorized_keys")
526 execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts")
527 end
528 end
529
530 test_env.main()
531 package.path = test_env.env_variables.LUA_PATH
532
533 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables)
534 test_env.lib_extension = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').lib_extension)\"", false, test_env.env_variables)
535 test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or ""
536 test_env.md5sums = create_md5sums(test_env.testing_paths)
537 test_env.setup_done = true
538 title("RUNNING TESTS")
539 end
540
541 if extra_rocks then
542 local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server)
543 if make_manifest then
544 test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server)
545 end
546 end
547
548 if test_env.RESET_ENV then
549 reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables)
550 end
551end
552
553--- Test if required rock is installed and if not, install it.
554-- Return `true` if the rock is already installed or has been installed successfully,
555-- `false` if installation failed.
556function test_env.need_rock(rock)
557 print("Check if " .. rock .. " is installed")
558 if test_env.run.luarocks_noprint_nocov(test_env.quiet("show " .. rock)) then
559 return true
560 else
561 return test_env.run.luarocks_noprint_nocov(test_env.quiet("install " .. rock))
562 end
563end
564
565--- For each key-value pair in replacements table
566-- replace %{key} in given string with value.
567local function substitute(str, replacements)
568 return (str:gsub("%%%b{}", function(marker)
569 return replacements[marker:sub(3, -2)]
570 end))
571end
572
573
574--- Create configs for luacov and several versions of Luarocks
575-- configs needed for some tests.
576local function create_configs()
577 -- testing_config.lua and testing_config_show_downloads.lua
578 local config_content = substitute([[
579 rocks_trees = {
580 "%{testing_tree}",
581 { name = "system", root = "%{testing_sys_tree}" },
582 }
583 rocks_servers = {
584 "%{testing_server}"
585 }
586 local_cache = "%{testing_cache}"
587 upload_server = "testing"
588 upload_user = "%{user}"
589 upload_servers = {
590 testing = {
591 rsync = "localhost/tmp/luarocks_testing",
592 },
593 }
594 external_deps_dirs = {
595 "/usr/local",
596 "/usr",
597 -- These are used for a test that fails, so it
598 -- can point to invalid paths:
599 {
600 prefix = "/opt",
601 bin = "bin",
602 include = "include",
603 lib = { "lib", "lib64" },
604 }
605 }
606 ]], {
607 user = os.getenv("USER"),
608 testing_sys_tree = test_env.testing_paths.testing_sys_tree,
609 testing_tree = test_env.testing_paths.testing_tree,
610 testing_server = test_env.testing_paths.testing_server,
611 testing_cache = test_env.testing_paths.testing_cache
612 })
613
614 write_file(test_env.testing_paths.testrun_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"")
615 write_file(test_env.testing_paths.testrun_dir .. "/testing_config_show_downloads.lua", config_content
616 .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}")
617
618 -- testing_config_sftp.lua
619 config_content = substitute([[
620 rocks_trees = {
621 "%{testing_tree}",
622 "%{testing_sys_tree}",
623 }
624 local_cache = "%{testing_cache}"
625 upload_server = "testing"
626 upload_user = "%{user}"
627 upload_servers = {
628 testing = {
629 sftp = "localhost/tmp/luarocks_testing",
630 },
631 }
632 ]], {
633 user = os.getenv("USER"),
634 testing_sys_tree = test_env.testing_paths.testing_sys_tree,
635 testing_tree = test_env.testing_paths.testing_tree,
636 testing_cache = test_env.testing_paths.testing_cache
637 })
638
639 write_file(test_env.testing_paths.testrun_dir .. "/testing_config_sftp.lua", config_content)
640
641 -- luacov.config
642 config_content = substitute([[
643 return {
644 statsfile = "%{testrun_dir}/luacov.stats.out",
645 reportfile = "%{testrun_dir}/luacov.report.out",
646 modules = {
647 ["luarocks"] = "src/bin/luarocks",
648 ["luarocks-admin"] = "src/bin/luarocks-admin",
649 ["luarocks.*"] = "src",
650 ["luarocks.*.*"] = "src",
651 ["luarocks.*.*.*"] = "src"
652 }
653 }
654 ]], {
655 testrun_dir = test_env.testing_paths.testrun_dir
656 })
657
658 write_file(test_env.testing_paths.testrun_dir .. "/luacov.config", config_content)
659
660 config_content = [[
661 -- Config file of mock LuaRocks.org site for tests
662 upload = {
663 server = "http://localhost:8080",
664 tool_version = "1.0.0",
665 api_version = "1",
666 }
667 ]]
668 write_file(test_env.testing_paths.testrun_dir .. "/luarocks_site.lua", config_content)
669end
670
671--- Remove testing directories.
672local function clean()
673 print("Cleaning testing directory...")
674 test_env.remove_dir(test_env.testing_paths.luarocks_tmp)
675 test_env.remove_subdirs(test_env.testing_paths.testrun_dir, "testing[_%-]")
676 test_env.remove_files(test_env.testing_paths.testrun_dir, "testing_")
677 test_env.remove_files(test_env.testing_paths.testrun_dir, "luacov")
678 test_env.remove_files(test_env.testing_paths.testrun_dir, "upload_config")
679 test_env.remove_files(test_env.testing_paths.testrun_dir, "luarocks_site")
680 print("Cleaning done!")
681end
682
683--- Install luarocks into testing prefix.
684local function install_luarocks(install_env_vars)
685 local testing_paths = test_env.testing_paths
686 title("Installing LuaRocks")
687 if test_env.TEST_TARGET_OS == "windows" then
688 local compiler_flag = test_env.MINGW and "/MW" or ""
689 assert(execute_bool("install.bat /LUA " .. testing_paths.luadir .. " " .. compiler_flag .. " /P " .. testing_paths.testing_lrprefix .. " /NOREG /NOADMIN /F /Q /CONFIG " .. testing_paths.testing_lrprefix .. "/etc/luarocks", false, install_env_vars))
690 assert(execute_bool(testing_paths.win_tools .. "/cp " .. testing_paths.testing_lrprefix .. "/lua/luarocks/core/site_config* " .. testing_paths.src_dir .. "/luarocks/core"))
691 else
692 local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix
693 assert(execute_bool(configure_cmd, false, install_env_vars))
694 assert(execute_bool("make clean", false, install_env_vars))
695 assert(execute_bool("make src/luarocks/core/site_config_"..test_env.lua_version:gsub("%.", "_")..".lua", false, install_env_vars))
696 assert(execute_bool("make dev", false, install_env_vars))
697 end
698 print("LuaRocks installed correctly!")
699end
700
701function test_env.mock_server_extra_rocks(more)
702 local rocks = {
703 -- rocks needed for mock-server
704 "/copas-2.0.1-1.src.rock",
705 "/coxpcall-1.16.0-1.src.rock",
706 "/dkjson-2.5-2.src.rock",
707 "/luafilesystem-1.6.3-1.src.rock",
708 "/luasec-0.6-1.rockspec",
709 "/luasocket-3.0rc1-2.src.rock",
710 "/luasocket-3.0rc1-2.rockspec",
711 "/restserver-0.1-1.src.rock",
712 "/restserver-xavante-0.2-1.src.rock",
713 "/rings-1.3.0-1.src.rock",
714 "/wsapi-1.6.1-1.src.rock",
715 "/wsapi-xavante-1.6.1-1.src.rock",
716 "/xavante-2.4.0-1.src.rock"
717 }
718 if more then
719 for _, rock in ipairs(more) do
720 table.insert(rocks, rock)
721 end
722 end
723 return rocks
724end
725
726function test_env.mock_server_init()
727 local assert = require("luassert")
728 local testing_paths = test_env.testing_paths
729 assert.is_true(test_env.need_rock("restserver-xavante"))
730 local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua &", true, test_env.env_variables)
731 os.execute(final_command)
732end
733
734function test_env.mock_server_done()
735 os.execute("curl localhost:8080/shutdown")
736end
737
738---
739-- Main function to create config files and testing environment
740function test_env.main()
741 local testing_paths = test_env.testing_paths
742
743 if test_env.TEST_ENV_CLEAN then
744 clean()
745 end
746
747 lfs.mkdir(testing_paths.testrun_dir)
748 lfs.mkdir(testing_paths.testing_cache)
749 lfs.mkdir(testing_paths.luarocks_tmp)
750
751 create_configs()
752
753 local install_env_vars = {
754 LUAROCKS_CONFIG = test_env.testing_paths.testrun_dir .. "/testing_config.lua"
755 }
756
757 install_luarocks(install_env_vars)
758
759 -- Preparation of rocks for building environment
760 local rocks = {} -- names of rocks, required for building environment
761 local urls = {} -- names of rock and rockspec files to be downloaded
762 table.insert(urls, "/luacov-0.11.0-1.rockspec")
763 table.insert(urls, "/luacov-0.11.0-1.src.rock")
764
765 if test_env.TYPE_TEST_ENV == "full" then
766 table.insert(urls, "/luafilesystem-1.6.3-1.src.rock")
767 table.insert(urls, "/luasocket-3.0rc1-1.src.rock")
768 table.insert(urls, "/luasocket-3.0rc1-1.rockspec")
769 table.insert(urls, "/luaposix-33.2.1-1.src.rock")
770 table.insert(urls, "/md5-1.2-1.src.rock")
771 table.insert(urls, "/lzlib-0.4.1.53-1.src.rock")
772 rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"}
773
774 if test_env.LUA_V ~= "5.1" then
775 table.insert(urls, "/luabitop-1.0.2-1.rockspec")
776 table.insert(urls, "/luabitop-1.0.2-1.src.rock")
777 table.insert(rocks, "luabitop")
778 end
779 end
780
781 table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment
782
783 -- Download rocks needed for LuaRocks testing environment
784 lfs.mkdir(testing_paths.testing_server)
785 download_rocks(urls, testing_paths.testing_server)
786 build_environment(rocks, install_env_vars)
787end
788
789test_env.set_lua_version()
790test_env.set_args()
791test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V)
792test_env.env_variables = create_env(test_env.testing_paths)
793test_env.run = make_run_functions()
794
795return test_env
diff --git a/spec/util_spec.lua b/spec/util_spec.lua
index 25cc51d8..3aa8fbf5 100644
--- a/spec/util_spec.lua
+++ b/spec/util_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua
index 0c860939..9ee86ada 100644
--- a/spec/write_rockspec_spec.lua
+++ b/spec/write_rockspec_spec.lua
@@ -1,4 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4 4
@@ -27,28 +27,28 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function()
27 27
28 describe("LuaRocks write_rockspec more complex tests", function() 28 describe("LuaRocks write_rockspec more complex tests", function()
29 it("LuaRocks write_rockspec git luarocks", function() 29 it("LuaRocks write_rockspec git luarocks", function()
30 assert.is_true(run.luarocks_bool("write_rockspec git://github.com/keplerproject/luarocks")) 30 assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock"))
31 assert.is.truthy(lfs.attributes("luarocks-dev-1.rockspec")) 31 assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec"))
32 assert.is_true(os.remove("luarocks-dev-1.rockspec")) 32 assert.is_true(os.remove("testrock-dev-1.rockspec"))
33 end) 33 end)
34 34
35 it("LuaRocks write_rockspec git luarocks --tag=v2.3.0", function() 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")) 36 assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --tag=v2.3.0"))
37 assert.is.truthy(lfs.attributes("luarocks-2.3.0-1.rockspec")) 37 assert.is.truthy(lfs.attributes("testrock-2.3.0-1.rockspec"))
38 assert.is_true(os.remove("luarocks-2.3.0-1.rockspec")) 38 assert.is_true(os.remove("testrock-2.3.0-1.rockspec"))
39 end) 39 end)
40 40
41 it("LuaRocks write_rockspec git luarocks with format flag", function() 41 it("LuaRocks write_rockspec git luarocks with format flag", function()
42 assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2")) 42 assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --rockspec-format=1.1 --lua-version=5.1,5.2"))
43 assert.is.truthy(lfs.attributes("luarocks-dev-1.rockspec")) 43 assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec"))
44 assert.is_true(os.remove("luarocks-dev-1.rockspec")) 44 assert.is_true(os.remove("testrock-dev-1.rockspec"))
45 end) 45 end)
46 46
47 it("LuaRocks write_rockspec git luarocks with full flags", function() 47 it("LuaRocks write_rockspec git luarocks with full flags", function()
48 assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/luarocks --lua-version=5.1,5.2 --license=\"MIT/X11\" " 48 assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --lua-version=5.1,5.2 --license=\"MIT/X11\" "
49 .. " --homepage=\"http://www.luarocks.org\" --summary=\"A package manager for Lua modules\" ")) 49 .. " --homepage=\"http://www.luarocks.org\" --summary=\"A package manager for Lua modules\" "))
50 assert.is.truthy(lfs.attributes("luarocks-dev-1.rockspec")) 50 assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec"))
51 assert.is_true(os.remove("luarocks-dev-1.rockspec")) 51 assert.is_true(os.remove("testrock-dev-1.rockspec"))
52 end) 52 end)
53 53
54 it("LuaRocks write_rockspec rockspec via http", function() 54 it("LuaRocks write_rockspec rockspec via http", function()