aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Melnichenko <mpeterval@gmail.com>2016-07-09 16:35:33 +0400
committerGitHub <noreply@github.com>2016-07-09 16:35:33 +0400
commit8e55688c191827a9b2e9c499a95c888078979e8c (patch)
treeaeaf8c1886c949e8e357b59a04cebc3be3930bce
parent5af7e0d7c2dcf65e41ae8523f3771e9528be32a7 (diff)
parenta05ba7ce42ae4e42f80b5cacdd8770ae5e6cc04b (diff)
downloadluarocks-8e55688c191827a9b2e9c499a95c888078979e8c.tar.gz
luarocks-8e55688c191827a9b2e9c499a95c888078979e8c.tar.bz2
luarocks-8e55688c191827a9b2e9c499a95c888078979e8c.zip
Merge pull request #583 from mpeterv/adjust-new-tests
Minor changes and fixes for new test suite
-rw-r--r--.busted6
-rw-r--r--.travis.yml16
-rw-r--r--spec/add_spec.lua10
-rw-r--r--spec/build_spec.lua7
-rw-r--r--spec/config_spec.lua12
-rw-r--r--spec/deps_spec.lua9
-rw-r--r--spec/doc_spec.lua7
-rw-r--r--spec/download_spec.lua5
-rw-r--r--spec/fetch_spec.lua3
-rw-r--r--spec/help_spec.lua10
-rw-r--r--spec/install_spec.lua22
-rw-r--r--spec/lint_spec.lua10
-rw-r--r--spec/list_spec.lua8
-rw-r--r--spec/make_manifest_spec.lua10
-rw-r--r--spec/make_spec.lua9
-rw-r--r--spec/new_version_spec.lua9
-rw-r--r--spec/pack_spec.lua6
-rw-r--r--spec/path_spec.lua8
-rw-r--r--spec/purge_spec.lua10
-rw-r--r--spec/refresh_cache_spec.lua10
-rw-r--r--spec/remove_spec.lua9
-rw-r--r--spec/search_spec.lua8
-rw-r--r--spec/show_spec.lua8
-rw-r--r--spec/unpack_spec.lua13
-rw-r--r--spec/upload_spec.lua6
-rw-r--r--spec/util_spec.lua10
-rw-r--r--spec/write_rockspec_spec.lua9
-rw-r--r--test/test_environment.lua624
28 files changed, 405 insertions, 469 deletions
diff --git a/.busted b/.busted
new file mode 100644
index 00000000..29a8137b
--- /dev/null
+++ b/.busted
@@ -0,0 +1,6 @@
1return {
2 default = {
3 helper = "test/test_environment",
4 ["auto-insulate"] = false
5 }
6}
diff --git a/.travis.yml b/.travis.yml
index c8755e7f..02bdb6c9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -40,11 +40,7 @@ matrix:
40 40
41 41
42before_install: 42before_install:
43 - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi 43 - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install python; fi
44 - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3; fi
45 - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then virtualenv venv -p python3; fi
46 - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then source venv/bin/activate; fi
47
48 - pip install hererocks 44 - pip install hererocks
49 - hererocks lua_install -r^ --$LUA 45 - hererocks lua_install -r^ --$LUA
50 - export PATH=$PATH:$PWD/lua_install/bin # Add directory with all installed binaries to PATH 46 - export PATH=$PATH:$PWD/lua_install/bin # Add directory with all installed binaries to PATH
@@ -53,17 +49,17 @@ install:
53 - luarocks install busted 49 - luarocks install busted
54 - luarocks install luacov 50 - luarocks install luacov
55 - luarocks install luacov-coveralls 51 - luarocks install luacov-coveralls
56 52
57script: 53script:
58 - busted -Xhelper travis,$LUA --verbose 54 - busted -Xhelper travis --verbose
59 - busted -Xhelper travis,$LUA,env=full --verbose 55 - busted -Xhelper travis,env=full --verbose
60 56
61after_success: 57after_success:
62 - luacov-coveralls -c $TRAVIS_BUILD_DIR/test/luacov.config --exclude $TRAVIS_BUILD_DIR/test/ 58 - luacov-coveralls -c $TRAVIS_BUILD_DIR/test/luacov.config --exclude $TRAVIS_BUILD_DIR/test/
63 - $PWD/lua_install/bin/luacov -c $TRAVIS_BUILD_DIR/test/luacov.config 59 - luacov -c $TRAVIS_BUILD_DIR/test/luacov.config
64 - grep "Summary" -B1 -A1000 $TRAVIS_BUILD_DIR/test/luacov.report.out 60 - grep "Summary" -B1 -A1000 $TRAVIS_BUILD_DIR/test/luacov.report.out
65 61
66notifications: 62notifications:
67 email: 63 email:
68 on_success: change 64 on_success: change
69 on_failure: change \ No newline at end of file 65 on_failure: change
diff --git a/spec/add_spec.lua b/spec/add_spec.lua
index e417f974..dca6f850 100644
--- a/spec/add_spec.lua
+++ b/spec/add_spec.lua
@@ -1,20 +1,18 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3local testing_paths = test_env.testing_paths
3 4
4test_env.unload_luarocks() 5test_env.unload_luarocks()
5local add = require("luarocks.add")
6 6
7local extra_rocks = { 7local extra_rocks = {
8 "/luasocket-3.0rc1-1.src.rock", 8 "/luasocket-3.0rc1-1.src.rock",
9 "/luasocket-3.0rc1-1.rockspec" 9 "/luasocket-3.0rc1-1.rockspec"
10} 10}
11 11
12expose("LuaRocks add tests #blackbox #b_add", function() 12describe("LuaRocks add tests #blackbox #b_add", function()
13 13
14 before_each(function() 14 before_each(function()
15 test_env.setup_specs(extra_rocks) 15 test_env.setup_specs(extra_rocks)
16 testing_paths = test_env.testing_paths
17 run = test_env.run
18 end) 16 end)
19 17
20 describe("LuaRocks-admin add tests", function() 18 describe("LuaRocks-admin add tests", function()
@@ -43,4 +41,4 @@ expose("LuaRocks add tests #blackbox #b_add", function()
43 assert.is_false(run.luarocks_admin_bool("--server=\"localhost@/tmp/luarocks_testing\" add " .. testing_paths.testing_server .. "luasocket-3.0rc1-1.src.rock")) 41 assert.is_false(run.luarocks_admin_bool("--server=\"localhost@/tmp/luarocks_testing\" add " .. testing_paths.testing_server .. "luasocket-3.0rc1-1.src.rock"))
44 end) 42 end)
45 end) 43 end)
46end) \ No newline at end of file 44end)
diff --git a/spec/build_spec.lua b/spec/build_spec.lua
index 6665de0b..1ce99089 100644
--- a/spec/build_spec.lua
+++ b/spec/build_spec.lua
@@ -1,8 +1,9 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
4local testing_paths = test_env.testing_paths
3 5
4test_env.unload_luarocks() 6test_env.unload_luarocks()
5local build = require("luarocks.build")
6 7
7local extra_rocks = { 8local extra_rocks = {
8 "/lmathx-20120430.51-1.src.rock", 9 "/lmathx-20120430.51-1.src.rock",
@@ -26,12 +27,10 @@ local extra_rocks = {
26 "/validate-args-1.5.4-1.rockspec" 27 "/validate-args-1.5.4-1.rockspec"
27} 28}
28 29
29expose("LuaRocks build tests #blackbox #b_build", function() 30describe("LuaRocks build tests #blackbox #b_build", function()
30 31
31 before_each(function() 32 before_each(function()
32 test_env.setup_specs(extra_rocks) 33 test_env.setup_specs(extra_rocks)
33 testing_paths = test_env.testing_paths
34 run = test_env.run
35 end) 34 end)
36 35
37 describe("LuaRocks build - basic testing set", function() 36 describe("LuaRocks build - basic testing set", function()
diff --git a/spec/config_spec.lua b/spec/config_spec.lua
index f6cabd8c..0dee8620 100644
--- a/spec/config_spec.lua
+++ b/spec/config_spec.lua
@@ -1,17 +1,17 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
4local testing_paths = test_env.testing_paths
5local site_config
3 6
4test_env.unload_luarocks() 7test_env.unload_luarocks()
5local cfg = require("luarocks.cfg")
6 8
7expose("LuaRocks config tests #blackbox #b_config", function() 9describe("LuaRocks config tests #blackbox #b_config", function()
8 10
9 before_each(function() 11 before_each(function()
10 test_env.setup_specs(extra_rocks) 12 test_env.setup_specs()
11 test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs 13 test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs
12 site_config = require("luarocks.site_config") 14 site_config = require("luarocks.site_config")
13 testing_paths = test_env.testing_paths
14 run = test_env.run
15 end) 15 end)
16 16
17 describe("LuaRocks config - basic tests", function() 17 describe("LuaRocks config - basic tests", function()
@@ -87,4 +87,4 @@ expose("LuaRocks config tests #blackbox #b_config", function()
87 test_env.remove_dir(testing_paths.testing_lrprefix) 87 test_env.remove_dir(testing_paths.testing_lrprefix)
88 end) 88 end)
89 end) 89 end)
90end) \ No newline at end of file 90end)
diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua
index ce784080..c1bd404d 100644
--- a/spec/deps_spec.lua
+++ b/spec/deps_spec.lua
@@ -1,8 +1,9 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
4local testing_paths = test_env.testing_paths
3 5
4test_env.unload_luarocks() 6test_env.unload_luarocks()
5local deps = require("luarocks.deps")
6 7
7local extra_rocks = { 8local extra_rocks = {
8 "/lxsh-0.8.6-2.src.rock", 9 "/lxsh-0.8.6-2.src.rock",
@@ -12,12 +13,10 @@ local extra_rocks = {
12 "/lpeg-0.12-1.src.rock" 13 "/lpeg-0.12-1.src.rock"
13} 14}
14 15
15expose("LuaRocks deps tests #blackbox #b_deps", function() 16describe("LuaRocks deps tests #blackbox #b_deps", function()
16 17
17 before_each(function() 18 before_each(function()
18 test_env.setup_specs(extra_rocks) 19 test_env.setup_specs(extra_rocks)
19 testing_paths = test_env.testing_paths
20 run = test_env.run
21 end) 20 end)
22 21
23 it("LuaRocks deps mode one", function() 22 it("LuaRocks deps mode one", function()
@@ -112,4 +111,4 @@ expose("LuaRocks deps tests #blackbox #b_deps", function()
112 assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) 111 assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh"))
113 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) 112 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh"))
114 end) 113 end)
115end) \ No newline at end of file 114end)
diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua
index 476b8ea8..9dbeaab8 100644
--- a/spec/doc_spec.lua
+++ b/spec/doc_spec.lua
@@ -1,19 +1,16 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5local doc = require("luarocks.doc")
6 5
7local extra_rocks = { 6local extra_rocks = {
8 "/luarepl-0.4-1.src.rock" 7 "/luarepl-0.4-1.src.rock"
9} 8}
10 9
11expose("LuaRocks doc tests #blackbox #b_doc", function() 10describe("LuaRocks doc tests #blackbox #b_doc", function()
12 11
13 before_each(function() 12 before_each(function()
14 test_env.setup_specs(extra_rocks) 13 test_env.setup_specs(extra_rocks)
15 testing_paths = test_env.testing_paths
16 run = test_env.run
17 end) 14 end)
18 15
19 describe("LuaRocks doc basic tests", function() 16 describe("LuaRocks doc basic tests", function()
diff --git a/spec/download_spec.lua b/spec/download_spec.lua
index 9b5d9e2e..320d9304 100644
--- a/spec/download_spec.lua
+++ b/spec/download_spec.lua
@@ -1,18 +1,17 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
3 4
4test_env.unload_luarocks() 5test_env.unload_luarocks()
5local download = require("luarocks.download")
6 6
7local extra_rocks = { 7local extra_rocks = {
8 "/validate-args-1.5.4-1.rockspec" 8 "/validate-args-1.5.4-1.rockspec"
9} 9}
10 10
11expose("LuaRocks download tests #blackbox #b_download", function() 11describe("LuaRocks download tests #blackbox #b_download", function()
12 12
13 before_each(function() 13 before_each(function()
14 test_env.setup_specs(extra_rocks) 14 test_env.setup_specs(extra_rocks)
15 run = test_env.run
16 end) 15 end)
17 16
18 it("LuaRocks download with no flags/arguments", function() 17 it("LuaRocks download with no flags/arguments", function()
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua
index 1f298733..05a709e4 100644
--- a/spec/fetch_spec.lua
+++ b/spec/fetch_spec.lua
@@ -1,5 +1,4 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs")
3 2
4test_env.unload_luarocks() 3test_env.unload_luarocks()
5local fetch = require("luarocks.fetch") 4local fetch = require("luarocks.fetch")
@@ -13,4 +12,4 @@ describe("Luarocks fetch test #whitebox #w_fetch", function()
13 assert.are.same("parser.moon", fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) 12 assert.are.same("parser.moon", fetch.url_to_base_dir("git://github.com/Cirru/parser.moon"))
14 assert.are.same("v0.3", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) 13 assert.are.same("v0.3", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3"))
15 end) 14 end)
16end) \ No newline at end of file 15end)
diff --git a/spec/help_spec.lua b/spec/help_spec.lua
index 0f40dd38..0d41e2e9 100644
--- a/spec/help_spec.lua
+++ b/spec/help_spec.lua
@@ -1,14 +1,12 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5local help = require("luarocks.help")
6 5
7expose("LuaRocks help tests #blackbox #b_help", function() 6describe("LuaRocks help tests #blackbox #b_help", function()
8 7
9 before_each(function() 8 before_each(function()
10 test_env.setup_specs(extra_rocks) 9 test_env.setup_specs()
11 run = test_env.run
12 end) 10 end)
13 11
14 it("LuaRocks help with no flags/arguments", function() 12 it("LuaRocks help with no flags/arguments", function()
@@ -26,4 +24,4 @@ expose("LuaRocks help tests #blackbox #b_help", function()
26 it("LuaRocks-admin help with no flags/arguments", function() 24 it("LuaRocks-admin help with no flags/arguments", function()
27 assert.is_true(run.luarocks_admin_bool("help")) 25 assert.is_true(run.luarocks_admin_bool("help"))
28 end) 26 end)
29end) \ No newline at end of file 27end)
diff --git a/spec/install_spec.lua b/spec/install_spec.lua
index 306bbbc1..0e406e22 100644
--- a/spec/install_spec.lua
+++ b/spec/install_spec.lua
@@ -1,8 +1,10 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
4local testing_paths = test_env.testing_paths
5local env_variables = test_env.env_variables
3 6
4test_env.unload_luarocks() 7test_env.unload_luarocks()
5local install = require("luarocks.install")
6 8
7local extra_rocks = { 9local extra_rocks = {
8 "/cprint-0.1-2.src.rock", 10 "/cprint-0.1-2.src.rock",
@@ -19,14 +21,10 @@ local extra_rocks = {
19 "/wsapi-1.6-1.src.rock" 21 "/wsapi-1.6-1.src.rock"
20} 22}
21 23
22expose("LuaRocks install tests #blackbox #b_install", function() 24describe("LuaRocks install tests #blackbox #b_install", function()
23 25
24 before_each(function() 26 before_each(function()
25 test_env.setup_specs(extra_rocks) 27 test_env.setup_specs(extra_rocks)
26 testing_paths = test_env.testing_paths
27 env_variables = test_env.env_variables
28 run = test_env.run
29 platform = test_env.platform
30 end) 28 end)
31 29
32 describe("LuaRocks install - basic tests", function() 30 describe("LuaRocks install - basic tests", function()
@@ -86,21 +84,21 @@ expose("LuaRocks install tests #blackbox #b_install", function()
86 84
87 it("LuaRocks install only-deps of luasocket packed rock", function() 85 it("LuaRocks install only-deps of luasocket packed rock", function()
88 assert.is_true(test_env.need_luasocket()) 86 assert.is_true(test_env.need_luasocket())
89 local output = run.luarocks("install --only-deps " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. platform .. ".rock") 87 local output = run.luarocks("install --only-deps " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. test_env.platform .. ".rock")
90 assert.are.same(output, "Successfully installed dependencies for luasocket 3.0rc1-1") 88 assert.are.same(output, "Successfully installed dependencies for luasocket 3.0rc1-1")
91 end) 89 end)
92 90
93 it("LuaRocks install binary rock of cprint", function() 91 it("LuaRocks install binary rock of cprint", function()
94 assert.is_true(test_env.need_luasocket()) 92 assert.is_true(test_env.need_luasocket())
95 assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) 93 assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint"))
96 assert.is_true(run.luarocks_bool("install cprint-0.1-2." .. platform .. ".rock")) 94 assert.is_true(run.luarocks_bool("install cprint-0.1-2." .. test_env.platform .. ".rock"))
97 assert.is_true(os.remove("cprint-0.1-2." .. platform .. ".rock")) 95 assert.is_true(os.remove("cprint-0.1-2." .. test_env.platform .. ".rock"))
98 end) 96 end)
99 97
100 it("LuaRocks install reinstall", function() 98 it("LuaRocks install reinstall", function()
101 assert.is_true(test_env.need_luasocket()) 99 assert.is_true(test_env.need_luasocket())
102 assert.is_true(run.luarocks_bool("install " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. platform .. ".rock")) 100 assert.is_true(run.luarocks_bool("install " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. test_env.platform .. ".rock"))
103 assert.is_true(run.luarocks_bool("install --deps-mode=none " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. 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"))
104 end) 102 end)
105 end) 103 end)
106 104
@@ -127,4 +125,4 @@ expose("LuaRocks install tests #blackbox #b_install", function()
127 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.0-1")) 125 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.0-1"))
128 end) 126 end)
129 end) 127 end)
130end) \ No newline at end of file 128end)
diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua
index cba80a3e..f7496037 100644
--- a/spec/lint_spec.lua
+++ b/spec/lint_spec.lua
@@ -1,19 +1,17 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3local testing_paths = test_env.testing_paths
3 4
4test_env.unload_luarocks() 5test_env.unload_luarocks()
5local lint = require("luarocks.lint")
6 6
7local extra_rocks = { 7local extra_rocks = {
8 "/validate-args-1.5.4-1.rockspec" 8 "/validate-args-1.5.4-1.rockspec"
9} 9}
10 10
11expose("LuaRocks lint tests #blackbox #b_lint", function() 11describe("LuaRocks lint tests #blackbox #b_lint", function()
12 12
13 before_each(function() 13 before_each(function()
14 test_env.setup_specs(extra_rocks) 14 test_env.setup_specs(extra_rocks)
15 testing_paths = test_env.testing_paths
16 run = test_env.run
17 end) 15 end)
18 16
19 it("LuaRocks lint with no flags/arguments", function() 17 it("LuaRocks lint with no flags/arguments", function()
@@ -48,4 +46,4 @@ expose("LuaRocks lint tests #blackbox #b_lint", function()
48 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.testing_dir .. "/testfiles/no_build_table-1.0-1.rockspec"))
49 end) 47 end)
50 end) 48 end)
51end) \ No newline at end of file 49end)
diff --git a/spec/list_spec.lua b/spec/list_spec.lua
index 545483df..1b082ab6 100644
--- a/spec/list_spec.lua
+++ b/spec/list_spec.lua
@@ -1,20 +1,18 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3local testing_paths = test_env.testing_paths
3 4
4test_env.unload_luarocks() 5test_env.unload_luarocks()
5local list = require("luarocks.list")
6 6
7local extra_rocks = { 7local extra_rocks = {
8 "/say-1.0-1.src.rock", 8 "/say-1.0-1.src.rock",
9 "/say-1.2-1.src.rock" 9 "/say-1.2-1.src.rock"
10} 10}
11 11
12expose("LuaRocks list tests #blackbox #b_list", function() 12describe("LuaRocks list tests #blackbox #b_list", function()
13 13
14 before_each(function() 14 before_each(function()
15 test_env.setup_specs(extra_rocks) 15 test_env.setup_specs(extra_rocks)
16 run = test_env.run
17 testing_paths = test_env.testing_paths
18 end) 16 end)
19 17
20 it("LuaRocks list with no flags/arguments", function() 18 it("LuaRocks list with no flags/arguments", function()
diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua
index c6cb1328..1c7f5bf8 100644
--- a/spec/make_manifest_spec.lua
+++ b/spec/make_manifest_spec.lua
@@ -1,14 +1,12 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5local make_manifest = require("luarocks.make_manifest")
6 5
7expose("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() 6describe("LuaRocks make_manifest tests #blackbox #b_make_manifest", function()
8 7
9 before_each(function() 8 before_each(function()
10 test_env.setup_specs(extra_rocks) 9 test_env.setup_specs()
11 run = test_env.run
12 end) 10 end)
13 11
14 describe("LuaRocks-admin make manifest tests", function() 12 describe("LuaRocks-admin make manifest tests", function()
@@ -16,4 +14,4 @@ expose("LuaRocks make_manifest tests #blackbox #b_make_manifest", function()
16 assert.is_true(run.luarocks_admin_bool("make_manifest")) 14 assert.is_true(run.luarocks_admin_bool("make_manifest"))
17 end) 15 end)
18 end) 16 end)
19end) \ No newline at end of file 17end)
diff --git a/spec/make_spec.lua b/spec/make_spec.lua
index f70bb7e9..2821c143 100644
--- a/spec/make_spec.lua
+++ b/spec/make_spec.lua
@@ -1,8 +1,9 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
4local testing_paths = test_env.testing_paths
3 5
4test_env.unload_luarocks() 6test_env.unload_luarocks()
5local make = require("luarocks.make")
6 7
7local extra_rocks = { 8local extra_rocks = {
8 "/lpeg-0.12-1.src.rock", 9 "/lpeg-0.12-1.src.rock",
@@ -12,12 +13,10 @@ local extra_rocks = {
12 "/lxsh-0.8.6-2.rockspec" 13 "/lxsh-0.8.6-2.rockspec"
13} 14}
14 15
15expose("LuaRocks make tests #blackbox #b_make", function() 16describe("LuaRocks make tests #blackbox #b_make", function()
16 17
17 before_each(function() 18 before_each(function()
18 test_env.setup_specs(extra_rocks) 19 test_env.setup_specs(extra_rocks)
19 run = test_env.run
20 testing_paths = test_env.testing_paths
21 end) 20 end)
22 21
23 it("LuaRocks make with no flags/arguments", function() 22 it("LuaRocks make with no flags/arguments", function()
@@ -96,4 +95,4 @@ expose("LuaRocks make tests #blackbox #b_make", function()
96 assert.is.truthy(lfs.attributes("lxsh-0.8.6-2.all.rock")) 95 assert.is.truthy(lfs.attributes("lxsh-0.8.6-2.all.rock"))
97 end) 96 end)
98 end) 97 end)
99end) \ No newline at end of file 98end)
diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua
index 57014226..2274bce3 100644
--- a/spec/new_version_spec.lua
+++ b/spec/new_version_spec.lua
@@ -1,19 +1,18 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
4local testing_paths = test_env.testing_paths
3 5
4test_env.unload_luarocks() 6test_env.unload_luarocks()
5local new_version = require("luarocks.new_version")
6 7
7local extra_rocks = { 8local extra_rocks = {
8 "/abelhas-1.0-1.rockspec" 9 "/abelhas-1.0-1.rockspec"
9} 10}
10 11
11expose("LuaRocks new_version tests #blackbox #b_new_version", function() 12describe("LuaRocks new_version tests #blackbox #b_new_version", function()
12 13
13 before_each(function() 14 before_each(function()
14 test_env.setup_specs(extra_rocks) 15 test_env.setup_specs(extra_rocks)
15 testing_paths = test_env.testing_paths
16 run = test_env.run
17 end) 16 end)
18 17
19 describe("LuaRocks new_version basic tests", function() 18 describe("LuaRocks new_version basic tests", function()
@@ -50,4 +49,4 @@ expose("LuaRocks new_version tests #blackbox #b_new_version", function()
50 test_env.remove_files(lfs.currentdir(), "luacov--") 49 test_env.remove_files(lfs.currentdir(), "luacov--")
51 end) 50 end)
52 end) 51 end)
53end) \ No newline at end of file 52end)
diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua
index a07e7ed2..416184a8 100644
--- a/spec/pack_spec.lua
+++ b/spec/pack_spec.lua
@@ -1,8 +1,8 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
3 4
4test_env.unload_luarocks() 5test_env.unload_luarocks()
5local pack = require("luarocks.pack")
6 6
7local extra_rocks = { 7local extra_rocks = {
8 "/luasec-0.6-1.rockspec", 8 "/luasec-0.6-1.rockspec",
@@ -10,12 +10,10 @@ local extra_rocks = {
10 "/luasocket-3.0rc1-1.rockspec" 10 "/luasocket-3.0rc1-1.rockspec"
11} 11}
12 12
13expose("LuaRocks pack tests #blackbox #b_pack", function() 13describe("LuaRocks pack tests #blackbox #b_pack", function()
14 14
15 before_each(function() 15 before_each(function()
16 test_env.setup_specs(extra_rocks) 16 test_env.setup_specs(extra_rocks)
17 testing_paths = test_env.testing_paths
18 run = test_env.run
19 end) 17 end)
20 18
21 it("LuaRocks pack basic", function() 19 it("LuaRocks pack basic", function()
diff --git a/spec/path_spec.lua b/spec/path_spec.lua
index 266ada89..22f07591 100644
--- a/spec/path_spec.lua
+++ b/spec/path_spec.lua
@@ -1,13 +1,11 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5local path = require("luarocks.path")
6 5
7expose("LuaRocks path tests #blackbox #b_path", function() 6describe("LuaRocks path tests #blackbox #b_path", function()
8 before_each(function() 7 before_each(function()
9 test_env.setup_specs(extra_rocks) 8 test_env.setup_specs()
10 run = test_env.run
11 end) 9 end)
12 10
13 it("LuaRocks path bin", function() 11 it("LuaRocks path bin", function()
diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua
index 639f96f3..09a9d433 100644
--- a/spec/purge_spec.lua
+++ b/spec/purge_spec.lua
@@ -1,14 +1,12 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3local testing_paths = test_env.testing_paths
3 4
4test_env.unload_luarocks() 5test_env.unload_luarocks()
5local purge = require("luarocks.purge")
6 6
7expose("LuaRocks purge tests #blackbox #b_purge", function() 7describe("LuaRocks purge tests #blackbox #b_purge", function()
8 before_each(function() 8 before_each(function()
9 test_env.setup_specs(extra_rocks) 9 test_env.setup_specs()
10 testing_paths = test_env.testing_paths
11 run = test_env.run
12 end) 10 end)
13 11
14 describe("LuaRocks purge basic tests", function() 12 describe("LuaRocks purge basic tests", function()
diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua
index 27a95e5c..c20771ab 100644
--- a/spec/refresh_cache_spec.lua
+++ b/spec/refresh_cache_spec.lua
@@ -1,14 +1,12 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5local refresh_cache = require("luarocks.refresh_cache")
6 5
7expose("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() 6describe("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function()
8 7
9 before_each(function() 8 before_each(function()
10 test_env.setup_specs(extra_rocks) 9 test_env.setup_specs()
11 run = test_env.run
12 end) 10 end)
13 11
14 describe("LuaRocks-admin refresh cache tests #ssh", function() 12 describe("LuaRocks-admin refresh cache tests #ssh", function()
@@ -16,4 +14,4 @@ expose("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function()
16 assert.is_true(run.luarocks_admin_bool("--server=testing refresh_cache")) 14 assert.is_true(run.luarocks_admin_bool("--server=testing refresh_cache"))
17 end) 15 end)
18 end) 16 end)
19end) \ No newline at end of file 17end)
diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua
index a94673a8..41c6348a 100644
--- a/spec/remove_spec.lua
+++ b/spec/remove_spec.lua
@@ -1,8 +1,9 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
4local testing_paths = test_env.testing_paths
3 5
4test_env.unload_luarocks() 6test_env.unload_luarocks()
5local remove = require("luarocks.remove")
6 7
7local extra_rocks = { 8local extra_rocks = {
8 "/abelhas-1.0-1.rockspec", 9 "/abelhas-1.0-1.rockspec",
@@ -11,12 +12,10 @@ local extra_rocks = {
11 "/luasocket-3.0rc1-1.rockspec" 12 "/luasocket-3.0rc1-1.rockspec"
12} 13}
13 14
14expose("LuaRocks remove tests #blackbox #b_remove", function() 15describe("LuaRocks remove tests #blackbox #b_remove", function()
15 16
16 before_each(function() 17 before_each(function()
17 test_env.setup_specs(extra_rocks) 18 test_env.setup_specs(extra_rocks)
18 testing_paths = test_env.testing_paths
19 run = test_env.run
20 end) 19 end)
21 20
22 describe("LuaRocks remove basic tests", function() 21 describe("LuaRocks remove basic tests", function()
@@ -82,4 +81,4 @@ expose("LuaRocks remove tests #blackbox #b_remove", function()
82 it("LuaRocks-admin remove missing", function() 81 it("LuaRocks-admin remove missing", function()
83 assert.is_false(run.luarocks_admin_bool("--server=testing remove")) 82 assert.is_false(run.luarocks_admin_bool("--server=testing remove"))
84 end) 83 end)
85end) \ No newline at end of file 84end)
diff --git a/spec/search_spec.lua b/spec/search_spec.lua
index a0258942..33c49856 100644
--- a/spec/search_spec.lua
+++ b/spec/search_spec.lua
@@ -1,18 +1,16 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5local search = require("luarocks.search")
6 5
7local extra_rocks = { 6local extra_rocks = {
8"/lzlib-0.4.1.53-1.src.rock" 7"/lzlib-0.4.1.53-1.src.rock"
9} 8}
10 9
11expose("LuaRocks search tests #blackbox #b_search", function() 10describe("LuaRocks search tests #blackbox #b_search", function()
12 11
13 before_each(function() 12 before_each(function()
14 test_env.setup_specs(extra_rocks) 13 test_env.setup_specs(extra_rocks)
15 run = test_env.run
16 end) 14 end)
17 15
18 it("LuaRocks search with no flags/arguments", function() 16 it("LuaRocks search with no flags/arguments", function()
@@ -39,4 +37,4 @@ expose("LuaRocks search tests #blackbox #b_search", function()
39 local num = 123 37 local num = 123
40 assert.is_true(run.luarocks_bool("search " .. num)) 38 assert.is_true(run.luarocks_bool("search " .. num))
41 end) 39 end)
42end) \ No newline at end of file 40end)
diff --git a/spec/show_spec.lua b/spec/show_spec.lua
index 85797eb6..f528a6de 100644
--- a/spec/show_spec.lua
+++ b/spec/show_spec.lua
@@ -1,14 +1,12 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5local show = require("luarocks.show")
6 5
7expose("LuaRocks show tests #blackbox #b_show", function() 6describe("LuaRocks show tests #blackbox #b_show", function()
8 7
9 before_each(function() 8 before_each(function()
10 test_env.setup_specs(extra_rocks) 9 test_env.setup_specs()
11 run = test_env.run
12 end) 10 end)
13 11
14 it("LuaRocks show with no flags/arguments", function() 12 it("LuaRocks show with no flags/arguments", function()
diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua
index efe902f5..76e9e5a8 100644
--- a/spec/unpack_spec.lua
+++ b/spec/unpack_spec.lua
@@ -1,21 +1,18 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3local testing_paths = test_env.testing_paths
3 4
4test_env.unload_luarocks() 5test_env.unload_luarocks()
5local unpack = require("luarocks.unpack")
6 6
7local extra_rocks = { 7local extra_rocks = {
8 "/cprint-0.1-2.src.rock", 8 "/cprint-0.1-2.src.rock",
9 "/cprint-0.1-2.rockspec" 9 "/cprint-0.1-2.rockspec"
10} 10}
11 11
12expose("LuaRocks unpack tests #blackbox #b_unpack", function() 12describe("LuaRocks unpack tests #blackbox #b_unpack", function()
13 13
14 before_each(function() 14 before_each(function()
15 test_env.setup_specs(extra_rocks) 15 test_env.setup_specs(extra_rocks)
16 testing_paths = test_env.testing_paths
17 run = test_env.run
18 platform = test_env.platform
19 end) 16 end)
20 17
21 describe("LuaRocks unpack basic fail tests", function() 18 describe("LuaRocks unpack basic fail tests", function()
@@ -51,9 +48,9 @@ expose("LuaRocks unpack tests #blackbox #b_unpack", function()
51 it("LuaRocks unpack binary", function() 48 it("LuaRocks unpack binary", function()
52 assert.is_true(run.luarocks_bool("build cprint")) 49 assert.is_true(run.luarocks_bool("build cprint"))
53 assert.is_true(run.luarocks_bool("pack cprint")) 50 assert.is_true(run.luarocks_bool("pack cprint"))
54 assert.is_true(run.luarocks_bool("unpack cprint-0.1-2." .. platform .. ".rock")) 51 assert.is_true(run.luarocks_bool("unpack cprint-0.1-2." .. test_env.platform .. ".rock"))
55 test_env.remove_dir("cprint-0.1-2") 52 test_env.remove_dir("cprint-0.1-2")
56 os.remove("cprint-0.1-2." .. platform .. ".rock") 53 os.remove("cprint-0.1-2." .. test_env.platform .. ".rock")
57 end) 54 end)
58 end) 55 end)
59end) 56end)
diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua
index daf40d61..c10ef0e9 100644
--- a/spec/upload_spec.lua
+++ b/spec/upload_spec.lua
@@ -1,18 +1,16 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local run = test_env.run
3 3
4test_env.unload_luarocks() 4test_env.unload_luarocks()
5local upload = require("luarocks.upload")
6 5
7local extra_rocks = { 6local extra_rocks = {
8 "/lua-cjson-2.1.0-1.src.rock" 7 "/lua-cjson-2.1.0-1.src.rock"
9} 8}
10 9
11expose("LuaRocks upload tests #blackbox #b_upload", function() 10describe("LuaRocks upload tests #blackbox #b_upload", function()
12 11
13 before_each(function() 12 before_each(function()
14 test_env.setup_specs(extra_rocks) 13 test_env.setup_specs(extra_rocks)
15 run = test_env.run
16 end) 14 end)
17 15
18 it("LuaRocks upload with no flags/arguments", function() 16 it("LuaRocks upload with no flags/arguments", function()
diff --git a/spec/util_spec.lua b/spec/util_spec.lua
index 7c22d1cb..9118ffc9 100644
--- a/spec/util_spec.lua
+++ b/spec/util_spec.lua
@@ -1,13 +1,13 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
4local testing_paths = test_env.testing_paths
5local env_variables = test_env.env_variables
3 6
4expose("Basic tests #blackbox #b_util", function() 7describe("Basic tests #blackbox #b_util", function()
5 8
6 before_each(function() 9 before_each(function()
7 test_env.setup_specs(extra_rocks) 10 test_env.setup_specs()
8 testing_paths = test_env.testing_paths
9 env_variables = test_env.env_variables
10 run = test_env.run
11 end) 11 end)
12 12
13 it("LuaRocks version", function() 13 it("LuaRocks version", function()
diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua
index d6e32f15..85e345d5 100644
--- a/spec/write_rockspec_spec.lua
+++ b/spec/write_rockspec_spec.lua
@@ -1,14 +1,13 @@
1local test_env = require("test/test_environment") 1local test_env = require("test/test_environment")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local run = test_env.run
3 4
4test_env.unload_luarocks() 5test_env.unload_luarocks()
5local write_rockspec = require("luarocks.write_rockspec")
6 6
7expose("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() 7describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function()
8 8
9 before_each(function() 9 before_each(function()
10 test_env.setup_specs(extra_rocks) 10 test_env.setup_specs()
11 run = test_env.run
12 end) 11 end)
13 12
14 describe("LuaRocks write_rockspec basic tests", function() 13 describe("LuaRocks write_rockspec basic tests", function()
@@ -71,4 +70,4 @@ expose("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function()
71 assert.is_true(os.remove("luafcgi-scm-1.rockspec")) 70 assert.is_true(os.remove("luafcgi-scm-1.rockspec"))
72 end) 71 end)
73 end) 72 end)
74end) \ No newline at end of file 73end)
diff --git a/test/test_environment.lua b/test/test_environment.lua
index 6de501fb..6de7a4e2 100644
--- a/test/test_environment.lua
+++ b/test/test_environment.lua
@@ -1,26 +1,38 @@
1local lfs = require("lfs") 1local lfs = require("lfs")
2local test_env = {} 2local test_env = {}
3local arg = arg or { ... } 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 clean Remove existing testing environment.
18 travis Add if running on TravisCI.
19 os=<type> Set OS ("linux", "osx", or "windows").
20]]
4 21
5local function help() 22local function help()
6 print("LuaRocks test-suite\n\n".. 23 print(help_message)
7 [[ 24 os.exit(1)
8 INFORMATION 25end
9 New test-suite for LuaRocks project, using unit testing framework Busted. 26
10 REQUIREMENTS 27local function title(str)
11 Tests require to have Lua installed and added to PATH. Be sure sshd is runnig on your system, or 28 print()
12 use '--exclude-tags=ssh', to not execute tests which require sshd. 29 print(("-"):rep(#str))
13 USAGE -Xhelper <arguments> 30 print(str)
14 lua=<version> (mandatory) type your full version of Lua (e.g. --lua 5.2.4) 31 print(("-"):rep(#str))
15 OR 32end
16 luajit=<version> (mandatory) type your full version of LuaJIT (e.g. --luajit 2.0.3) 33
17 34local function exists(path)
18 env=<type> (default:"minimal") type what kind of environment to use ["minimal", "full"] 35 return lfs.attributes(path, "mode") ~= nil
19 clean remove existing testing environment
20 travis add just if running on TravisCI
21 os=<version> type your OS ["linux", "osx", "windows"]
22 ]]);
23 os.exit(1)
24end 36end
25 37
26--- Helper function for execute_bool and execute_output 38--- Helper function for execute_bool and execute_output
@@ -70,54 +82,38 @@ local function execute_output(command, print_command, env_variables)
70 return output:gsub("\n","") -- output adding new line, need to be removed 82 return output:gsub("\n","") -- output adding new line, need to be removed
71end 83end
72 84
73--- Set all arguments from input into global variables 85--- Set test_env.LUA_V or test_env.LUAJIT_V based
74function test_env.set_args() 86-- on version of Lua used to run this script.
75 if arg[1] == nil then 87function test_env.set_lua_version()
76 help() 88 if _G.jit then
77 end 89 test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d")
78 90 else
79 local args_position 91 test_env.LUA_V = _VERSION:match("5%.%d")
80
81 for i=1, #arg do
82 if arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then
83 args_position = i+1
84 test_env.LUA_V = arg[args_position]:gsub("(.*)lua=([^%,]+)(.*)","%2")
85 break
86 elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then
87 args_position = i+1
88 test_env.LUAJIT_V = arg[args_position]:gsub("(.*)luajit=([^%,]+)(.*)","%2")
89 break
90 elseif arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then
91 print("Please specify just Lua or LuaJIT version for testing in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag")
92 os.exit(1)
93 elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then
94 print("Please add mandatory argument - version of Lua or LuaJIT in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag")
95 os.exit(1)
96 end
97 end
98
99 if not args_position then
100 help()
101 end 92 end
93end
102 94
95--- Set all arguments from input into global variables
96function test_env.set_args()
103 -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables 97 -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables
104 test_env.TYPE_TEST_ENV = "minimal" 98 test_env.TYPE_TEST_ENV = "minimal"
105 99
106 if arg[args_position]:find("env=") then 100 for _, argument in ipairs(arg) do
107 test_env.TYPE_TEST_ENV = arg[args_position]:gsub("(.*)env=([^%,]+)(.*)","%2") 101 if argument:find("^env=") then
108 end 102 test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$")
109 if arg[args_position]:find("clean") then 103 elseif argument == "clean" then
110 test_env.TEST_ENV_CLEAN = true 104 test_env.TEST_ENV_CLEAN = true
111 end 105 elseif argument == "travis" then
112 if arg[args_position]:find("travis") then 106 test_env.TRAVIS = true
113 test_env.TRAVIS = true 107 elseif argument:find("^os=") then
114 end 108 test_env.TEST_TARGET_OS = argument:match("^os=(.*)$")
115 if arg[args_position]:find("os=") then 109 else
116 test_env.TEST_TARGET_OS = arg[args_position]:gsub("(.*)os=([^%,]+)(.*)","%2") 110 help()
111 end
117 end 112 end
118 113
119 if not test_env.TEST_TARGET_OS then 114 if not test_env.TEST_TARGET_OS then
120 print("[OS CHECK]") 115 title("OS CHECK")
116
121 if execute_bool("sw_vers") then 117 if execute_bool("sw_vers") then
122 test_env.TEST_TARGET_OS = "osx" 118 test_env.TEST_TARGET_OS = "osx"
123 elseif execute_bool("uname -s") then 119 elseif execute_bool("uname -s") then
@@ -125,7 +121,6 @@ function test_env.set_args()
125 else 121 else
126 test_env.TEST_TARGET_OS = "windows" 122 test_env.TEST_TARGET_OS = "windows"
127 end 123 end
128 print("--------------")
129 end 124 end
130 return true 125 return true
131end 126end
@@ -133,15 +128,13 @@ end
133--- Remove directory recursively 128--- Remove directory recursively
134-- @param path string: directory path to delete 129-- @param path string: directory path to delete
135function test_env.remove_dir(path) 130function test_env.remove_dir(path)
136 if lfs.attributes(path) then 131 if exists(path) then
137 for file in lfs.dir(path) do 132 for file in lfs.dir(path) do
138 if file ~= "." and file ~= ".." then 133 if file ~= "." and file ~= ".." then
139 local full_path = path..'/'..file 134 local full_path = path..'/'..file
140 local attr = lfs.attributes(full_path)
141 135
142 if attr.mode == "directory" then 136 if lfs.attributes(full_path, "mode") == "directory" then
143 test_env.remove_dir(full_path) 137 test_env.remove_dir(full_path)
144 os.remove(full_path)
145 else 138 else
146 os.remove(full_path) 139 os.remove(full_path)
147 end 140 end
@@ -151,32 +144,30 @@ function test_env.remove_dir(path)
151 os.remove(path) 144 os.remove(path)
152end 145end
153 146
154--- Remove directory recursively 147--- Remove subdirectories of a directory that match a pattern
155-- @param path string: directory path to delete 148-- @param path string: path to directory
156-- @param pattern string: pattern in directories 149-- @param pattern string: pattern matching basenames of subdirectories to be removed
157function test_env.remove_dir_pattern(path, pattern) 150function test_env.remove_subdirs(path, pattern)
158 if lfs.attributes(path) then 151 if exists(path) then
159 for file in lfs.dir(path) do 152 for file in lfs.dir(path) do
160 if file ~= "." and file ~= ".." then 153 if file ~= "." and file ~= ".." then
161 local full_path = path..'/'..file 154 local full_path = path..'/'..file
162 local attr = lfs.attributes(full_path)
163 155
164 if attr.mode == "directory" and file:find(pattern) then 156 if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then
165 test_env.remove_dir(full_path) 157 test_env.remove_dir(full_path)
166 os.remove(full_path)
167 end 158 end
168 end 159 end
169 end 160 end
170 end 161 end
171end 162end
172 163
173--- Remove files based on filename 164--- Remove files matching a pattern
174-- @param path string: directory where to delete files 165-- @param path string: directory where to delete files
175-- @param pattern string: pattern in filenames 166-- @param pattern string: pattern matching basenames of files to be deleted
176-- @return result_check boolean: true if one or more files deleted 167-- @return result_check boolean: true if one or more files deleted
177function test_env.remove_files(path, pattern) 168function test_env.remove_files(path, pattern)
178 local result_check = false 169 local result_check = false
179 if lfs.attributes(path) then 170 if exists(path) then
180 for file in lfs.dir(path) do 171 for file in lfs.dir(path) do
181 if file ~= "." and file ~= ".." then 172 if file ~= "." and file ~= ".." then
182 if file:find(pattern) then 173 if file:find(pattern) then
@@ -192,51 +183,44 @@ end
192 183
193 184
194--- Function for downloading rocks and rockspecs 185--- Function for downloading rocks and rockspecs
195-- @param rocks table: table with full name of rocks/rockspecs to download 186-- @param urls table: array of full names of rocks/rockspecs to download
196-- @param save_path string: path to directory, where to download rocks/rockspecs 187-- @param save_path string: path to directory, where to download rocks/rockspecs
197-- @return make_manifest boolean: true if new rocks downloaded 188-- @return make_manifest boolean: true if new rocks downloaded
198local function download_rocks(rocks, save_path) 189local function download_rocks(urls, save_path)
199 local luarocks_repo = "https://luarocks.org" 190 local luarocks_repo = "https://luarocks.org"
200 local make_manifest = false 191 local make_manifest = false
201 192
202 for _,rock in ipairs(rocks) do 193 for _, url in ipairs(urls) do
203 -- check if already downloaded 194 -- check if already downloaded
204 if not os.rename( save_path .. rock, save_path .. rock) then 195 if not exists(save_path .. url) then
205 execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. rock) 196 execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url)
206 make_manifest = true 197 make_manifest = true
207 end 198 end
208 end 199 end
209 return make_manifest 200 return make_manifest
210end 201end
211 202
212--- Create config files for testing 203--- Create a file containing a string.
213-- @param config_path string: path where to save config file 204-- @param path string: path to file.
214-- @param config_content string: content of this config file 205-- @param str string: content of the file.
215local function create_config(config_path, config_content) 206local function write_file(path, str)
216 local file, err = io.open(config_path, "w+") 207 local file = assert(io.open(path, "w"))
217 if not file then return nil, err end 208 file:write(str)
218 file:write(config_content)
219 file:close() 209 file:close()
220end 210end
221 211
222--- Create md5sum of directory structure recursively, based on filename and size 212--- Create md5sum of directory structure recursively, based on filename and size
223-- @param path string: path to directory for generate md5sum 213-- @param path string: path to directory for generate md5sum
224-- @param testing_os string(optional): version of PC OS
225-- @return md5sum string: md5sum of directory 214-- @return md5sum string: md5sum of directory
226local function hash_environment(path, testing_os) 215local function hash_environment(path)
227 local md5sum = "" 216 if test_env.TEST_TARGET_OS == "linux" then
228 testing_os = testing_os or test_env.TEST_TARGET_OS 217 return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum")
229 218 elseif test_env.TEST_TARGET_OS == "osx" then
230 if testing_os == "linux" then 219 return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5")
231 md5sum = execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") 220 else
232 end 221 -- TODO: Windows
233 if testing_os == "osx" then 222 return ""
234 md5sum = execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5")
235 end 223 end
236 --TODO if testing_os == "windows" then
237 -- md5sum = execute_output("find . -printf \"%s %p\n\" | md5sum")
238 -- end
239 return md5sum
240end 224end
241 225
242--- Create environment variables needed for tests 226--- Create environment variables needed for tests
@@ -275,51 +259,48 @@ local function create_md5sums(testing_paths)
275 return md5sums 259 return md5sums
276end 260end
277 261
278local function run_luarocks(testing_paths, env_variables) 262local function make_run_function(cmd_name, exec_function, with_coverage, do_print)
279 263 local cmd_prefix = test_env.testing_paths.lua .. " "
280 local function make_command_function(exec_function, lua_cmd, do_print) 264
281 return function(cmd, new_vars) 265 if with_coverage then
282 local temp_vars = {} 266 cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testing_dir .. "/luacov.config')\" "
283 for k, v in pairs(env_variables) do 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
284 temp_vars[k] = v 278 temp_vars[k] = v
285 end 279 end
286 if new_vars then
287 for k, v in pairs(new_vars) do
288 temp_vars[k] = v
289 end
290 end
291 return exec_function(lua_cmd .. cmd, do_print, temp_vars)
292 end 280 end
281 return exec_function(cmd_prefix .. cmd, do_print, temp_vars)
293 end 282 end
283end
294 284
295 local run = {} 285local function make_run_functions()
296 286 return {
297 local cov_str = testing_paths.lua .. " -e\"require('luacov.runner')('" .. testing_paths.testing_dir .. "/luacov.config')\" " 287 luarocks = make_run_function("luarocks", execute_output, true, true),
298 288 luarocks_bool = make_run_function("luarocks", execute_bool, true, true),
299 local luarocks_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks " 289 luarocks_noprint = make_run_function("luarocks", execute_bool, true, false),
300 run.luarocks = make_command_function(execute_output, luarocks_cmd, true) 290 luarocks_nocov = make_run_function("luarocks", execute_bool, false, true),
301 run.luarocks_bool = make_command_function(execute_bool, luarocks_cmd, true) 291 luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false),
302 run.luarocks_noprint = make_command_function(execute_bool, luarocks_cmd, false) 292 luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true),
303 293 luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true),
304 local luarocks_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks " 294 luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false)
305 run.luarocks_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, true) 295 }
306 run.luarocks_noprint_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, false)
307
308 local luarocks_admin_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks-admin "
309 run.luarocks_admin = make_command_function(execute_output, luarocks_admin_cmd, true)
310 run.luarocks_admin_bool = make_command_function(execute_bool, luarocks_admin_cmd, true)
311
312 local luarocks_admin_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks-admin "
313 run.luarocks_admin_nocov = make_command_function(execute_bool, luarocks_admin_nocov_cmd, false)
314
315 return run
316end 296end
317 297
318--- Build environment for testing 298--- Rebuild environment.
319local function build_environment(env_rocks, testing_paths, env_variables) 299-- Remove old installed rocks and install new ones,
320 print("\n--------------------") 300-- updating manifests and tree copies.
321 print("BUILDING ENVIRONMENT") 301local function build_environment(rocks, env_variables)
322 print("--------------------") 302 title("BUILDING ENVIRONMENT")
303 local testing_paths = test_env.testing_paths
323 test_env.remove_dir(testing_paths.testing_tree) 304 test_env.remove_dir(testing_paths.testing_tree)
324 test_env.remove_dir(testing_paths.testing_sys_tree) 305 test_env.remove_dir(testing_paths.testing_sys_tree)
325 test_env.remove_dir(testing_paths.testing_tree_copy) 306 test_env.remove_dir(testing_paths.testing_tree_copy)
@@ -328,14 +309,14 @@ local function build_environment(env_rocks, testing_paths, env_variables)
328 lfs.mkdir(testing_paths.testing_tree) 309 lfs.mkdir(testing_paths.testing_tree)
329 lfs.mkdir(testing_paths.testing_sys_tree) 310 lfs.mkdir(testing_paths.testing_sys_tree)
330 311
331 local run = run_luarocks(testing_paths, env_variables) 312 test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server)
332 run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) 313 test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache)
333 run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache)
334 314
335 for _,package in ipairs(env_rocks) do 315 for _, rock in ipairs(rocks) do
336 if not run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then 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
337 run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) 317 test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables)
338 run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, 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)
339 end 320 end
340 end 321 end
341 322
@@ -361,32 +342,11 @@ local function reset_environment(testing_paths, md5sums)
361end 342end
362 343
363local function create_paths(luaversion_full) 344local function create_paths(luaversion_full)
364 local testing_paths = {} 345 local cfg = require("luarocks.cfg")
365
366 testing_paths.luadir = ""
367
368 if test_env.TRAVIS then
369 testing_paths.luadir = lfs.currentdir() .. "/lua_install"
370 testing_paths.lua = testing_paths.luadir .. "/bin/lua"
371 end
372 346
373 if test_env.LUA_V and not test_env.TRAVIS then 347 local testing_paths = {}
374 if lfs.attributes("/usr/bin/lua") then 348 testing_paths.luadir = cfg.variables.LUA_BINDIR:gsub("/bin/?$", "")
375 testing_paths.luadir = "/usr" 349 testing_paths.lua = cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter
376 testing_paths.lua = testing_paths.luadir .. "/bin/lua"
377 elseif lfs.attributes("/usr/local/bin/lua") then
378 testing_paths.luadir = "/usr/local"
379 testing_paths.lua = testing_paths.luadir .. "/bin/lua"
380 end
381 elseif test_env.LUAJIT_V and not test_env.TRAVIS then
382 if lfs.attributes("/usr/bin/luajit") then
383 testing_paths.luadir = "/usr"
384 testing_paths.lua = testing_paths.luadir .. "/bin/luajit"
385 elseif lfs.attributes("/usr/local/bin/luajit") then
386 testing_paths.luadir = "/usr/local"
387 testing_paths.lua = testing_paths.luadir .. "/bin/luajit"
388 end
389 end
390 350
391 testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows? 351 testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows?
392 352
@@ -415,13 +375,11 @@ function test_env.unload_luarocks()
415end 375end
416 376
417--- Function for initially setup of environment, variables, md5sums for spec files 377--- Function for initially setup of environment, variables, md5sums for spec files
418function test_env.setup_specs(extra_rocks, luaversion_full) 378function test_env.setup_specs(extra_rocks)
419 -- if global variable about successful creation of testing environment doesn't exists, build environment 379 -- if global variable about successful creation of testing environment doesn't exists, build environment
420 if not test_env.setup_done then 380 if not test_env.setup_done then
421 test_env.set_args()
422
423 if test_env.TRAVIS then 381 if test_env.TRAVIS then
424 if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then 382 if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then
425 execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") 383 execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa")
426 execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") 384 execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys")
427 execute_bool("chmod og-wx ~/.ssh/authorized_keys") 385 execute_bool("chmod og-wx ~/.ssh/authorized_keys")
@@ -429,197 +387,213 @@ function test_env.setup_specs(extra_rocks, luaversion_full)
429 end 387 end
430 end 388 end
431 389
432 luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V
433
434 test_env.main() 390 test_env.main()
435
436 -- Set paths, env_vars and functions for specs
437 test_env.testing_paths = create_paths(luaversion_full)
438 test_env.env_variables = create_env(test_env.testing_paths)
439 package.path = test_env.env_variables.LUA_PATH 391 package.path = test_env.env_variables.LUA_PATH
440 392
441 test_env.run = run_luarocks(test_env.testing_paths, test_env.env_variables)
442 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) 393 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables)
443 test_env.md5sums = create_md5sums(test_env.testing_paths) 394 test_env.md5sums = create_md5sums(test_env.testing_paths)
444 test_env.setup_done = true 395 test_env.setup_done = true
396 title("RUNNING TESTS")
445 end 397 end
446 398
447 if extra_rocks then 399 if extra_rocks then
448 local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) 400 local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server)
449 if make_manifest then 401 if make_manifest then
450 local run = run_luarocks(test_env.testing_paths, test_env.env_variables) 402 test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server)
451 run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server)
452 end 403 end
453 end 404 end
454 405
455 reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) 406 reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables)
456
457 return true
458end 407end
459 408
460--- Helper function for tests which needs luasocket installed 409--- Helper function for tests which needs luasocket installed
461function test_env.need_luasocket(luarocks_nocov, testing_cache, platform) 410function test_env.need_luasocket()
462 luarocks_nocov = luarocks_nocov or test_env.run.luarocks_nocov 411 if test_env.run.luarocks_nocov("show luasocket") then
463 testing_cache = testing_cache or test_env.testing_paths.testing_cache
464 platform = platform or test_env.platform
465
466 if luarocks_nocov("show luasocket") then
467 return true 412 return true
468 else 413 else
469 testing_cache = testing_cache .. "/" 414 local testing_cache = test_env.testing_paths.testing_cache .. "/"
470 local luasocket_rock = "luasocket-3.0rc1-1." .. platform .. ".rock" 415 local luasocket_rock = "luasocket-3.0rc1-1." .. test_env.platform .. ".rock"
471 if not os.rename( testing_cache .. luasocket_rock, testing_cache .. luasocket_rock) then 416 if not exists(testing_cache .. luasocket_rock) then
472 luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") 417 test_env.run.luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1")
473 os.rename(luasocket_rock, testing_cache .. luasocket_rock) 418 os.rename(luasocket_rock, testing_cache .. luasocket_rock)
474 end 419 end
475 luarocks_nocov("install " .. testing_cache .. luasocket_rock) 420 return test_env.run.luarocks_nocov("install " .. testing_cache .. luasocket_rock)
476 end 421 end
477 return true 422end
423
424--- For each key-value pair in replacements table
425-- replace %{key} in given string with value.
426local function substitute(str, replacements)
427 return (str:gsub("%%%b{}", function(marker)
428 return replacements[marker:sub(3, -2)]
429 end))
430end
431
432
433--- Create configs for luacov and several versions of Luarocks
434-- configs needed for some tests.
435local 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)
518end
519
520--- Remove testing directories.
521local 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!")
528end
529
530--- Install luarocks into testing prefix.
531local 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))
478end 539end
479 540
480--- 541---
481-- Main function to create config files and testing environment 542-- Main function to create config files and testing environment
482function test_env.main(luaversion_full, env_type, env_clean) 543function test_env.main()
483 luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V 544 local testing_paths = test_env.testing_paths
484 local testing_paths = create_paths(luaversion_full) 545
485 546 if test_env.TEST_ENV_CLEAN then
486 env_clean = env_clean or test_env.TEST_ENV_CLEAN 547 clean()
487 if env_clean then
488 print("Cleaning testing directory...")
489 test_env.remove_dir(testing_paths.luarocks_tmp)
490 test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_")
491 test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-")
492 test_env.remove_files(testing_paths.testing_dir, "testing_")
493 test_env.remove_files(testing_paths.testing_dir, "luacov")
494 print("Cleaning done!")
495 end 548 end
496 549
497 lfs.mkdir(testing_paths.testing_cache) 550 lfs.mkdir(testing_paths.testing_cache)
498 lfs.mkdir(testing_paths.luarocks_tmp) 551 lfs.mkdir(testing_paths.luarocks_tmp)
499 552
500--- CONFIG FILES 553 create_configs()
501-- testing_config.lua and testing_config_show_downloads.lua
502 local config_content = ([[rocks_trees = {
503 "%{testing_tree}",
504 { name = "system", root = "%{testing_sys_tree}" },
505}
506rocks_servers = {
507 "%{testing_server}"
508}
509local_cache = "%{testing_cache}"
510upload_server = "testing"
511upload_user = "%{user}"
512upload_servers = {
513 testing = {
514 rsync = "localhost/tmp/luarocks_testing",
515 },
516}
517external_deps_dirs = {
518 "/usr/local",
519 "/usr",
520 -- These are used for a test that fails, so it
521 -- can point to invalid paths:
522 {
523 prefix = "/opt",
524 bin = "bin",
525 include = "include",
526 lib = { "lib", "lib64" },
527 }
528}]]):gsub("%%%b{}", {
529 ["%{user}"] = os.getenv("USER"),
530 ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree,
531 ["%{testing_tree}"] = testing_paths.testing_tree,
532 ["%{testing_server}"] = testing_paths.testing_server,
533 ["%{testing_cache}"] = testing_paths.testing_cache})
534
535 create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"")
536 create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content
537 .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}")
538 554
539-- testing_config_sftp.lua 555 local install_env_vars = {
540 config_content=([[rocks_trees = { 556 LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua",
541 "%{testing_tree}", 557 LUA_PATH = "",
542 "%{testing_sys_tree}", 558 LUA_CPATH = ""
543}
544local_cache = "%{testing_cache}"
545upload_server = "testing"
546upload_user = "%{user}"
547upload_servers = {
548 testing = {
549 sftp = "localhost/tmp/luarocks_testing",
550 },
551}]]):gsub("%%%b{}", {
552 ["%{user}"] = os.getenv("USER"),
553 ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree,
554 ["%{testing_tree}"] = testing_paths.testing_tree,
555 ["%{testing_cache}"] = testing_paths.testing_cache})
556
557 create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content)
558
559-- luacov.config
560 config_content=([[return {
561 statsfile = "%{testing_dir}/luacov.stats.out",
562 reportfile = "%{testing_dir}/luacov.report.out",
563 modules = {
564 ["luarocks"] = "src/bin/luarocks",
565 ["luarocks-admin"] = "src/bin/luarocks-admin",
566 ["luarocks.*"] = "src",
567 ["luarocks.*.*"] = "src",
568 ["luarocks.*.*.*"] = "src"
569 } 559 }
570}]]):gsub("%%%b{}", {
571 ["%{testing_dir}"] = testing_paths.testing_dir})
572
573 create_config(testing_paths.testing_dir .. "/luacov.config", config_content)
574 560
575 -- Create environment variables for configuration 561 install_luarocks(install_env_vars)
576 local temp_env_variables = {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua",LUA_PATH="",LUA_CPATH=""}
577
578 -- Configure LuaRocks testing environment
579 local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix
580 configure_cmd = configure_cmd .. " && make clean"
581
582 if not execute_bool(configure_cmd, false, temp_env_variables) then
583 os.exit(1)
584 end
585 if not execute_bool("make src/luarocks/site_config.lua && make dev", false, temp_env_variables) then
586 os.exit(1)
587 end
588 562
589 -- Preparation of rocks for building environment 563 -- Preparation of rocks for building environment
590 env_type = env_type or test_env.TYPE_TEST_ENV 564 local rocks = {} -- names of rocks, required for building environment
591 565 local urls = {} -- names of rock and rockspec files to be downloaded
592 local env_rocks = {} -- short names of rocks, required for building environment 566 table.insert(urls, "/luacov-0.11.0-1.rockspec")
593 local rocks = {} -- full names of rocks required for download 567 table.insert(urls, "/luacov-0.11.0-1.src.rock")
594 rocks[#rocks+1] = "/luacov-0.11.0-1.rockspec" 568
595 rocks[#rocks+1] = "/luacov-0.11.0-1.src.rock" 569 if test_env.TYPE_TEST_ENV == "full" then
596 570 table.insert(urls, "/luafilesystem-1.6.3-1.src.rock")
597 if env_type == "full" then 571 table.insert(urls, "/luasocket-3.0rc1-1.src.rock")
598 rocks[#rocks+1] = "/luafilesystem-1.6.3-1.src.rock" 572 table.insert(urls, "/luasocket-3.0rc1-1.rockspec")
599 rocks[#rocks+1] = "/luasocket-3.0rc1-1.src.rock" 573 table.insert(urls, "/luaposix-33.2.1-1.src.rock")
600 rocks[#rocks+1] = "/luasocket-3.0rc1-1.rockspec" 574 table.insert(urls, "/md5-1.2-1.src.rock")
601 rocks[#rocks+1] = "/luaposix-33.2.1-1.src.rock" 575 table.insert(urls, "/lzlib-0.4.1.53-1.src.rock")
602 rocks[#rocks+1] = "/md5-1.2-1.src.rock" 576 rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"}
603 rocks[#rocks+1] = "/lzlib-0.4.1.53-1.src.rock" 577
604 env_rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} 578 if test_env.LUA_V ~= "5.1" then
605 end 579 table.insert(urls, "/luabitop-1.0.2-1.rockspec")
606 if env_type == "full" and luaversion_full ~= "5.1.5" then 580 table.insert(urls, "/luabitop-1.0.2-1.src.rock")
607 rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" 581 table.insert(rocks, "luabitop")
608 rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" 582 end
609 table.insert(env_rocks, "luabitop")
610 end 583 end
611 584
612 table.insert(env_rocks, "luacov") -- luacov is needed for minimal or full environment 585 table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment
613 586
614 -- Download rocks needed for LuaRocks testing environment 587 -- Download rocks needed for LuaRocks testing environment
615 lfs.mkdir(testing_paths.testing_server) 588 lfs.mkdir(testing_paths.testing_server)
616 download_rocks(rocks, testing_paths.testing_server) 589 download_rocks(urls, testing_paths.testing_server)
617 590 build_environment(rocks, install_env_vars)
618 build_environment(env_rocks, testing_paths, temp_env_variables)
619
620 print("----------------")
621 print(" RUNNING TESTS")
622 print("----------------")
623end 591end
624 592
593test_env.set_lua_version()
594test_env.set_args()
595test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V)
596test_env.env_variables = create_env(test_env.testing_paths)
597test_env.run = make_run_functions()
598
625return test_env 599return test_env