From da447ac2ab5de57880d1179f5d3df7638ab5af23 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 16 Aug 2026 08:56:36 +0800 Subject: add packages test for addon --- tests/actions/addon/custom-package/addon.lua | 2 ++ .../includes/packages/src/include/hello_utils.h | 7 +++++++ .../addon/custom-package/includes/packages/xmake.lua | 13 +++++++++++++ tests/actions/addon/projects/custom-package/src/main.c | 7 +++++++ tests/actions/addon/projects/custom-package/xmake.lua | 9 +++++++++ tests/actions/addon/test.lua | 16 ++++++++++++++++ 6 files changed, 54 insertions(+) create mode 100644 tests/actions/addon/custom-package/addon.lua create mode 100644 tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h create mode 100644 tests/actions/addon/custom-package/includes/packages/xmake.lua create mode 100644 tests/actions/addon/projects/custom-package/src/main.c create mode 100644 tests/actions/addon/projects/custom-package/xmake.lua diff --git a/tests/actions/addon/custom-package/addon.lua b/tests/actions/addon/custom-package/addon.lua new file mode 100644 index 000000000..56d8300f3 --- /dev/null +++ b/tests/actions/addon/custom-package/addon.lua @@ -0,0 +1,2 @@ +addon("custom-package") + set_description("the addon which provides a custom package") diff --git a/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h b/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h new file mode 100644 index 000000000..c7b9e86b1 --- /dev/null +++ b/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h @@ -0,0 +1,7 @@ +#pragma once +#include + +static inline void hello_utils_greeting(void) +{ + printf("hello from the custom package!\n"); +} diff --git a/tests/actions/addon/custom-package/includes/packages/xmake.lua b/tests/actions/addon/custom-package/includes/packages/xmake.lua new file mode 100644 index 000000000..5a02187fd --- /dev/null +++ b/tests/actions/addon/custom-package/includes/packages/xmake.lua @@ -0,0 +1,13 @@ +-- an addon can ship the package definitions, so that a project only needs +-- includes("@addon/custom-package/packages") and add_requires("hello-utils") +package("hello-utils") + set_kind("library", {headeronly = true}) + set_description("the custom package of the tests") + + -- the sources are shipped by this addon, so it can be installed offline + set_sourcedir(path.join(os.scriptdir(), "src")) + + on_install(function (package) + os.cp("include", package:installdir()) + end) +package_end() diff --git a/tests/actions/addon/projects/custom-package/src/main.c b/tests/actions/addon/projects/custom-package/src/main.c new file mode 100644 index 000000000..3edd2a8cb --- /dev/null +++ b/tests/actions/addon/projects/custom-package/src/main.c @@ -0,0 +1,7 @@ +#include + +int main(int argc, char** argv) +{ + hello_utils_greeting(); + return 0; +} diff --git a/tests/actions/addon/projects/custom-package/xmake.lua b/tests/actions/addon/projects/custom-package/xmake.lua new file mode 100644 index 000000000..1c967020d --- /dev/null +++ b/tests/actions/addon/projects/custom-package/xmake.lua @@ -0,0 +1,9 @@ +-- the package definitions come from the addon +includes("@addon/custom-package/packages") + +add_requires("hello-utils") + +target("test") + set_kind("binary") + add_files("src/main.c") + add_packages("hello-utils") diff --git a/tests/actions/addon/test.lua b/tests/actions/addon/test.lua index 192230b08..0b80a62e9 100644 --- a/tests/actions/addon/test.lua +++ b/tests/actions/addon/test.lua @@ -239,6 +239,22 @@ function test_template(t) end) end +-- an addon can ship the package definitions in its includes file, so that a project +-- only needs `add_requires`, @see tests/actions/addon/custom-package +function test_include_packages(t) + + -- @note we need a compiler here, the project links against the package + if not (find_program("gcc") or find_program("clang") or find_program("cc")) then + return + end + _with_addons({"custom-package"}, function () + _with_project("custom-package", function () + t:require(os.iorunv("xmake", {"build", "-y"}):find("build ok", 1, true)) + t:require(os.iorunv("xmake", {"run"}):find("hello from the custom package", 1, true)) + end) + end) +end + -- an addon can provide a toolchain and its tool modules -- -- @see tests/apis/custom_toolchain for the same toolchain maintained inside a project -- cgit v1.3.1 From 58f6d2dd060b78afb0f1002c5586fc85dfca0629 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 16 Aug 2026 09:01:09 +0800 Subject: format code --- .../addon/custom-package/includes/packages/src/include/hello_utils.h | 3 +-- tests/actions/addon/projects/custom-package/src/main.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h b/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h index c7b9e86b1..ca969acd2 100644 --- a/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h +++ b/tests/actions/addon/custom-package/includes/packages/src/include/hello_utils.h @@ -1,7 +1,6 @@ #pragma once #include -static inline void hello_utils_greeting(void) -{ +static inline void hello_utils_greeting(void) { printf("hello from the custom package!\n"); } diff --git a/tests/actions/addon/projects/custom-package/src/main.c b/tests/actions/addon/projects/custom-package/src/main.c index 3edd2a8cb..12208c880 100644 --- a/tests/actions/addon/projects/custom-package/src/main.c +++ b/tests/actions/addon/projects/custom-package/src/main.c @@ -1,7 +1,6 @@ #include -int main(int argc, char** argv) -{ +int main(int argc, char** argv) { hello_utils_greeting(); return 0; } -- cgit v1.3.1