diff options
-rw-r--r-- | spec/test_spec.lua | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/spec/test_spec.lua b/spec/test_spec.lua index ffcf2ac0..0111f89a 100644 --- a/spec/test_spec.lua +++ b/spec/test_spec.lua | |||
@@ -1,7 +1,9 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local lfs = require("lfs") | 2 | local lfs = require("lfs") |
3 | local get_tmp_path = test_env.get_tmp_path | ||
3 | local run = test_env.run | 4 | local run = test_env.run |
4 | local testing_paths = test_env.testing_paths | 5 | local testing_paths = test_env.testing_paths |
6 | local write_file = test_env.write_file | ||
5 | 7 | ||
6 | test_env.unload_luarocks() | 8 | test_env.unload_luarocks() |
7 | 9 | ||
@@ -76,3 +78,171 @@ describe("luarocks test #integration", function() | |||
76 | end) | 78 | end) |
77 | end) | 79 | end) |
78 | end) | 80 | end) |
81 | |||
82 | test_env.unload_luarocks() | ||
83 | |||
84 | local fs = require("luarocks.fs") | ||
85 | local path = require("luarocks.path") | ||
86 | local test = require("luarocks.test") | ||
87 | local test_busted = require("luarocks.test.busted") | ||
88 | local test_command = require("luarocks.test.command") | ||
89 | |||
90 | describe("LuaRocks test #unit", function() | ||
91 | local runner | ||
92 | |||
93 | setup(function() | ||
94 | runner = require("luacov.runner") | ||
95 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
96 | runner.tick = true | ||
97 | end) | ||
98 | |||
99 | teardown(function() | ||
100 | runner.shutdown() | ||
101 | end) | ||
102 | |||
103 | local tmpdir | ||
104 | local olddir | ||
105 | |||
106 | local create_tmp_dir = function() | ||
107 | tmpdir = get_tmp_path() | ||
108 | olddir = lfs.currentdir() | ||
109 | lfs.mkdir(tmpdir) | ||
110 | lfs.chdir(tmpdir) | ||
111 | fs.change_dir(tmpdir) | ||
112 | end | ||
113 | |||
114 | local destroy_tmp_dir = function() | ||
115 | if olddir then | ||
116 | lfs.chdir(olddir) | ||
117 | if tmpdir then | ||
118 | lfs.rmdir(tmpdir) | ||
119 | end | ||
120 | end | ||
121 | end | ||
122 | |||
123 | describe("test.command", function() | ||
124 | describe("command.detect_type", function() | ||
125 | before_each(function() | ||
126 | create_tmp_dir() | ||
127 | end) | ||
128 | |||
129 | after_each(function() | ||
130 | destroy_tmp_dir() | ||
131 | end) | ||
132 | |||
133 | it("returns true if test.lua exists", function() | ||
134 | write_file("test.lua", "", finally) | ||
135 | assert.truthy(test_command.detect_type()) | ||
136 | end) | ||
137 | |||
138 | it("returns false if test.lua doesn't exist", function() | ||
139 | assert.falsy(test_command.detect_type()) | ||
140 | end) | ||
141 | end) | ||
142 | |||
143 | describe("command.run_tests", function() | ||
144 | before_each(function() | ||
145 | create_tmp_dir() | ||
146 | end) | ||
147 | |||
148 | after_each(function() | ||
149 | destroy_tmp_dir() | ||
150 | end) | ||
151 | |||
152 | it("returns the result of the executed tests", function() | ||
153 | write_file("test.lua", "assert(1==1)", finally) | ||
154 | assert.truthy(test_command.run_tests(nil, {})) | ||
155 | |||
156 | write_file("test.lua", "assert(1==2)", finally) | ||
157 | assert.falsy(test_command.run_tests(nil, {})) | ||
158 | end) | ||
159 | |||
160 | it("returns the result of the executed tests with custom arguments and test command", function() | ||
161 | write_file("test.lua", "assert(1==1)", finally) | ||
162 | |||
163 | local test = { | ||
164 | script = "test.lua", | ||
165 | flags = { | ||
166 | arg1 = "1", | ||
167 | arg2 = "2" | ||
168 | }, | ||
169 | command = fs.Q(testing_paths.lua) | ||
170 | } | ||
171 | assert.truthy(test_command.run_tests(test, {})) | ||
172 | end) | ||
173 | |||
174 | it("returns false and does nothing if the test script doesn't exist", function() | ||
175 | assert.falsy(test_command.run_tests(nil, {})) | ||
176 | end) | ||
177 | end) | ||
178 | end) | ||
179 | |||
180 | describe("test.busted", function() | ||
181 | describe("busted.detect_type", function() | ||
182 | before_each(function() | ||
183 | create_tmp_dir() | ||
184 | end) | ||
185 | |||
186 | after_each(function() | ||
187 | destroy_tmp_dir() | ||
188 | end) | ||
189 | |||
190 | it("returns true if .busted exists", function() | ||
191 | write_file(".busted", "", finally) | ||
192 | assert.truthy(test_busted.detect_type()) | ||
193 | end) | ||
194 | |||
195 | it("returns false if .busted doesn't exist", function() | ||
196 | assert.falsy(test_busted.detect_type()) | ||
197 | end) | ||
198 | end) | ||
199 | |||
200 | describe("busted.run_tests", function() | ||
201 | before_each(function() | ||
202 | path.use_tree(testing_paths.testing_sys_tree) | ||
203 | create_tmp_dir() | ||
204 | end) | ||
205 | |||
206 | after_each(function() | ||
207 | destroy_tmp_dir() | ||
208 | end) | ||
209 | |||
210 | pending("returns the result of the executed tests", function() | ||
211 | -- FIXME: busted issue | ||
212 | write_file("test_spec.lua", "assert(1==1)", finally) | ||
213 | assert.truthy(test_busted.run_tests(nil, {})) | ||
214 | |||
215 | write_file("test_spec.lua", "assert(1==2)", finally) | ||
216 | assert.falsy(test_busted.run_tests()) | ||
217 | end) | ||
218 | end) | ||
219 | end) | ||
220 | |||
221 | describe("test", function() | ||
222 | describe("test.run_test_suite", function() | ||
223 | before_each(function() | ||
224 | create_tmp_dir() | ||
225 | end) | ||
226 | |||
227 | after_each(function() | ||
228 | destroy_tmp_dir() | ||
229 | end) | ||
230 | |||
231 | it("returns false if the given rockspec cannot be loaded", function() | ||
232 | assert.falsy(test.run_test_suite("invalid", nil, {})) | ||
233 | end) | ||
234 | |||
235 | it("returns false if no test type was detected", function() | ||
236 | assert.falsy(test.run_test_suite({ package = "test" }, nil, {})) | ||
237 | end) | ||
238 | |||
239 | it("returns the result of executing the tests specified in the given rockspec", function() | ||
240 | write_file("test.lua", "assert(1==1)", finally) | ||
241 | assert.truthy(test.run_test_suite({ test_dependencies = {} }, nil, {})) | ||
242 | |||
243 | write_file("test.lua", "assert(1==2)", finally) | ||
244 | assert.falsy(test.run_test_suite({ test_dependencies = {} }, nil, {})) | ||
245 | end) | ||
246 | end) | ||
247 | end) | ||
248 | end) | ||