diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-03-30 15:22:09 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-03-30 19:52:17 -0300 |
commit | 2dc0a68c941d883753b2d6715921a8952f95204b (patch) | |
tree | 57c45b68dfd9041ad6484aac1f3be0b11ac706ce /spec | |
parent | 43adf5df7465c39a9f6fc735654aabac991cabb5 (diff) | |
download | luarocks-2dc0a68c941d883753b2d6715921a8952f95204b.tar.gz luarocks-2dc0a68c941d883753b2d6715921a8952f95204b.tar.bz2 luarocks-2dc0a68c941d883753b2d6715921a8952f95204b.zip |
Tests: run our own local git-daemon repository for git tests
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fetch_spec.lua | 33 | ||||
-rw-r--r-- | spec/util/git_repo.lua | 107 | ||||
-rw-r--r-- | spec/util/test_env.lua | 24 | ||||
-rw-r--r-- | spec/write_rockspec_spec.lua | 107 |
4 files changed, 217 insertions, 54 deletions
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index 59f73b57..5f518e4d 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua | |||
@@ -1,4 +1,5 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local git_repo = require("spec.util.git_repo") | ||
2 | 3 | ||
3 | test_env.unload_luarocks() | 4 | test_env.unload_luarocks() |
4 | local fetch = require("luarocks.fetch") | 5 | local fetch = require("luarocks.fetch") |
@@ -6,23 +7,35 @@ local vers = require("luarocks.vers") | |||
6 | 7 | ||
7 | describe("Luarocks fetch test #whitebox #w_fetch", function() | 8 | describe("Luarocks fetch test #whitebox #w_fetch", function() |
8 | it("Fetch url to base dir", function() | 9 | it("Fetch url to base dir", function() |
9 | assert.are.same("v0.3", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) | 10 | assert.are.same("v0.3", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) |
10 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) | 11 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2.zip")) |
11 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) | 12 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2.tar.gz")) |
12 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) | 13 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2.tar.bz2")) |
13 | assert.are.same("parser.moon", fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) | 14 | assert.are.same("parser.moon", fetch.url_to_base_dir("git://example.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")) | 15 | assert.are.same("v0.3", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2/archive/v0.3")) |
15 | end) | 16 | end) |
16 | 17 | ||
17 | describe("fetch_sources", function() | 18 | describe("fetch_sources #unix #git", function() |
18 | it("from Git", function() | 19 | local git |
20 | |||
21 | setup(function() | ||
22 | git = git_repo.start() | ||
23 | end) | ||
24 | |||
25 | teardown(function() | ||
26 | if git then | ||
27 | git:stop() | ||
28 | end | ||
29 | end) | ||
30 | |||
31 | it("from #git", function() | ||
19 | local rockspec = { | 32 | local rockspec = { |
20 | format_is_at_least = vers.format_is_at_least, | 33 | format_is_at_least = vers.format_is_at_least, |
21 | name = "testrock", | 34 | name = "testrock", |
22 | version = "dev-1", | 35 | version = "dev-1", |
23 | source = { | 36 | source = { |
24 | protocol = "git", | 37 | protocol = "git", |
25 | url = "git://github.com/luarocks/testrock", | 38 | url = "git://localhost:20000/testrock", |
26 | }, | 39 | }, |
27 | variables = { | 40 | variables = { |
28 | GIT = "git", | 41 | GIT = "git", |
@@ -31,7 +44,7 @@ describe("Luarocks fetch test #whitebox #w_fetch", function() | |||
31 | local pathname, tmpdir = fetch.fetch_sources(rockspec, false) | 44 | local pathname, tmpdir = fetch.fetch_sources(rockspec, false) |
32 | assert.are.same("testrock", pathname) | 45 | assert.are.same("testrock", pathname) |
33 | assert.match("luarocks_testrock%-dev%-1%-", tmpdir) | 46 | assert.match("luarocks_testrock%-dev%-1%-", tmpdir) |
34 | assert.match("^%d%d%d%d%d%d%d%d.%d%d%d%d%d%d.%x+$", rockspec.source.identifier) | 47 | assert.match("^%d%d%d%d%d%d%d%d.%d%d%d%d%d%d.%x+$", tostring(rockspec.source.identifier)) |
35 | end) | 48 | end) |
36 | end) | 49 | end) |
37 | 50 | ||
diff --git a/spec/util/git_repo.lua b/spec/util/git_repo.lua new file mode 100644 index 00000000..6cccfcc4 --- /dev/null +++ b/spec/util/git_repo.lua | |||
@@ -0,0 +1,107 @@ | |||
1 | local git_repo = {} | ||
2 | |||
3 | local test_env = require("spec.util.test_env") | ||
4 | local lfs = require("lfs") | ||
5 | |||
6 | local files = { | ||
7 | ---------------------------------------- | ||
8 | ["testrock-dev-1.rockspec"] = [[ | ||
9 | package = "testrock" | ||
10 | version = "dev-1" | ||
11 | source = { | ||
12 | url = "git://localhost:20000/testrock" | ||
13 | } | ||
14 | description = { | ||
15 | homepage = "https://localhost", | ||
16 | license = "MIT" | ||
17 | } | ||
18 | dependencies = {} | ||
19 | build = { | ||
20 | type = "builtin", | ||
21 | modules = { | ||
22 | testrock = "testrock.lua" | ||
23 | } | ||
24 | } | ||
25 | ]], | ||
26 | ---------------------------------------- | ||
27 | ["testrock.lua"] = [[ | ||
28 | local testrock = {} | ||
29 | |||
30 | function testrock.say() | ||
31 | return "Hello, world!" | ||
32 | end | ||
33 | |||
34 | return testrock | ||
35 | ]], | ||
36 | ---------------------------------------- | ||
37 | ["foo.c"] = [[ | ||
38 | #include <lua.h> | ||
39 | int luaopen_foo(lua_State* L) { | ||
40 | lua_pushnumber(L, 42); | ||
41 | return 1; | ||
42 | } | ||
43 | ]], | ||
44 | ---------------------------------------- | ||
45 | ["test.lua"] = [[ | ||
46 | print("this should be ignored!") | ||
47 | ]], | ||
48 | } | ||
49 | |||
50 | local function write_file(filename, contents) | ||
51 | local fd = assert(io.open(filename, "w")) | ||
52 | assert(fd:write(contents)) | ||
53 | fd:close() | ||
54 | end | ||
55 | |||
56 | local function handling(args) | ||
57 | local pok, ret = pcall(args.try) | ||
58 | if not pok then | ||
59 | pok, ret = pcall(args.catch, ret) | ||
60 | end | ||
61 | args.finally() | ||
62 | if not pok then | ||
63 | error(ret) | ||
64 | end | ||
65 | return ret | ||
66 | end | ||
67 | |||
68 | function git_repo.start() | ||
69 | local dir = lfs.currentdir() | ||
70 | return handling { | ||
71 | try = function() | ||
72 | local pidfile = os.tmpname() | ||
73 | local basedir = test_env.testing_paths.testrun_dir .. "/git_repo" | ||
74 | local repodir = basedir .. "/testrock" | ||
75 | test_env.remove_dir(basedir) | ||
76 | lfs.mkdir(basedir) | ||
77 | lfs.mkdir(repodir) | ||
78 | lfs.chdir(repodir) | ||
79 | assert(test_env.execute("git init")) | ||
80 | for name, contents in pairs(files) do | ||
81 | write_file(name, contents) | ||
82 | test_env.execute("git add " .. name) | ||
83 | end | ||
84 | assert(test_env.execute("git commit -a -m 'initial commit'")) | ||
85 | print("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &") | ||
86 | assert(test_env.execute("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &")) | ||
87 | assert(test_env.execute("sleep 0.1; netstat -ln | grep '0.0.0.0:9418 .* LISTEN'")) | ||
88 | return { | ||
89 | stop = function() | ||
90 | local fd = io.open(pidfile) | ||
91 | local pid = fd:read("*a") | ||
92 | fd:close() | ||
93 | assert(test_env.execute("kill -HUP " .. pid)) | ||
94 | test_env.remove_dir(basedir) | ||
95 | end | ||
96 | } | ||
97 | end, | ||
98 | catch = function(err) | ||
99 | error(err) | ||
100 | end, | ||
101 | finally = function() | ||
102 | lfs.chdir(dir) | ||
103 | end, | ||
104 | } | ||
105 | end | ||
106 | |||
107 | return git_repo | ||
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 2232de87..e318128e 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
@@ -1,6 +1,7 @@ | |||
1 | local lfs = require("lfs") | ||
2 | local test_env = {} | 1 | local test_env = {} |
3 | 2 | ||
3 | local lfs = require("lfs") | ||
4 | |||
4 | local help_message = [[ | 5 | local help_message = [[ |
5 | LuaRocks test-suite | 6 | LuaRocks test-suite |
6 | 7 | ||
@@ -135,6 +136,11 @@ function test_env.execute_helper(command, print_command, env_variables) | |||
135 | return final_command | 136 | return final_command |
136 | end | 137 | end |
137 | 138 | ||
139 | function test_env.execute(cmd) | ||
140 | local ok = os.execute(cmd) | ||
141 | return (ok == true or ok == 0) -- normalize Lua 5.1 output to boolean | ||
142 | end | ||
143 | |||
138 | --- Execute command and returns true/false | 144 | --- Execute command and returns true/false |
139 | -- @return true/false boolean: status of the command execution | 145 | -- @return true/false boolean: status of the command execution |
140 | local function execute_bool(command, print_command, env_variables) | 146 | local function execute_bool(command, print_command, env_variables) |
@@ -147,8 +153,7 @@ local function execute_bool(command, print_command, env_variables) | |||
147 | redirect = " > "..redirect_filename | 153 | redirect = " > "..redirect_filename |
148 | os.remove(redirect_filename) | 154 | os.remove(redirect_filename) |
149 | end | 155 | end |
150 | local ok = os.execute(command .. redirect) | 156 | local ok = test_env.execute(command .. redirect) |
151 | ok = (ok == true or ok == 0) -- normalize Lua 5.1 output to boolean | ||
152 | if redirect ~= "" then | 157 | if redirect ~= "" then |
153 | if not ok then | 158 | if not ok then |
154 | local fd = io.open(redirect_filename, "r") | 159 | local fd = io.open(redirect_filename, "r") |
@@ -530,9 +535,13 @@ function test_env.unload_luarocks() | |||
530 | package.loaded[modname] = nil | 535 | package.loaded[modname] = nil |
531 | end | 536 | end |
532 | end | 537 | end |
538 | local src_pattern = test_env.testing_paths.src_dir .. "/?.lua" | ||
539 | if not package.path:find(src_pattern, 1, true) then | ||
540 | package.path = src_pattern .. ";" .. package.path | ||
541 | end | ||
533 | end | 542 | end |
534 | 543 | ||
535 | --- Function for initially setup of environment, variables, md5sums for spec files | 544 | --- Function for initial setup of environment, variables, md5sums for spec files |
536 | function test_env.setup_specs(extra_rocks) | 545 | function test_env.setup_specs(extra_rocks) |
537 | -- if global variable about successful creation of testing environment doesn't exist, build environment | 546 | -- if global variable about successful creation of testing environment doesn't exist, build environment |
538 | if not test_env.setup_done then | 547 | if not test_env.setup_done then |
@@ -546,6 +555,10 @@ function test_env.setup_specs(extra_rocks) | |||
546 | end | 555 | end |
547 | 556 | ||
548 | test_env.main() | 557 | test_env.main() |
558 | |||
559 | -- preload before meddling with package.path | ||
560 | require("spec.util.git_repo") | ||
561 | |||
549 | package.path = test_env.env_variables.LUA_PATH | 562 | package.path = test_env.env_variables.LUA_PATH |
550 | 563 | ||
551 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables) | 564 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables) |
@@ -744,9 +757,8 @@ function test_env.mock_server_extra_rocks(more) | |||
744 | end | 757 | end |
745 | 758 | ||
746 | function test_env.mock_server_init() | 759 | function test_env.mock_server_init() |
747 | local assert = require("luassert") | ||
748 | local testing_paths = test_env.testing_paths | 760 | local testing_paths = test_env.testing_paths |
749 | assert.is_true(test_env.need_rock("restserver-xavante")) | 761 | assert(test_env.need_rock("restserver-xavante")) |
750 | local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua &", true, test_env.env_variables) | 762 | local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua &", true, test_env.env_variables) |
751 | os.execute(final_command) | 763 | os.execute(final_command) |
752 | end | 764 | end |
diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index 9ee86ada..e4a7fa73 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua | |||
@@ -1,8 +1,9 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local git_repo = require("spec.util.git_repo") | ||
2 | local lfs = require("lfs") | 3 | local lfs = require("lfs") |
3 | local run = test_env.run | 4 | local run = test_env.run |
4 | 5 | ||
5 | test_env.unload_luarocks() | 6 | local extra_rocks = test_env.mock_server_extra_rocks() |
6 | 7 | ||
7 | describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() | 8 | describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() |
8 | 9 | ||
@@ -10,63 +11,93 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() | |||
10 | test_env.setup_specs() | 11 | test_env.setup_specs() |
11 | end) | 12 | end) |
12 | 13 | ||
13 | describe("LuaRocks write_rockspec basic tests", function() | 14 | it("runs with no flags/arguments", function() |
14 | it("LuaRocks write_rockspec with no flags/arguments", function() | 15 | local d = lfs.currentdir() |
15 | assert.is_true(run.luarocks_bool("write_rockspec")) | 16 | finally(function() |
16 | os.remove("luarocks-dev-1.rockspec") | 17 | os.remove("testrock-dev-1.rockspec") |
18 | lfs.chdir(d) | ||
17 | end) | 19 | end) |
20 | lfs.chdir("..") | ||
21 | assert.is_true(run.luarocks_bool("write_rockspec")) | ||
22 | end) | ||
18 | 23 | ||
19 | it("LuaRocks write_rockspec with invalid argument", function() | 24 | it("fails with invalid argument", function() |
20 | assert.is_false(run.luarocks_bool("write_rockspec invalid")) | 25 | assert.is_false(run.luarocks_bool("write_rockspec invalid")) |
26 | end) | ||
27 | |||
28 | it("fails with invalid zip", function() | ||
29 | assert.is_false(run.luarocks_bool("write_rockspec http://example.com/invalid.zip")) | ||
30 | end) | ||
31 | |||
32 | describe("from #git #unix", function() | ||
33 | local git | ||
34 | |||
35 | setup(function() | ||
36 | git = git_repo.start() | ||
21 | end) | 37 | end) |
22 | 38 | ||
23 | it("LuaRocks write_rockspec invalid zip", function() | 39 | teardown(function() |
24 | assert.is_false(run.luarocks_bool("write_rockspec http://example.com/invalid.zip")) | 40 | git:stop() |
25 | end) | 41 | end) |
26 | end) | ||
27 | 42 | ||
28 | describe("LuaRocks write_rockspec more complex tests", function() | 43 | it("runs", function() |
29 | it("LuaRocks write_rockspec git luarocks", function() | 44 | finally(function() os.remove("testrock-dev-1.rockspec") end) |
30 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock")) | 45 | assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock")) |
31 | assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) | 46 | assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) |
32 | assert.is_true(os.remove("testrock-dev-1.rockspec")) | ||
33 | end) | 47 | end) |
34 | 48 | ||
35 | it("LuaRocks write_rockspec git luarocks --tag=v2.3.0", function() | 49 | it("runs with --tag", function() |
36 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --tag=v2.3.0")) | 50 | finally(function() os.remove("testrock-2.3.0-1.rockspec") end) |
51 | assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock --tag=v2.3.0")) | ||
37 | assert.is.truthy(lfs.attributes("testrock-2.3.0-1.rockspec")) | 52 | assert.is.truthy(lfs.attributes("testrock-2.3.0-1.rockspec")) |
38 | assert.is_true(os.remove("testrock-2.3.0-1.rockspec")) | 53 | -- TODO check contents |
39 | end) | 54 | end) |
40 | 55 | ||
41 | it("LuaRocks write_rockspec git luarocks with format flag", function() | 56 | it("runs with format flag", function() |
42 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --rockspec-format=1.1 --lua-version=5.1,5.2")) | 57 | finally(function() os.remove("testrock-dev-1.rockspec") end) |
58 | assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock --rockspec-format=1.1 --lua-version=5.1,5.2")) | ||
43 | assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) | 59 | assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) |
44 | assert.is_true(os.remove("testrock-dev-1.rockspec")) | 60 | -- TODO check contents |
45 | end) | 61 | end) |
46 | 62 | ||
47 | it("LuaRocks write_rockspec git luarocks with full flags", function() | 63 | it("runs with full flags", function() |
48 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --lua-version=5.1,5.2 --license=\"MIT/X11\" " | 64 | finally(function() os.remove("testrock-dev-1.rockspec") end) |
65 | assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock --lua-version=5.1,5.2 --license=\"MIT/X11\" " | ||
49 | .. " --homepage=\"http://www.luarocks.org\" --summary=\"A package manager for Lua modules\" ")) | 66 | .. " --homepage=\"http://www.luarocks.org\" --summary=\"A package manager for Lua modules\" ")) |
50 | assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) | 67 | assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) |
51 | assert.is_true(os.remove("testrock-dev-1.rockspec")) | 68 | -- TODO check contents |
52 | end) | 69 | end) |
53 | 70 | ||
54 | it("LuaRocks write_rockspec rockspec via http", function() | 71 | it("with various flags", function() |
55 | assert.is_true(run.luarocks_bool("write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1")) | 72 | finally(function() os.remove("testrock-dev-1.rockspec") end) |
56 | assert.is.truthy(lfs.attributes("luarocks-2.1.0-1.rockspec")) | 73 | assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock --lib=fcgi --license=\"3-clause BSD\" " .. "--lua-version=5.1,5.2")) |
57 | assert.is_true(os.remove("luarocks-2.1.0-1.rockspec")) | 74 | assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) |
75 | -- TODO check contents | ||
58 | end) | 76 | end) |
59 | 77 | end) | |
60 | it("LuaRocks write_rockspec base dir, luassert.tar.gz via https", function() | 78 | |
61 | assert.is_true(run.luarocks_bool("write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1")) | 79 | describe("from tarball #mock", function() |
62 | assert.is.truthy(lfs.attributes("luassert-1.2-1.rockspec")) | 80 | |
63 | assert.is_true(os.remove("luassert-1.2-1.rockspec")) | 81 | setup(function() |
82 | test_env.setup_specs(extra_rocks) | ||
83 | test_env.mock_server_init() | ||
64 | end) | 84 | end) |
65 | 85 | teardown(function() | |
66 | it("LuaRocks write_rockspec git luafcgi with many flags", function() | 86 | test_env.mock_server_done() |
67 | assert.is_true(run.luarocks_bool("write_rockspec git://github.com/arcapos/luafcgi --lib=fcgi --license=\"3-clause BSD\" " .. "--lua-version=5.1,5.2")) | 87 | end) |
68 | assert.is.truthy(lfs.attributes("luafcgi-dev-1.rockspec")) -- TODO maybe read it content and find arguments from flags? | 88 | |
69 | assert.is_true(os.remove("luafcgi-dev-1.rockspec")) | 89 | it("via http", function() |
90 | finally(function() os.remove("an_upstream_tarball-0.1-1.rockspec") end) | ||
91 | assert.is_true(run.luarocks_bool("write_rockspec http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz --lua-version=5.1")) | ||
92 | assert.is.truthy(lfs.attributes("an_upstream_tarball-0.1-1.rockspec")) | ||
93 | -- TODO check contents | ||
94 | end) | ||
95 | |||
96 | it("with a different basedir", function() | ||
97 | finally(function() os.remove("renamed_upstream_tarball-0.1-1.rockspec") end) | ||
98 | assert.is_true(run.luarocks_bool("write_rockspec http://localhost:8080/file/renamed_upstream_tarball-0.1.tar.gz --lua-version=5.1")) | ||
99 | assert.is.truthy(lfs.attributes("renamed_upstream_tarball-0.1-1.rockspec")) | ||
100 | -- TODO check contents | ||
70 | end) | 101 | end) |
71 | end) | 102 | end) |
72 | end) | 103 | end) |