summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-13 22:36:44 +0800
committerruki <[email protected]>2026-01-13 22:36:44 +0800
commite8ad981e1326c6fa47242c10ff64b4b794bcf215 (patch)
tree6fc9ab324c65f92fcca79c698545c4d4d1968542
parent0569f75900e97a721cc7acbff3e9738095743d8c (diff)
add requires lock test
-rw-r--r--tests/projects/package/requires_lock/src/main.c29
-rw-r--r--tests/projects/package/requires_lock/test.lua107
-rw-r--r--tests/projects/package/requires_lock/xmake-requires.lock13
-rw-r--r--tests/projects/package/requires_lock/xmake.lua15
4 files changed, 164 insertions, 0 deletions
diff --git a/tests/projects/package/requires_lock/src/main.c b/tests/projects/package/requires_lock/src/main.c
new file mode 100644
index 000000000..911b06925
--- /dev/null
+++ b/tests/projects/package/requires_lock/src/main.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <zlib.h>
+
+int main(int argc, char** argv) {
+ printf("zlib version: %s\n", zlibVersion());
+
+ // simple compression test
+ const char* source = "Hello, zlib requires lock test!";
+ uLong sourceLen = strlen(source) + 1;
+ uLong destLen = compressBound(sourceLen);
+ Bytef* dest = (Bytef*)malloc(destLen);
+
+ if (compress(dest, &destLen, (const Bytef*)source, sourceLen) == Z_OK) {
+ printf("Compression successful, compressed size: %lu\n", destLen);
+
+ // decompression test
+ uLong decompLen = sourceLen;
+ Bytef* decomp = (Bytef*)malloc(decompLen);
+ if (uncompress(decomp, &decompLen, dest, destLen) == Z_OK) {
+ printf("Decompression successful: %s\n", (char*)decomp);
+ }
+ free(decomp);
+ }
+ free(dest);
+
+ return 0;
+}
diff --git a/tests/projects/package/requires_lock/test.lua b/tests/projects/package/requires_lock/test.lua
new file mode 100644
index 000000000..437bff11d
--- /dev/null
+++ b/tests/projects/package/requires_lock/test.lua
@@ -0,0 +1,107 @@
+-- test lock file generation and basic content validation
+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)
+ 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")
+
+ -- check platform-specific entries exist
+ 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)
+
+ -- check zlib entries
+ local plat_entries = lockdata[plat_arch_key]
+ local found_zlib = false
+ local found_zlib_shared = false
+
+ for key, package_data in pairs(plat_entries) do
+ if key:find("zlib#") then
+ found_zlib = true
+ assert(package_data.version, "zlib should have version")
+ 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
+
+ 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
+
+-- 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
+ local lockdata_after_first = io.load(lockfile)
+
+ -- remove packages and reinstall to test lock file stability
+ os.rm(path.join(scriptdir, ".xmake", "packages"))
+
+ -- rebuild and verify lock file content doesn't change
+ t:build()
+
+ local lockdata_after_second = io.load(lockfile)
+
+ -- 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")
+
+ -- compare platform-specific entries
+ local plat = config.plat() or os.subhost()
+ local arch = config.arch() or os.subarch()
+ local plat_arch_key = plat .. "|" .. arch
+
+ 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")
+
+ -- verify each package entry is identical
+ for key, first_data in pairs(first_plat_entries) do
+ local second_data = second_plat_entries[key]
+ assert(second_data, "package entry should exist: " .. key)
+ assert(first_data.version == second_data.version, "version should not change for: " .. key)
+ assert(first_data.repo.url == second_data.repo.url, "repo url should not change for: " .. key)
+ 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
+
+ print("✓ lock file stability test passed")
+end
+
+function main(t)
+ -- freebsd ci is slower
+ 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()
+
+ -- test requires lock file generation and content
+ test_lock_file_generation(t:scriptdir())
+
+ -- test building with existing lock file
+ t:build()
+
+ -- test lock file stability across rebuilds
+ test_lock_file_stability(t:scriptdir(), t)
+
+ print("requires lock test passed!")
+ end
+end
diff --git a/tests/projects/package/requires_lock/xmake-requires.lock b/tests/projects/package/requires_lock/xmake-requires.lock
new file mode 100644
index 000000000..04633257c
--- /dev/null
+++ b/tests/projects/package/requires_lock/xmake-requires.lock
@@ -0,0 +1,13 @@
+{
+ __meta__ = {
+ version = "1.0"
+ },
+ ["macosx|x86_64"] = {
+ ["zlib >=1.2.11#f56260b5"] = {
+ version = "v1.3.1"
+ },
+ ["zlib#16fb575b"] = {
+ version = "v1.3.1"
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/projects/package/requires_lock/xmake.lua b/tests/projects/package/requires_lock/xmake.lua
new file mode 100644
index 000000000..ddd56ab78
--- /dev/null
+++ b/tests/projects/package/requires_lock/xmake.lua
@@ -0,0 +1,15 @@
+-- test requires lock functionality with zlib package
+set_policy("package.requires_lock", true)
+
+add_requires("zlib >=1.2.11", {system = false})
+add_requires("zlib", {system = false, configs = {shared = true}, alias = "zlib_shared"})
+
+target("test_static")
+ set_kind("binary")
+ add_files("src/*.c")
+ add_packages("zlib")
+
+target("test_shared")
+ set_kind("binary")
+ add_files("src/*.c")
+ add_packages("zlib_shared")