Skip to content

Commit

Permalink
test: rework internal asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
DifferentialOrange committed Mar 21, 2023
1 parent e0576c2 commit d922704
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
version-pre-extraction-hook: |
local rock_utils = require('test.rock_utils')
rock_utils.remove_builtin('metrics')
require('metrics')
rock_utils.assert_nonbuiltin('metrics')
package:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/push_rockspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
version-pre-extraction-hook: |
local rock_utils = require('test.rock_utils')
rock_utils.remove_builtin('metrics')
require('metrics')
rock_utils.assert_nonbuiltin('metrics')
push-scm-rockspec:
Expand Down
1 change: 0 additions & 1 deletion test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ require('strict').on()
-- Clean up built-in metrics to run tests with repository module.
local rock_utils = require('test.rock_utils')
rock_utils.remove_builtin('metrics')
require('metrics')
rock_utils.assert_nonbuiltin('metrics')


Expand Down
21 changes: 19 additions & 2 deletions test/rock_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local function traverse_rock(func, name)
end
end

-- Metrics may have table cross-references.
-- Package may have table cross-references.
local MAX_DEPTH = 8

-- Package functions contain useful debug info.
Expand Down Expand Up @@ -39,8 +39,12 @@ local function traverse_pkg_func(func, name, pkg, max_depth)
end
end

local function remove_builtin_pkg(name, _)
local function remove_loaded_pkg(name, _)
package.loaded[name] = nil
end

local function remove_builtin_pkg(name, _)
remove_loaded_pkg(name)
if loaders_ok then
loaders.builtin[name] = nil
end
Expand Down Expand Up @@ -70,16 +74,29 @@ local function remove_builtin_rock(name)
traverse_rock(remove_builtin_pkg, name)
end

local function remove_loaded_rock(name)
traverse_rock(remove_loaded_pkg, name)
end

local function remove_override_rock(name)
loaders.override_builtin_disable()
traverse_rock(remove_loaded_pkg, name)
end

local function assert_nonbuiltin_rock(name)
require(name)
traverse_rock(assert_nonbuiltin_pkg, name)
end

local function assert_builtin_rock(name)
require(name)
traverse_rock(assert_builtin_pkg, name)
end

return {
assert_builtin = assert_builtin_rock,
assert_nonbuiltin = assert_nonbuiltin_rock,
remove_builtin = remove_builtin_rock,
remove_loaded = remove_loaded_rock,
remove_override = remove_override_rock,
}

0 comments on commit d922704

Please sign in to comment.