diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-13 17:06:10 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-13 17:06:10 +0300 |
commit | d335afd351497ae5598eaa74c36d8b04cf69148b (patch) | |
tree | 0e34c57b069f59019bee96bf694b5b1fa380b06a | |
parent | 6f0efdcc78f793c28645850e95d5cdb33698996f (diff) | |
download | luarocks-d335afd351497ae5598eaa74c36d8b04cf69148b.tar.gz luarocks-d335afd351497ae5598eaa74c36d8b04cf69148b.tar.bz2 luarocks-d335afd351497ae5598eaa74c36d8b04cf69148b.zip |
test
-rw-r--r-- | src/luarocks/core/cfg.d.tl | 1 | ||||
-rw-r--r-- | src/luarocks/fs.d.tl | 5 | ||||
-rw-r--r-- | src/luarocks/manif.tl | 2 | ||||
-rw-r--r-- | src/luarocks/repos.tl | 81 | ||||
-rw-r--r-- | src/luarocks/test-original.lua | 100 | ||||
-rw-r--r-- | src/luarocks/test.lua | 57 | ||||
-rw-r--r-- | src/luarocks/test.tl | 5 |
7 files changed, 197 insertions, 54 deletions
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl index bd07e527..9c4d0e3f 100644 --- a/src/luarocks/core/cfg.d.tl +++ b/src/luarocks/core/cfg.d.tl | |||
@@ -76,6 +76,7 @@ local record cfg | |||
76 | -- repos | 76 | -- repos |
77 | hooks_enabled: boolean | 77 | hooks_enabled: boolean |
78 | wrap_bin_scripts: boolean | 78 | wrap_bin_scripts: boolean |
79 | wrapper_suffix: string | ||
79 | end | 80 | end |
80 | 81 | ||
81 | return cfg \ No newline at end of file | 82 | return cfg \ No newline at end of file |
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl index e946f642..4868889c 100644 --- a/src/luarocks/fs.d.tl +++ b/src/luarocks/fs.d.tl | |||
@@ -51,6 +51,11 @@ local record fs | |||
51 | command_at: function(string, string, ?boolean): string | 51 | command_at: function(string, string, ?boolean): string |
52 | -- repos | 52 | -- repos |
53 | is_actual_binary: function(string): boolean | 53 | is_actual_binary: function(string): boolean |
54 | remove_dir_tree_if_empty: function(string) | ||
55 | wrap_script: function(string, string, string, string, string): boolean, string | ||
56 | is_lua: function(string): boolean | ||
57 | copy_binary: function(string, string): boolean, string | ||
58 | move: function(string, string, string): boolean, string | ||
54 | end | 59 | end |
55 | 60 | ||
56 | return fs | 61 | return fs |
diff --git a/src/luarocks/manif.tl b/src/luarocks/manif.tl index 13c48aa8..3ce753e1 100644 --- a/src/luarocks/manif.tl +++ b/src/luarocks/manif.tl | |||
@@ -177,7 +177,7 @@ end | |||
177 | -- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. | 177 | -- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. |
178 | -- @return (string, string) or nil: name and version of the provider rock or nil if there | 178 | -- @return (string, string) or nil: name and version of the provider rock or nil if there |
179 | -- is no provider. | 179 | -- is no provider. |
180 | function manif.get_current_provider(item_type: string, item_name: string, repo: string | Tree): string, string | 180 | function manif.get_current_provider(item_type: string, item_name: string, repo?: string | Tree): string, string |
181 | local providers = get_providers(item_type, item_name, repo) | 181 | local providers = get_providers(item_type, item_name, repo) |
182 | if providers then | 182 | if providers then |
183 | return providers[1]:match("([^/]*)/([^/]*)") | 183 | return providers[1]:match("([^/]*)/([^/]*)") |
diff --git a/src/luarocks/repos.tl b/src/luarocks/repos.tl index e6044b81..5ce73831 100644 --- a/src/luarocks/repos.tl +++ b/src/luarocks/repos.tl | |||
@@ -1,6 +1,19 @@ | |||
1 | 1 | ||
2 | --- Functions for managing the repository on disk. | 2 | --- Functions for managing the repository on disk. |
3 | local record repos | 3 | local record repos |
4 | record Op | ||
5 | name: string | ||
6 | dst: string | ||
7 | backup: boolean | ||
8 | src: string | ||
9 | suffix: string | ||
10 | backup_file: string | ||
11 | fn: function(string, string, boolean): boolean, string | ||
12 | end | ||
13 | record Paths | ||
14 | nv: string | ||
15 | v: string | ||
16 | end | ||
4 | end | 17 | end |
5 | 18 | ||
6 | local fs = require("luarocks.fs") | 19 | local fs = require("luarocks.fs") |
@@ -18,6 +31,12 @@ local type Entry = RockManifest.Entry | |||
18 | local type r = require("luarocks.core.types.rockspec") | 31 | local type r = require("luarocks.core.types.rockspec") |
19 | local type Rockspec = r.Rockspec | 32 | local type Rockspec = r.Rockspec |
20 | 33 | ||
34 | local type t = require("luarocks.core.types.tree") | ||
35 | local type Tree = t.Tree | ||
36 | |||
37 | local type Op = repos.Op | ||
38 | local type Paths = repos.Paths | ||
39 | |||
21 | -- Tree of files installed by a package are stored | 40 | -- Tree of files installed by a package are stored |
22 | -- in its rock manifest. Some of these files have to | 41 | -- in its rock manifest. Some of these files have to |
23 | -- be deployed to locations where Lua can load them as | 42 | -- be deployed to locations where Lua can load them as |
@@ -194,7 +213,7 @@ function repos.should_wrap_bin_scripts(rockspec: Rockspec): boolean | |||
194 | return true | 213 | return true |
195 | end | 214 | end |
196 | 215 | ||
197 | local function find_suffixed(file: string, suffix: string) | 216 | local function find_suffixed(file: string, suffix: string): string, string |
198 | local filenames = {file} | 217 | local filenames = {file} |
199 | if suffix and suffix ~= "" then | 218 | if suffix and suffix ~= "" then |
200 | table.insert(filenames, 1, file .. suffix) | 219 | table.insert(filenames, 1, file .. suffix) |
@@ -209,7 +228,7 @@ local function find_suffixed(file: string, suffix: string) | |||
209 | return nil, table.concat(filenames, ", ") .. " not found" | 228 | return nil, table.concat(filenames, ", ") .. " not found" |
210 | end | 229 | end |
211 | 230 | ||
212 | local function check_suffix(filename, suffix) | 231 | local function check_suffix(filename: string, suffix: string): string |
213 | local suffixed_filename, err = find_suffixed(filename, suffix) | 232 | local suffixed_filename, err = find_suffixed(filename, suffix) |
214 | if not suffixed_filename then | 233 | if not suffixed_filename then |
215 | return "" | 234 | return "" |
@@ -223,20 +242,16 @@ end | |||
223 | -- item from the newest version of lexicographically smallest package | 242 | -- item from the newest version of lexicographically smallest package |
224 | -- is deployed using non-versioned name and others use versioned names. | 243 | -- is deployed using non-versioned name and others use versioned names. |
225 | 244 | ||
226 | local function get_deploy_paths(name, version, deploy_type, file_path, repo) | 245 | local function get_deploy_paths(name: string, version: string, deploy_type: string, file_path: string, repo?: string | Tree): Paths |
227 | assert(type(name) == "string") | ||
228 | assert(type(version) == "string") | ||
229 | assert(type(deploy_type) == "string") | ||
230 | assert(type(file_path) == "string") | ||
231 | 246 | ||
232 | repo = repo or cfg.root_dir | 247 | repo = repo or cfg.root_dir |
233 | local deploy_dir = path["deploy_" .. deploy_type .. "_dir"](repo) | 248 | local deploy_dir = (path as {string: function(string | Tree): string})["deploy_" .. deploy_type .. "_dir"](repo) |
234 | local non_versioned = dir.path(deploy_dir, file_path) | 249 | local non_versioned = dir.path(deploy_dir, file_path) |
235 | local versioned = path.versioned_name(non_versioned, deploy_dir, name, version) | 250 | local versioned = path.versioned_name(non_versioned, deploy_dir, name, version) |
236 | return { nv = non_versioned, v = versioned } | 251 | return { nv = non_versioned, v = versioned } |
237 | end | 252 | end |
238 | 253 | ||
239 | local function check_spot_if_available(name, version, deploy_type, file_path) | 254 | local function check_spot_if_available(name: string, version: string, deploy_type: string, file_path: string): string, string, string, string |
240 | local item_type, item_name = manif.get_provided_item(deploy_type, file_path) | 255 | local item_type, item_name = manif.get_provided_item(deploy_type, file_path) |
241 | local cur_name, cur_version = manif.get_current_provider(item_type, item_name) | 256 | local cur_name, cur_version = manif.get_current_provider(item_type, item_name) |
242 | 257 | ||
@@ -258,7 +273,7 @@ local function check_spot_if_available(name, version, deploy_type, file_path) | |||
258 | end | 273 | end |
259 | end | 274 | end |
260 | 275 | ||
261 | local function backup_existing(should_backup, target) | 276 | local function backup_existing(should_backup: boolean, target: string): string, string |
262 | if not should_backup then | 277 | if not should_backup then |
263 | fs.delete(target) | 278 | fs.delete(target) |
264 | return | 279 | return |
@@ -278,11 +293,11 @@ local function backup_existing(should_backup, target) | |||
278 | end | 293 | end |
279 | end | 294 | end |
280 | 295 | ||
281 | local function prepare_op_install() | 296 | local function prepare_op_install(): function(Op): (boolean, string), function() |
282 | local mkdirs = {} | 297 | local mkdirs = {} |
283 | local rmdirs = {} | 298 | local rmdirs = {} |
284 | 299 | ||
285 | local function memoize_mkdir(d) | 300 | local function memoize_mkdir(d: string): boolean, string |
286 | if mkdirs[d] then | 301 | if mkdirs[d] then |
287 | return true | 302 | return true |
288 | end | 303 | end |
@@ -294,7 +309,7 @@ local function prepare_op_install() | |||
294 | return true | 309 | return true |
295 | end | 310 | end |
296 | 311 | ||
297 | local function op_install(op) | 312 | local function op_install(op: Op): boolean, string |
298 | local ok, err = memoize_mkdir(dir.dir_name(op.dst)) | 313 | local ok, err = memoize_mkdir(dir.dir_name(op.dst)) |
299 | if not ok then | 314 | if not ok then |
300 | return nil, err | 315 | return nil, err |
@@ -326,7 +341,7 @@ local function prepare_op_install() | |||
326 | return op_install, done_op_install | 341 | return op_install, done_op_install |
327 | end | 342 | end |
328 | 343 | ||
329 | local function rollback_install(op) | 344 | local function rollback_install(op: Op): boolean |
330 | fs.delete(op.dst) | 345 | fs.delete(op.dst) |
331 | if op.backup_file then | 346 | if op.backup_file then |
332 | os.rename(op.backup_file, op.dst) | 347 | os.rename(op.backup_file, op.dst) |
@@ -335,7 +350,7 @@ local function rollback_install(op) | |||
335 | return true | 350 | return true |
336 | end | 351 | end |
337 | 352 | ||
338 | local function op_rename(op) | 353 | local function op_rename(op: Op): boolean, string |
339 | if op.suffix then | 354 | if op.suffix then |
340 | local suffix = check_suffix(op.src, op.suffix) | 355 | local suffix = check_suffix(op.src, op.suffix) |
341 | op.src = op.src .. suffix | 356 | op.src = op.src .. suffix |
@@ -353,13 +368,13 @@ local function op_rename(op) | |||
353 | end | 368 | end |
354 | end | 369 | end |
355 | 370 | ||
356 | local function rollback_rename(op) | 371 | local function rollback_rename(op: Op): boolean, string |
357 | return op_rename({ src = op.dst, dst = op.src }) | 372 | return op_rename({ src = op.dst, dst = op.src }) |
358 | end | 373 | end |
359 | 374 | ||
360 | local function prepare_op_delete() | 375 | local function prepare_op_delete(): function(Op), function() |
361 | local deletes = {} | 376 | local deletes: {string} = {} |
362 | local rmdirs = {} | 377 | local rmdirs: {string: boolean} = {} |
363 | 378 | ||
364 | local function done_op_delete() | 379 | local function done_op_delete() |
365 | for _, f in ipairs(deletes) do | 380 | for _, f in ipairs(deletes) do |
@@ -371,7 +386,7 @@ local function prepare_op_delete() | |||
371 | end | 386 | end |
372 | end | 387 | end |
373 | 388 | ||
374 | local function op_delete(op) | 389 | local function op_delete(op: Op) |
375 | if op.suffix then | 390 | if op.suffix then |
376 | local suffix = check_suffix(op.name, op.suffix) | 391 | local suffix = check_suffix(op.name, op.suffix) |
377 | op.name = op.name .. suffix | 392 | op.name = op.name .. suffix |
@@ -385,19 +400,19 @@ local function prepare_op_delete() | |||
385 | return op_delete, done_op_delete | 400 | return op_delete, done_op_delete |
386 | end | 401 | end |
387 | 402 | ||
388 | local function rollback_ops(ops, op_fn, n) | 403 | local function rollback_ops(ops: {Op}, op_fn: function(Op): (boolean, string), n: integer) |
389 | for i = 1, n do | 404 | for i = 1, n do |
390 | op_fn(ops[i]) | 405 | op_fn(ops[i]) |
391 | end | 406 | end |
392 | end | 407 | end |
393 | 408 | ||
394 | --- Double check that all files referenced in `rock_manifest` are installed in `repo`. | 409 | --- Double check that all files referenced in `rock_manifest` are installed in `repo`. |
395 | function repos.check_everything_is_installed(name, version, rock_manifest, repo, accept_versioned) | 410 | function repos.check_everything_is_installed(name: string, version: string, rock_manifest: {string: Entry}, repo: string | Tree, accept_versioned: boolean): boolean, string |
396 | local missing = {} | 411 | local missing = {} |
397 | local suffix = cfg.wrapper_suffix or "" | 412 | local suffix = cfg.wrapper_suffix or "" |
398 | for _, category in ipairs({"bin", "lua", "lib"}) do | 413 | for _, category in ipairs({"bin", "lua", "lib"}) do |
399 | if rock_manifest[category] then | 414 | if rock_manifest[category] then |
400 | repos.recurse_rock_manifest_entry(rock_manifest[category], function(file_path) | 415 | repos.recurse_rock_manifest_entry(rock_manifest[category], function(file_path: string): boolean, string |
401 | local paths = get_deploy_paths(name, version, category, file_path, repo) | 416 | local paths = get_deploy_paths(name, version, category, file_path, repo) |
402 | if category == "bin" then | 417 | if category == "bin" then |
403 | if (fs.exists(paths.nv) or fs.exists(paths.nv .. suffix)) | 418 | if (fs.exists(paths.nv) or fs.exists(paths.nv .. suffix)) |
@@ -428,10 +443,8 @@ end | |||
428 | -- @param deps_mode: string: Which trees to check dependencies for: | 443 | -- @param deps_mode: string: Which trees to check dependencies for: |
429 | -- "one" for the current default tree, "all" for all trees, | 444 | -- "one" for the current default tree, "all" for all trees, |
430 | -- "order" for all trees with priority >= the current default, "none" for no trees. | 445 | -- "order" for all trees with priority >= the current default, "none" for no trees. |
431 | function repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | 446 | function repos.deploy_local_files(name: string, version: string, wrap_bin_scripts: boolean, deps_mode: string): boolean, string |
432 | assert(type(name) == "string" and not name:match("/")) | 447 | assert(not name:match("/")) |
433 | assert(type(version) == "string") | ||
434 | assert(type(wrap_bin_scripts) == "boolean") | ||
435 | 448 | ||
436 | local rock_manifest, load_err = manif.load_rock_manifest(name, version) | 449 | local rock_manifest, load_err = manif.load_rock_manifest(name, version) |
437 | if not rock_manifest then return nil, load_err end | 450 | if not rock_manifest then return nil, load_err end |
@@ -440,7 +453,7 @@ function repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | |||
440 | local renames = {} | 453 | local renames = {} |
441 | local installs = {} | 454 | local installs = {} |
442 | 455 | ||
443 | local function install_binary(source, target) | 456 | local function install_binary(source: string, target: string): boolean, string |
444 | if wrap_bin_scripts and fs.is_lua(source) then | 457 | if wrap_bin_scripts and fs.is_lua(source) then |
445 | return fs.wrap_script(source, target, deps_mode, name, version) | 458 | return fs.wrap_script(source, target, deps_mode, name, version) |
446 | else | 459 | else |
@@ -448,17 +461,17 @@ function repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | |||
448 | end | 461 | end |
449 | end | 462 | end |
450 | 463 | ||
451 | local function move_lua(source, target) | 464 | local function move_lua(source: string, target: string): boolean, string |
452 | return fs.move(source, target, "read") | 465 | return fs.move(source, target, "read") |
453 | end | 466 | end |
454 | 467 | ||
455 | local function move_lib(source, target) | 468 | local function move_lib(source: string, target: string): boolean, string |
456 | return fs.move(source, target, "exec") | 469 | return fs.move(source, target, "exec") |
457 | end | 470 | end |
458 | 471 | ||
459 | if rock_manifest.bin then | 472 | if rock_manifest.bin then |
460 | local source_dir = path.bin_dir(name, version) | 473 | local source_dir = path.bin_dir(name, version) |
461 | repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path) | 474 | repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path: string): boolean, string |
462 | local source = dir.path(source_dir, file_path) | 475 | local source = dir.path(source_dir, file_path) |
463 | local paths = get_deploy_paths(name, version, "bin", file_path, repo) | 476 | local paths = get_deploy_paths(name, version, "bin", file_path, repo) |
464 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "bin", file_path) | 477 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "bin", file_path) |
@@ -478,7 +491,7 @@ function repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | |||
478 | 491 | ||
479 | if rock_manifest.lua then | 492 | if rock_manifest.lua then |
480 | local source_dir = path.lua_dir(name, version) | 493 | local source_dir = path.lua_dir(name, version) |
481 | repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path) | 494 | repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path: string): boolean, string |
482 | local source = dir.path(source_dir, file_path) | 495 | local source = dir.path(source_dir, file_path) |
483 | local paths = get_deploy_paths(name, version, "lua", file_path, repo) | 496 | local paths = get_deploy_paths(name, version, "lua", file_path, repo) |
484 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lua", file_path) | 497 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lua", file_path) |
@@ -497,7 +510,7 @@ function repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | |||
497 | 510 | ||
498 | if rock_manifest.lib then | 511 | if rock_manifest.lib then |
499 | local source_dir = path.lib_dir(name, version) | 512 | local source_dir = path.lib_dir(name, version) |
500 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path) | 513 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path: string): boolean, string |
501 | local source = dir.path(source_dir, file_path) | 514 | local source = dir.path(source_dir, file_path) |
502 | local paths = get_deploy_paths(name, version, "lib", file_path, repo) | 515 | local paths = get_deploy_paths(name, version, "lib", file_path, repo) |
503 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lib", file_path) | 516 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lib", file_path) |
@@ -681,4 +694,4 @@ function repos.delete_local_version(name, version, deps_mode, quick) | |||
681 | return true, nil, "remove" | 694 | return true, nil, "remove" |
682 | end | 695 | end |
683 | 696 | ||
684 | return repos | 697 | return rep \ No newline at end of file |
diff --git a/src/luarocks/test-original.lua b/src/luarocks/test-original.lua new file mode 100644 index 00000000..d074b950 --- /dev/null +++ b/src/luarocks/test-original.lua | |||
@@ -0,0 +1,100 @@ | |||
1 | |||
2 | local test = {} | ||
3 | |||
4 | local fetch = require("luarocks.fetch") | ||
5 | local deps = require("luarocks.deps") | ||
6 | local util = require("luarocks.util") | ||
7 | |||
8 | local test_types = { | ||
9 | "busted", | ||
10 | "command", | ||
11 | } | ||
12 | |||
13 | local test_modules = {} | ||
14 | |||
15 | for _, test_type in ipairs(test_types) do | ||
16 | local mod = require("luarocks.test." .. test_type) | ||
17 | table.insert(test_modules, mod) | ||
18 | test_modules[test_type] = mod | ||
19 | test_modules[mod] = test_type | ||
20 | end | ||
21 | |||
22 | local function get_test_type(rockspec) | ||
23 | if rockspec.test and rockspec.test.type then | ||
24 | return rockspec.test.type | ||
25 | end | ||
26 | |||
27 | for _, test_module in ipairs(test_modules) do | ||
28 | if test_module.detect_type() then | ||
29 | return test_modules[test_module] | ||
30 | end | ||
31 | end | ||
32 | |||
33 | return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?" | ||
34 | end | ||
35 | |||
36 | -- Run test suite as configured in rockspec in the current directory. | ||
37 | function test.run_test_suite(rockspec_arg, test_type, args, prepare) | ||
38 | local rockspec | ||
39 | if type(rockspec_arg) == "string" then | ||
40 | local err, errcode | ||
41 | rockspec, err, errcode = fetch.load_rockspec(rockspec_arg) | ||
42 | if err then | ||
43 | return nil, err, errcode | ||
44 | end | ||
45 | else | ||
46 | assert(type(rockspec_arg) == "table") | ||
47 | rockspec = rockspec_arg | ||
48 | end | ||
49 | |||
50 | if not test_type then | ||
51 | local err | ||
52 | test_type, err = get_test_type(rockspec, test_type) | ||
53 | if not test_type then | ||
54 | return nil, err | ||
55 | end | ||
56 | end | ||
57 | assert(test_type) | ||
58 | |||
59 | local all_deps = { | ||
60 | "dependencies", | ||
61 | "build_dependencies", | ||
62 | "test_dependencies", | ||
63 | } | ||
64 | for _, dep_kind in ipairs(all_deps) do | ||
65 | if rockspec[dep_kind] and next(rockspec[dep_kind]) then | ||
66 | local ok, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") | ||
67 | if err then | ||
68 | return nil, err, errcode | ||
69 | end | ||
70 | end | ||
71 | end | ||
72 | |||
73 | local mod_name = "luarocks.test." .. test_type | ||
74 | local pok, test_mod = pcall(require, mod_name) | ||
75 | if not pok then | ||
76 | return nil, "failed loading test execution module " .. mod_name | ||
77 | end | ||
78 | |||
79 | if prepare then | ||
80 | if test_type == "busted" then | ||
81 | return test_mod.run_tests(rockspec_arg, {"--version"}) | ||
82 | else | ||
83 | return true | ||
84 | end | ||
85 | else | ||
86 | local flags = rockspec.test and rockspec.test.flags | ||
87 | if type(flags) == "table" then | ||
88 | util.variable_substitutions(flags, rockspec.variables) | ||
89 | |||
90 | -- insert any flags given in test.flags at the front of args | ||
91 | for i = 1, #flags do | ||
92 | table.insert(args, i, flags[i]) | ||
93 | end | ||
94 | end | ||
95 | |||
96 | return test_mod.run_tests(rockspec.test, args) | ||
97 | end | ||
98 | end | ||
99 | |||
100 | return test | ||
diff --git a/src/luarocks/test.lua b/src/luarocks/test.lua index d074b950..762b98b5 100644 --- a/src/luarocks/test.lua +++ b/src/luarocks/test.lua | |||
@@ -1,10 +1,24 @@ | |||
1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pcall = _tl_compat and _tl_compat.pcall or pcall; local table = _tl_compat and _tl_compat.table or table; local test = {TestModules = {}, } | ||
2 | |||
3 | |||
4 | |||
5 | |||
6 | |||
1 | 7 | ||
2 | local test = {} | ||
3 | 8 | ||
4 | local fetch = require("luarocks.fetch") | 9 | local fetch = require("luarocks.fetch") |
5 | local deps = require("luarocks.deps") | 10 | local deps = require("luarocks.deps") |
6 | local util = require("luarocks.util") | 11 | local util = require("luarocks.util") |
7 | 12 | ||
13 | |||
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
20 | |||
21 | |||
8 | local test_types = { | 22 | local test_types = { |
9 | "busted", | 23 | "busted", |
10 | "command", | 24 | "command", |
@@ -13,10 +27,15 @@ local test_types = { | |||
13 | local test_modules = {} | 27 | local test_modules = {} |
14 | 28 | ||
15 | for _, test_type in ipairs(test_types) do | 29 | for _, test_type in ipairs(test_types) do |
16 | local mod = require("luarocks.test." .. test_type) | 30 | local mod |
31 | if test_type == "command" then | ||
32 | mod = require("luarocks.test.command") | ||
33 | elseif test_type == "busted" then | ||
34 | mod = require("luarocks.test.busted") | ||
35 | end | ||
17 | table.insert(test_modules, mod) | 36 | table.insert(test_modules, mod) |
18 | test_modules[test_type] = mod | 37 | test_modules.typetomod[test_type] = mod |
19 | test_modules[mod] = test_type | 38 | test_modules.modtotype[mod] = test_type |
20 | end | 39 | end |
21 | 40 | ||
22 | local function get_test_type(rockspec) | 41 | local function get_test_type(rockspec) |
@@ -26,14 +45,14 @@ local function get_test_type(rockspec) | |||
26 | 45 | ||
27 | for _, test_module in ipairs(test_modules) do | 46 | for _, test_module in ipairs(test_modules) do |
28 | if test_module.detect_type() then | 47 | if test_module.detect_type() then |
29 | return test_modules[test_module] | 48 | return test_modules.modtotype[test_module] |
30 | end | 49 | end |
31 | end | 50 | end |
32 | 51 | ||
33 | return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?" | 52 | return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?" |
34 | end | 53 | end |
35 | 54 | ||
36 | -- Run test suite as configured in rockspec in the current directory. | 55 | |
37 | function test.run_test_suite(rockspec_arg, test_type, args, prepare) | 56 | function test.run_test_suite(rockspec_arg, test_type, args, prepare) |
38 | local rockspec | 57 | local rockspec |
39 | if type(rockspec_arg) == "string" then | 58 | if type(rockspec_arg) == "string" then |
@@ -43,13 +62,12 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare) | |||
43 | return nil, err, errcode | 62 | return nil, err, errcode |
44 | end | 63 | end |
45 | else | 64 | else |
46 | assert(type(rockspec_arg) == "table") | ||
47 | rockspec = rockspec_arg | 65 | rockspec = rockspec_arg |
48 | end | 66 | end |
49 | 67 | ||
50 | if not test_type then | 68 | if not test_type then |
51 | local err | 69 | local err |
52 | test_type, err = get_test_type(rockspec, test_type) | 70 | test_type, err = get_test_type(rockspec) |
53 | if not test_type then | 71 | if not test_type then |
54 | return nil, err | 72 | return nil, err |
55 | end | 73 | end |
@@ -62,23 +80,30 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare) | |||
62 | "test_dependencies", | 80 | "test_dependencies", |
63 | } | 81 | } |
64 | for _, dep_kind in ipairs(all_deps) do | 82 | for _, dep_kind in ipairs(all_deps) do |
65 | if rockspec[dep_kind] and next(rockspec[dep_kind]) then | 83 | if (rockspec)[dep_kind] and next((rockspec)[dep_kind]) ~= nil then |
66 | local ok, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") | 84 | local _, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") |
67 | if err then | 85 | if err then |
68 | return nil, err, errcode | 86 | return nil, err, errcode |
69 | end | 87 | end |
70 | end | 88 | end |
71 | end | 89 | end |
72 | 90 | ||
73 | local mod_name = "luarocks.test." .. test_type | 91 | local pok, test_mod |
74 | local pok, test_mod = pcall(require, mod_name) | 92 | if test_type == "command" then |
75 | if not pok then | 93 | pok, test_mod = pcall(require, "luarocks.test.command") |
76 | return nil, "failed loading test execution module " .. mod_name | 94 | if not pok then |
95 | return nil, "failed loading test execution module luarocks.test.command" | ||
96 | end | ||
97 | elseif test_type == "busted" then | ||
98 | pok, test_mod = pcall(require, "luarocks.test.busted") | ||
99 | if not pok then | ||
100 | return nil, "failed loading test execution module luarocks.test.busted" | ||
101 | end | ||
77 | end | 102 | end |
78 | 103 | ||
79 | if prepare then | 104 | if prepare then |
80 | if test_type == "busted" then | 105 | if test_type == "busted" then |
81 | return test_mod.run_tests(rockspec_arg, {"--version"}) | 106 | return test_mod.run_tests(rockspec.test, { "--version" }) |
82 | else | 107 | else |
83 | return true | 108 | return true |
84 | end | 109 | end |
@@ -87,7 +112,7 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare) | |||
87 | if type(flags) == "table" then | 112 | if type(flags) == "table" then |
88 | util.variable_substitutions(flags, rockspec.variables) | 113 | util.variable_substitutions(flags, rockspec.variables) |
89 | 114 | ||
90 | -- insert any flags given in test.flags at the front of args | 115 | |
91 | for i = 1, #flags do | 116 | for i = 1, #flags do |
92 | table.insert(args, i, flags[i]) | 117 | table.insert(args, i, flags[i]) |
93 | end | 118 | end |
diff --git a/src/luarocks/test.tl b/src/luarocks/test.tl index 83bb4517..86d572d8 100644 --- a/src/luarocks/test.tl +++ b/src/luarocks/test.tl | |||
@@ -13,7 +13,6 @@ local util = require("luarocks.util") | |||
13 | local type r = require("luarocks.core.types.rockspec") | 13 | local type r = require("luarocks.core.types.rockspec") |
14 | local type Rockspec = r.Rockspec | 14 | local type Rockspec = r.Rockspec |
15 | local type Dependencies = r.Dependencies | 15 | local type Dependencies = r.Dependencies |
16 | local type Test = r.Test | ||
17 | 16 | ||
18 | local type t = require("luarocks.core.types.testrunner") | 17 | local type t = require("luarocks.core.types.testrunner") |
19 | local type TestRunner = t.TestRunner | 18 | local type TestRunner = t.TestRunner |
@@ -68,7 +67,7 @@ function test.run_test_suite(rockspec_arg: string | Rockspec, test_type: string, | |||
68 | 67 | ||
69 | if not test_type then | 68 | if not test_type then |
70 | local err: string | 69 | local err: string |
71 | test_type, err = get_test_type(rockspec, test_type) --! | 70 | test_type, err = get_test_type(rockspec) |
72 | if not test_type then | 71 | if not test_type then |
73 | return nil, err | 72 | return nil, err |
74 | end | 73 | end |
@@ -104,7 +103,7 @@ function test.run_test_suite(rockspec_arg: string | Rockspec, test_type: string, | |||
104 | 103 | ||
105 | if prepare then | 104 | if prepare then |
106 | if test_type == "busted" then | 105 | if test_type == "busted" then |
107 | return test_mod.run_tests(rockspec_arg, {"--version"}) | 106 | return test_mod.run_tests(rockspec.test, {"--version"}) |
108 | else | 107 | else |
109 | return true | 108 | return true |
110 | end | 109 | end |