diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2023-10-31 21:28:45 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-31 21:28:45 -0300 |
commit | 4cfcf9d8df1abd7cca9f2c3590402ada543df327 (patch) | |
tree | 84ca4100af7fe6d64bd53a7badefc27f436772d0 /spec | |
parent | 82cca3c53aeedfa5ed1415f3a63e6d85117a8264 (diff) | |
download | luarocks-4cfcf9d8df1abd7cca9f2c3590402ada543df327.tar.gz luarocks-4cfcf9d8df1abd7cca9f2c3590402ada543df327.tar.bz2 luarocks-4cfcf9d8df1abd7cca9f2c3590402ada543df327.zip |
feat: auto-add luarocks-build-<build.type> build dependency (#1542)
Diffstat (limited to 'spec')
-rw-r--r-- | spec/rockspecs_spec.lua | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/spec/rockspecs_spec.lua b/spec/rockspecs_spec.lua new file mode 100644 index 00000000..76b33f65 --- /dev/null +++ b/spec/rockspecs_spec.lua | |||
@@ -0,0 +1,126 @@ | |||
1 | |||
2 | local rockspecs = require("luarocks.rockspecs") | ||
3 | local cfg = require("luarocks.core.cfg") | ||
4 | local test_env = require("spec.util.test_env") | ||
5 | local lfs = require("lfs") | ||
6 | |||
7 | describe("luarocks.rockspecs", function() | ||
8 | |||
9 | setup(function() | ||
10 | cfg.init() | ||
11 | end) | ||
12 | |||
13 | it("auto adds a build dependency for non-vendored build types", function() | ||
14 | local filename = "test-1.0-1.rockspec" | ||
15 | local rockspec = { | ||
16 | package = "test", | ||
17 | source = { | ||
18 | url = "", | ||
19 | }, | ||
20 | build = { | ||
21 | type = "foo" | ||
22 | }, | ||
23 | } | ||
24 | local globals = {} | ||
25 | local quick = true | ||
26 | |||
27 | local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick) | ||
28 | |||
29 | assert(rockspec == out) | ||
30 | assert.same(rockspec.build_dependencies, { | ||
31 | { name = "luarocks-build-foo", constraints = {} }, | ||
32 | }) | ||
33 | end) | ||
34 | |||
35 | it("does not add a build dependency for non-vendored build type if it's already ther", function() | ||
36 | local filename = "test-1.0-1.rockspec" | ||
37 | local rockspec = { | ||
38 | package = "test", | ||
39 | source = { | ||
40 | url = "", | ||
41 | }, | ||
42 | build_dependencies = { | ||
43 | "luarocks-build-cpp >= 1.0", | ||
44 | }, | ||
45 | build = { | ||
46 | type = "cpp" | ||
47 | }, | ||
48 | } | ||
49 | local globals = {} | ||
50 | local quick = true | ||
51 | |||
52 | local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick) | ||
53 | |||
54 | assert(rockspec == out) | ||
55 | |||
56 | assert.same(rockspec.build_dependencies, { | ||
57 | { name = "luarocks-build-cpp", constraints = { { op = ">=", version = { string = "1.0", 1, 0 } } } }, | ||
58 | }) | ||
59 | end) | ||
60 | |||
61 | it("does not add a build dependency for 'none' build type", function() | ||
62 | local filename = "test-1.0-1.rockspec" | ||
63 | local rockspec = { | ||
64 | package = "test", | ||
65 | source = { | ||
66 | url = "", | ||
67 | }, | ||
68 | build = { | ||
69 | type = "none" | ||
70 | }, | ||
71 | } | ||
72 | local globals = {} | ||
73 | local quick = true | ||
74 | |||
75 | local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick) | ||
76 | |||
77 | assert(rockspec == out) | ||
78 | assert.same(rockspec.build_dependencies, {}) | ||
79 | end) | ||
80 | |||
81 | it("does not add a build dependency for 'module' build type", function() | ||
82 | local filename = "test-1.0-1.rockspec" | ||
83 | local rockspec = { | ||
84 | package = "test", | ||
85 | source = { | ||
86 | url = "", | ||
87 | }, | ||
88 | build = { | ||
89 | type = "none" | ||
90 | }, | ||
91 | } | ||
92 | local globals = {} | ||
93 | local quick = true | ||
94 | |||
95 | local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick) | ||
96 | |||
97 | assert(rockspec == out) | ||
98 | assert.same(rockspec.build_dependencies, {}) | ||
99 | end) | ||
100 | |||
101 | for d in lfs.dir(test_env.testing_paths.src_dir .. "/luarocks/build") do | ||
102 | local name = d:match("(.*)%.lua") | ||
103 | if name then | ||
104 | it("does not add a build dependency for vendored '" .. name .. "' type", function() | ||
105 | local filename = "test-1.0-1.rockspec" | ||
106 | local rockspec = { | ||
107 | package = "test", | ||
108 | source = { | ||
109 | url = "", | ||
110 | }, | ||
111 | build = { | ||
112 | type = name | ||
113 | }, | ||
114 | } | ||
115 | local globals = {} | ||
116 | local quick = true | ||
117 | |||
118 | local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick) | ||
119 | |||
120 | assert(rockspec == out) | ||
121 | assert.same(rockspec.build_dependencies, {}) | ||
122 | end) | ||
123 | end | ||
124 | end | ||
125 | |||
126 | end) | ||