aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Roman <george.roman.99@gmail.com>2018-07-04 16:24:33 +0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-18 11:22:43 -0300
commit619296451e96608bae10b868c864b31108d0ee79 (patch)
treeacff3e97f3eab24ad5f7e99f8352f7d9c88ea9db
parent97bee5e84b0258ae5f25c038a85a54c6b621d5ce (diff)
downloadluarocks-619296451e96608bae10b868c864b31108d0ee79.tar.gz
luarocks-619296451e96608bae10b868c864b31108d0ee79.tar.bz2
luarocks-619296451e96608bae10b868c864b31108d0ee79.zip
Tests: use fixtures for some build integration tests
-rw-r--r--spec/build_spec.lua104
1 files changed, 80 insertions, 24 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua
index 53c338f9..982db801 100644
--- a/spec/build_spec.lua
+++ b/spec/build_spec.lua
@@ -6,6 +6,8 @@ local testing_paths = test_env.testing_paths
6local write_file = test_env.write_file 6local write_file = test_env.write_file
7 7
8test_env.unload_luarocks() 8test_env.unload_luarocks()
9local cfg = require("luarocks.core.cfg")
10local fs = require("luarocks.fs")
9 11
10local extra_rocks = { 12local extra_rocks = {
11 "/lmathx-20120430.51-1.src.rock", 13 "/lmathx-20120430.51-1.src.rock",
@@ -16,7 +18,6 @@ local extra_rocks = {
16 "/lmathx-20150505-1.rockspec", 18 "/lmathx-20150505-1.rockspec",
17 "/lpeg-1.0.0-1.rockspec", 19 "/lpeg-1.0.0-1.rockspec",
18 "/lpeg-1.0.0-1.src.rock", 20 "/lpeg-1.0.0-1.src.rock",
19 "/lpty-1.0.1-1.src.rock",
20 "/luafilesystem-1.6.3-1.src.rock", 21 "/luafilesystem-1.6.3-1.src.rock",
21 "/lualogging-1.3.0-1.src.rock", 22 "/lualogging-1.3.0-1.src.rock",
22 "/luasec-0.6-1.rockspec", 23 "/luasec-0.6-1.rockspec",
@@ -41,6 +42,10 @@ local c_module_source = [[
41]] 42]]
42 43
43describe("LuaRocks build tests #integration", function() 44describe("LuaRocks build tests #integration", function()
45 setup(function()
46 cfg.init()
47 fs.init()
48 end)
44 49
45 before_each(function() 50 before_each(function()
46 test_env.setup_specs(extra_rocks) 51 test_env.setup_specs(extra_rocks)
@@ -80,21 +85,43 @@ describe("LuaRocks build tests #integration", function()
80 end) 85 end)
81 end) 86 end)
82 87
83 describe("LuaRocks build - building lpeg with flags", function() 88 describe("LuaRocks build - building with flags", function()
84 it("LuaRocks build fail build permissions", function() 89 it("LuaRocks build fails if it doesn't have the permissions to access the specified tree #unix", function()
85 if test_env.TEST_TARGET_OS == "osx" or test_env.TEST_TARGET_OS == "linux" then 90 assert.is_false(run.luarocks_bool("build --tree=/usr " .. testing_paths.fixtures_dir .. "/a_rock-1.0.1-rockspec"))
86 assert.is_false(run.luarocks_bool("build --tree=/usr lpeg")) 91 assert.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec"))
87 end
88 end) 92 end)
89 93
90 it("LuaRocks build fail build permissions parent", function() 94 it("LuaRocks build fails if it doesn't have the permissions to access the specified tree's parent #unix", function()
91 if test_env.TEST_TARGET_OS == "osx" or test_env.TEST_TARGET_OS == "linux" then 95 assert.is_false(run.luarocks_bool("build --tree=/usr/invalid " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec"))
92 assert.is_false(run.luarocks_bool("build --tree=/usr/invalid lpeg")) 96 assert.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec"))
93 end
94 end) 97 end)
95 98
96 it("LuaRocks build lpeg verbose", function() 99 it("LuaRocks build verbose", function()
97 assert.is_true(run.luarocks_bool("build --verbose lpeg")) 100 local olddir = lfs.currentdir()
101 local tmpdir = get_tmp_path()
102 lfs.mkdir(tmpdir)
103 lfs.chdir(tmpdir)
104
105 write_file("test-1.0-1.rockspec", [[
106 package = "test"
107 version = "1.0-1"
108 source = {
109 url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua"
110 }
111 build = {
112 type = "builtin",
113 modules = {
114 test = "test.lua"
115 }
116 }
117 ]], finally)
118 write_file("test.lua", "return {}", finally)
119
120 assert.is_true(run.luarocks_bool("build --verbose test-1.0-1.rockspec"))
121 assert.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec"))
122
123 lfs.chdir(olddir)
124 lfs.rmdir(tmpdir)
98 end) 125 end)
99 126
100 it("LuaRocks build lpeg branch=master", function() 127 it("LuaRocks build lpeg branch=master", function()
@@ -103,9 +130,9 @@ describe("LuaRocks build tests #integration", function()
103 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) 130 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec"))
104 end) 131 end)
105 132
106 it("LuaRocks build lpeg deps-mode=123", function() 133 it("LuaRocks build fails if the deps-mode argument is invalid", function()
107 assert.is_false(run.luarocks_bool("build --deps-mode=123 lpeg --verbose")) 134 assert.is_false(run.luarocks_bool("build --deps-mode=123 " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec"))
108 assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) 135 assert.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec"))
109 end) 136 end)
110 137
111 it("LuaRocks build lpeg only-sources example", function() 138 it("LuaRocks build lpeg only-sources example", function()
@@ -121,9 +148,9 @@ describe("LuaRocks build tests #integration", function()
121 assert.is_true(os.remove("lpeg-1.0.0-1.src.rock")) 148 assert.is_true(os.remove("lpeg-1.0.0-1.src.rock"))
122 end) 149 end)
123 150
124 it("LuaRocks build lpeg with empty tree", function() 151 it("LuaRocks build fails if an empty tree is given", function()
125 assert.is_false(run.luarocks_bool("build --tree=\"\" lpeg")) 152 assert.is_false(run.luarocks_bool("build --tree=\"\" " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec"))
126 assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) 153 assert.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec"))
127 end) 154 end)
128 end) 155 end)
129 156
@@ -138,13 +165,40 @@ describe("LuaRocks build tests #integration", function()
138 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/stdlib/41.0.0-1/stdlib-41.0.0-1.rockspec")) 165 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/stdlib/41.0.0-1/stdlib-41.0.0-1.rockspec"))
139 end) 166 end)
140 167
141 it("LuaRocks build supported platforms lpty", function() 168 it("LuaRocks build fails if the current platform is not supported", function()
169 local olddir = lfs.currentdir()
170 local tmpdir = get_tmp_path()
171 lfs.mkdir(tmpdir)
172 lfs.chdir(tmpdir)
173
174 write_file("test-1.0-1.rockspec", [[
175 package = "test"
176 version = "1.0-1"
177 source = {
178 url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua"
179 }
180 supported_platforms = {
181 "unix", "macosx"
182 }
183 build = {
184 type = "builtin",
185 modules = {
186 test = "test.lua"
187 }
188 }
189 ]], finally)
190 write_file("test.lua", "return {}", finally)
191
142 if test_env.TEST_TARGET_OS == "windows" then 192 if test_env.TEST_TARGET_OS == "windows" then
143 assert.is_false(run.luarocks_bool("build lpty")) --Error: This rockspec for lpty does not support win32, windows platforms 193 assert.is_false(run.luarocks_bool("build test-1.0-1.rockspec")) -- Error: This rockspec does not support windows platforms
194 assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec"))
144 else 195 else
145 assert.is_true(run.luarocks_bool("build lpty")) 196 assert.is_true(run.luarocks_bool("build test-1.0-1.rockspec"))
146 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpty/1.0.1-1/lpty-1.0.1-1.rockspec")) 197 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec"))
147 end 198 end
199
200 lfs.chdir(olddir)
201 lfs.rmdir(tmpdir)
148 end) 202 end)
149 203
150 it("LuaRocks build luasec with skipping dependency checks", function() 204 it("LuaRocks build luasec with skipping dependency checks", function()
@@ -244,7 +298,7 @@ describe("LuaRocks build tests #integration", function()
244 assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) 298 assert.is_true(os.remove("validate-args-1.5.4-1.rockspec"))
245 end) 299 end)
246 300
247 it("LuaRocks build invalid patch", function() 301 it("LuaRocks build fails if given an argument with an invalid patch", function()
248 assert.is_false(run.luarocks_bool("build " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec")) 302 assert.is_false(run.luarocks_bool("build " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec"))
249 end) 303 end)
250 end) 304 end)
@@ -351,7 +405,7 @@ describe("LuaRocks build tests #integration", function()
351 setup(function() 405 setup(function()
352 test_env.mock_server_init() 406 test_env.mock_server_init()
353 end) 407 end)
354 408
355 teardown(function() 409 teardown(function()
356 test_env.mock_server_done() 410 test_env.mock_server_done()
357 end) 411 end)
@@ -566,6 +620,7 @@ describe("LuaRocks build tests #unit", function()
566 after_each(function() 620 after_each(function()
567 if olddir then 621 if olddir then
568 lfs.chdir(olddir) 622 lfs.chdir(olddir)
623 fs.change_dir(olddir)
569 if tmpdir then 624 if tmpdir then
570 lfs.rmdir(tmpdir) 625 lfs.rmdir(tmpdir)
571 end 626 end
@@ -678,6 +733,7 @@ describe("LuaRocks build tests #unit", function()
678 after_each(function() 733 after_each(function()
679 if olddir then 734 if olddir then
680 lfs.chdir(olddir) 735 lfs.chdir(olddir)
736 fs.change_dir(olddir)
681 if tmpdir then 737 if tmpdir then
682 lfs.rmdir(tmpdir) 738 lfs.rmdir(tmpdir)
683 end 739 end