summaryrefslogtreecommitdiff
path: root/tests/projects/package/requires_lock/test.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-13 22:46:54 +0800
committerruki <[email protected]>2026-01-13 22:46:54 +0800
commit46687b17c49e44c69264fd1d899cf297475b924b (patch)
tree9799b4a9e4424b08fe0e3f46a1e057c87cbcfde0 /tests/projects/package/requires_lock/test.lua
parent1dc17c218aa04c3a4fa7b74be0dfff6fc9b31809 (diff)
update format
Diffstat (limited to 'tests/projects/package/requires_lock/test.lua')
-rw-r--r--tests/projects/package/requires_lock/test.lua57
1 files changed, 33 insertions, 24 deletions
diff --git a/tests/projects/package/requires_lock/test.lua b/tests/projects/package/requires_lock/test.lua
index bdf42b3d4..224301f72 100644
--- a/tests/projects/package/requires_lock/test.lua
+++ b/tests/projects/package/requires_lock/test.lua
@@ -25,12 +25,12 @@ local function verify_lock_file_structure(lockdata)
assert(lockdata, "lock file should be loadable")
assert(lockdata.__meta__, "lock file should have metadata")
assert(lockdata.__meta__.version == "1.0", "lock file version should be 1.0")
-
+
local plat = config.plat() or os.subhost()
local arch = config.arch() or os.subarch()
local plat_arch_key = plat .. "|" .. arch
assert(lockdata[plat_arch_key], "should have entries for current platform: " .. plat_arch_key)
-
+
return lockdata[plat_arch_key]
end
@@ -49,11 +49,11 @@ end
function test_lock_file_generation(scriptdir)
local lockfile = path.join(scriptdir, "xmake-requires.lock")
assert(os.isfile(lockfile), "xmake-requires.lock should be generated")
-
+
-- load and verify lock file content
local lockdata = io.load(lockfile)
local plat_entries = verify_lock_file_structure(lockdata)
-
+
-- check zlib entries and repo info
local found_zlib = false
for key, package_data in pairs(plat_entries) do
@@ -65,12 +65,12 @@ function test_lock_file_generation(scriptdir)
assert(package_data.repo.commit, "zlib repo should have commit")
end
end
-
+
-- we should have three zlib entries (version constraint, specific version, shared config)
local zlib_count = count_zlib_entries(plat_entries)
assert(zlib_count == 3, "should find 3 zlib entries in lock file, found: " .. zlib_count)
assert(found_zlib, "should find zlib entry in lock file")
-
+
-- verify specific versions are locked correctly
local found_old_version = false
for key, package_data in pairs(plat_entries) do
@@ -80,43 +80,45 @@ function test_lock_file_generation(scriptdir)
end
end
assert(found_old_version, "should find zlib 1.2.13 entry with v1.2.13")
-
+
print("✓ lock file generation test passed")
end
-- test lock file stability across rebuilds
function test_lock_file_stability(scriptdir, t)
local lockfile = path.join(scriptdir, "xmake-requires.lock")
-
- -- get the lock file content after first build
+
+ -- get the lock file content and mtime after first build
local lockdata_after_first = io.load(lockfile)
+ local mtime_after_first = os.mtime(lockfile)
local keys_after_first = get_package_keys(lockdata_after_first)
-
+
-- 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()
-
+
local lockdata_after_second = io.load(lockfile)
+ local mtime_after_second = os.mtime(lockfile)
local keys_after_second = get_package_keys(lockdata_after_second)
-
+
-- compare lock file content
assert(lockdata_after_first.__meta__.version == lockdata_after_second.__meta__.version, "lock metadata version should not change")
assert(count_table(lockdata_after_first) == count_table(lockdata_after_second), "lock file structure should not change")
-
+
-- compare platform-specific entries
local plat_entries_after_first = verify_lock_file_structure(lockdata_after_first)
local plat_entries_after_second = verify_lock_file_structure(lockdata_after_second)
-
+
assert(count_table(plat_entries_after_first) == count_table(plat_entries_after_second), "platform entries count should not change")
-
+
-- verify package key order stability (keys should be in same order)
assert(#keys_after_first == #keys_after_second, "package keys count should be the same")
for i, key in ipairs(keys_after_first) do
assert(keys_after_second[i] == key, "package key order should be stable at index " .. i .. ": " .. key)
end
-
+
-- verify each package entry is identical
for key, first_data in pairs(plat_entries_after_first) do
local second_data = plat_entries_after_second[key]
@@ -126,7 +128,14 @@ function test_lock_file_stability(scriptdir, t)
assert(first_data.repo.commit == second_data.repo.commit, "repo commit should not change for: " .. key)
assert(first_data.repo.branch == second_data.repo.branch, "repo branch should not change for: " .. key)
end
-
+
+ -- verify mtime doesn't change (lock file should only be written when content actually changes)
+ -- With copy_if_different, the file should not be rewritten if content is identical
+ local time_diff = math.abs(mtime_after_second - mtime_after_first)
+ print("lock file mtime difference: " .. time_diff .. "s")
+ -- mtime should be exactly the same when content is identical
+ assert(time_diff == 0, "lock file mtime should not change when content is identical, diff: " .. time_diff .. "s")
+
print("✓ lock file stability test passed")
end
@@ -135,24 +144,24 @@ function main(t)
if is_host("bsd", "solaris") then
return
end
-
+
-- only for x86/x64, because it will take too long time on ci with arm/mips
if os.subarch():startswith("x") or os.subarch() == "i386" then
-- 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(scriptdir)
-
+
-- test building with existing lock file
t:build()
-
+
-- test lock file stability across rebuilds
test_lock_file_stability(scriptdir, t)
-
+
print("requires lock test passed!")
end
end