diff options
| author | ruki <[email protected]> | 2023-10-31 22:30:54 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-31 22:30:54 -0500 |
| commit | 1a53bc8550214990846409c31bc1e96bdedc49f4 (patch) | |
| tree | e1ff13eb8322a36cd0003d0d1f9f9591ba0849f6 | |
| parent | 62e71bb6aa56d397edc45a0a3112248778a42bac (diff) | |
| parent | 1fc0da75ce16ce63a587de77e2fccc77d922535a (diff) | |
Merge pull request #4343 from xmake-io/tests
Improve `xmake test` to support for building test stub code
| -rw-r--r-- | tests/actions/test/src/compile_1.cpp (renamed from tests/actions/test/src/compile.cpp) | 0 | ||||
| -rw-r--r-- | tests/actions/test/src/compile_2.cpp | 6 | ||||
| -rw-r--r-- | tests/actions/test/tests/stub_1.cpp | 3 | ||||
| -rw-r--r-- | tests/actions/test/tests/stub_2.cpp | 3 | ||||
| -rw-r--r-- | tests/actions/test/tests/stub_n1.cpp | 3 | ||||
| -rw-r--r-- | tests/actions/test/tests/stub_n2.cpp | 3 | ||||
| -rw-r--r-- | tests/actions/test/xmake.lua | 22 | ||||
| -rw-r--r-- | xmake/actions/test/main.lua | 12 |
8 files changed, 50 insertions, 2 deletions
diff --git a/tests/actions/test/src/compile.cpp b/tests/actions/test/src/compile_1.cpp index adfe8588c..adfe8588c 100644 --- a/tests/actions/test/src/compile.cpp +++ b/tests/actions/test/src/compile_1.cpp diff --git a/tests/actions/test/src/compile_2.cpp b/tests/actions/test/src/compile_2.cpp new file mode 100644 index 000000000..adfe8588c --- /dev/null +++ b/tests/actions/test/src/compile_2.cpp @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(int argc, char** argv) { + static_assert(0, "error"); + return 0; +} diff --git a/tests/actions/test/tests/stub_1.cpp b/tests/actions/test/tests/stub_1.cpp new file mode 100644 index 000000000..f44749b33 --- /dev/null +++ b/tests/actions/test/tests/stub_1.cpp @@ -0,0 +1,3 @@ +#ifndef STUB_1 +#error +#endif diff --git a/tests/actions/test/tests/stub_2.cpp b/tests/actions/test/tests/stub_2.cpp new file mode 100644 index 000000000..fd4050d90 --- /dev/null +++ b/tests/actions/test/tests/stub_2.cpp @@ -0,0 +1,3 @@ +#ifndef STUB_2 +#error +#endif diff --git a/tests/actions/test/tests/stub_n1.cpp b/tests/actions/test/tests/stub_n1.cpp new file mode 100644 index 000000000..229bfe431 --- /dev/null +++ b/tests/actions/test/tests/stub_n1.cpp @@ -0,0 +1,3 @@ +#ifndef STUB_N +#error +#endif diff --git a/tests/actions/test/tests/stub_n2.cpp b/tests/actions/test/tests/stub_n2.cpp new file mode 100644 index 000000000..229bfe431 --- /dev/null +++ b/tests/actions/test/tests/stub_n2.cpp @@ -0,0 +1,3 @@ +#ifndef STUB_N +#error +#endif diff --git a/tests/actions/test/xmake.lua b/tests/actions/test/xmake.lua index 328e817dd..a4f75036d 100644 --- a/tests/actions/test/xmake.lua +++ b/tests/actions/test/xmake.lua @@ -16,11 +16,29 @@ end target("test_10") set_kind("binary") set_default(false) - add_files("src/compile.cpp") + add_files("src/compile_1.cpp") add_tests("compile_fail", {build_should_fail = true}) target("test_11") set_kind("binary") set_default(false) - add_files("src/compile.cpp") + add_files("src/compile_2.cpp") add_tests("compile_pass", {build_should_pass = true}) + +target("test_13") + set_kind("binary") + set_default(false) + add_files("src/test_1.cpp") + add_tests("stub_1", {files = "tests/stub_1.cpp", defines = "STUB_1"}) + +target("test_14") + set_kind("binary") + set_default(false) + add_files("src/test_2.cpp") + add_tests("stub_2", {files = "tests/stub_2.cpp", defines = "STUB_2"}) + +target("test_15") + set_kind("binary") + set_default(false) + add_files("src/test_1.cpp") + add_tests("stub_n", {files = "tests/stub_n*.cpp", defines = "STUB_N"}) diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua index d73274a28..3a482339d 100644 --- a/xmake/actions/test/main.lua +++ b/xmake/actions/test/main.lua @@ -351,6 +351,18 @@ function main() local testinfo = {name = testname, target = target} if extra then table.join2(testinfo, extra) + if extra.files then + local target_new = target:clone() + local scriptdir = target:scriptdir() + target_new:name_set(target:name() .. "_" .. name) + for _, file in ipairs(extra.files) do + file = path.absolute(file, scriptdir) + file = path.relative(file, os.projectdir()) + target_new:add("files", file, {defines = extra.defines}) + project.target_add(target_new) + end + testinfo.target = target_new + end end if not testinfo.group then testinfo.group = target:get("group") |
