summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-06 22:31:30 +0800
committerGitHub <[email protected]>2024-04-06 22:31:30 +0800
commit665f568fa3c27aec640037d2e0ceaa72ad4920c3 (patch)
tree533ee6ba18369ca701e1c142a32d82c93119f7bf /tests
parent5cfb0d402d553f27d9fb3673ffab5f1f235660ad (diff)
parent15ded5361b44cc6ffa456f64ce079c6e6f6604d9 (diff)
Merge pull request #4921 from Arthapz/cxx_snippet_runtimes
runtimes support for package:check_cxxsnippet
Diffstat (limited to 'tests')
-rw-r--r--tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/include/bar.hpp8
-rw-r--r--tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/src/bar.cpp5
-rw-r--r--tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/xmake.lua6
-rw-r--r--tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/xmake.lua15
-rw-r--r--tests/projects/c++/snippet_runtimes/src/main.cpp7
-rw-r--r--tests/projects/c++/snippet_runtimes/test.lua19
-rw-r--r--tests/projects/c++/snippet_runtimes/xmake.lua18
7 files changed, 78 insertions, 0 deletions
diff --git a/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/include/bar.hpp b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/include/bar.hpp
new file mode 100644
index 000000000..e712aebe0
--- /dev/null
+++ b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/include/bar.hpp
@@ -0,0 +1,8 @@
+#ifndef BAR_HPP
+#define BAR_HPP
+
+#include <string>
+
+std::string foo();
+
+#endif
diff --git a/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/src/bar.cpp b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/src/bar.cpp
new file mode 100644
index 000000000..1dc99de3c
--- /dev/null
+++ b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/src/bar.cpp
@@ -0,0 +1,5 @@
+#include <bar.hpp>
+
+std::string foo() {
+ return "bar";
+}
diff --git a/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/xmake.lua b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/xmake.lua
new file mode 100644
index 000000000..8393aed87
--- /dev/null
+++ b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/xmake.lua
@@ -0,0 +1,6 @@
+target("bar")
+ set_kind("$(kind)")
+ add_files("src/*.cpp")
+ add_headerfiles("include/(**.hpp)")
+ add_includedirs("include")
+
diff --git a/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/xmake.lua b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/xmake.lua
new file mode 100644
index 000000000..173fc1427
--- /dev/null
+++ b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/xmake.lua
@@ -0,0 +1,15 @@
+package("bar")
+ set_sourcedir(path.join(os.scriptdir(), "src"))
+
+ on_install(function(package)
+ import("package.tools.xmake").install(package, {})
+ end)
+
+ on_test(function(package)
+ assert(package:check_cxxsnippets({test = [[
+ #include <iostream>
+ void test() {
+ std::cout << _LIBCPP_VERSION << std::endl;
+ }
+ ]]}, {configs = {languages = "c++17"}}))
+ end)
diff --git a/tests/projects/c++/snippet_runtimes/src/main.cpp b/tests/projects/c++/snippet_runtimes/src/main.cpp
new file mode 100644
index 000000000..1c8e6bf02
--- /dev/null
+++ b/tests/projects/c++/snippet_runtimes/src/main.cpp
@@ -0,0 +1,7 @@
+#include <iostream>
+#include <bar.hpp>
+
+int main() {
+ std::cout << foo();
+ return 0;
+}
diff --git a/tests/projects/c++/snippet_runtimes/test.lua b/tests/projects/c++/snippet_runtimes/test.lua
new file mode 100644
index 000000000..753cab958
--- /dev/null
+++ b/tests/projects/c++/snippet_runtimes/test.lua
@@ -0,0 +1,19 @@
+import("lib.detect.find_tool")
+import("core.base.semver")
+import("utils.ci.is_running", {alias = "ci_is_running"})
+
+function _build()
+ if ci_is_running() then
+ assert(os.iorun("xmake -rvD"))
+ else
+ assert(os.iorun("xmake -r"))
+ end
+end
+
+function main(t)
+ local clang = find_tool("clang")
+ if clang and not is_subhost("windows") then
+ os.exec("xmake f --toolchain=clang --runtimes=c++_shared --yes")
+ _build()
+ end
+end
diff --git a/tests/projects/c++/snippet_runtimes/xmake.lua b/tests/projects/c++/snippet_runtimes/xmake.lua
new file mode 100644
index 000000000..1e5436ba4
--- /dev/null
+++ b/tests/projects/c++/snippet_runtimes/xmake.lua
@@ -0,0 +1,18 @@
+add_repositories("my-repo my-repo")
+add_requires("bar")
+
+target("foo")
+ set_kind("binary")
+ add_files("src/*.cpp")
+
+ add_packages("bar")
+
+ on_config(function(target)
+ assert(target:check_cxxsnippets({test = [[
+ #include <iostream>
+ void test() {
+ std::cout << _LIBCPP_VERSION << std::endl;
+ }
+ ]]}, {configs = {languages = "c++17"}}))
+ end)
+