From d9227043e616b0e5621b510f0846b93813ba2896 Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Mon, 20 Mar 2023 18:18:32 +0300 Subject: [PATCH] test: rework internal asserts --- .github/workflows/packaging.yml | 1 - .github/workflows/push_rockspec.yml | 1 - test/helper.lua | 1 - test/rock_utils.lua | 21 +++++++++++++++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml index 2f4ffa78..3119bc17 100644 --- a/.github/workflows/packaging.yml +++ b/.github/workflows/packaging.yml @@ -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: diff --git a/.github/workflows/push_rockspec.yml b/.github/workflows/push_rockspec.yml index c3d9a0f6..462474df 100644 --- a/.github/workflows/push_rockspec.yml +++ b/.github/workflows/push_rockspec.yml @@ -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: diff --git a/test/helper.lua b/test/helper.lua index eff6451b..f27ca481 100644 --- a/test/helper.lua +++ b/test/helper.lua @@ -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') diff --git a/test/rock_utils.lua b/test/rock_utils.lua index e9d2f260..7f4b49dc 100644 --- a/test/rock_utils.lua +++ b/test/rock_utils.lua @@ -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. @@ -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 @@ -70,11 +74,22 @@ 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 @@ -82,4 +97,6 @@ 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, }