summaryrefslogtreecommitdiff
path: root/tests/projects/package/requires_lock/test.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-13 22:42:51 +0800
committerruki <[email protected]>2026-01-13 22:42:51 +0800
commit168ac0bc82ab76b3fec593a944dfd9d929971838 (patch)
treee0b6770a5ce22f9aa2a5e8ffb0281f590560d876 /tests/projects/package/requires_lock/test.lua
parente8ad981e1326c6fa47242c10ff64b4b794bcf215 (diff)
fix requirelocks
Diffstat (limited to 'tests/projects/package/requires_lock/test.lua')
-rw-r--r--tests/projects/package/requires_lock/test.lua41
1 files changed, 30 insertions, 11 deletions
diff --git a/tests/projects/package/requires_lock/test.lua b/tests/projects/package/requires_lock/test.lua
index 437bff11d..ce6fadd2e 100644
--- a/tests/projects/package/requires_lock/test.lua
+++ b/tests/projects/package/requires_lock/test.lua
@@ -1,3 +1,5 @@
+import("core.project.config")
+
-- test lock file generation and basic content validation
function test_lock_file_generation(scriptdir)
local lockfile = path.join(scriptdir, "xmake-requires.lock")
@@ -27,15 +29,19 @@ function test_lock_file_generation(scriptdir)
assert(package_data.repo, "zlib should have repo info")
assert(package_data.repo.url, "zlib repo should have url")
assert(package_data.repo.commit, "zlib repo should have commit")
- elseif key:find("zlib~shared#") then
- found_zlib_shared = true
- assert(package_data.version, "zlib shared should have version")
- assert(package_data.repo, "zlib shared should have repo info")
end
end
+ -- we should have two zlib entries (one with version constraint, one with shared config)
+ local zlib_count = 0
+ for key, _ in pairs(plat_entries) do
+ if key:find("zlib") then
+ zlib_count = zlib_count + 1
+ end
+ end
+
+ assert(zlib_count == 2, "should find 2 zlib entries in lock file, found: " .. zlib_count)
assert(found_zlib, "should find zlib entry in lock file")
- assert(found_zlib_shared, "should find zlib shared entry in lock file")
print("✓ lock file generation test passed")
end
@@ -47,8 +53,8 @@ function test_lock_file_stability(scriptdir, t)
-- get the lock file content after first build
local lockdata_after_first = io.load(lockfile)
- -- remove packages and reinstall to test lock file stability
- os.rm(path.join(scriptdir, ".xmake", "packages"))
+ -- remove installed packages using xmake lua private.xrepo to trigger reinstallation
+ os.execv("xmake", {"lua", "private.xrepo", "remove", "--all", "-y", "zlib"})
-- rebuild and verify lock file content doesn't change
t:build()
@@ -57,7 +63,17 @@ function test_lock_file_stability(scriptdir, t)
-- compare lock file content
assert(lockdata_after_first.__meta__.version == lockdata_after_second.__meta__.version, "lock metadata version should not change")
- assert(table.size(lockdata_after_first) == table.size(lockdata_after_second), "lock file structure should not change")
+
+ -- count table entries properly
+ local function count_table(t)
+ local count = 0
+ for _ in pairs(t) do
+ count = count + 1
+ end
+ return count
+ end
+
+ assert(count_table(lockdata_after_first) == count_table(lockdata_after_second), "lock file structure should not change")
-- compare platform-specific entries
local plat = config.plat() or os.subhost()
@@ -67,7 +83,7 @@ function test_lock_file_stability(scriptdir, t)
local first_plat_entries = lockdata_after_first[plat_arch_key]
local second_plat_entries = lockdata_after_second[plat_arch_key]
- assert(table.size(first_plat_entries) == table.size(second_plat_entries), "platform entries count should not change")
+ assert(count_table(first_plat_entries) == count_table(second_plat_entries), "platform entries count should not change")
-- verify each package entry is identical
for key, first_data in pairs(first_plat_entries) do
@@ -93,14 +109,17 @@ function main(t)
-- build project and generate requires lock
t:build()
+ -- get script directory from context filename
+ local scriptdir = path.directory(t.filename)
+
-- test requires lock file generation and content
- test_lock_file_generation(t:scriptdir())
+ test_lock_file_generation(scriptdir)
-- test building with existing lock file
t:build()
-- test lock file stability across rebuilds
- test_lock_file_stability(t:scriptdir(), t)
+ test_lock_file_stability(scriptdir, t)
print("requires lock test passed!")
end