Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2_9] Use xmake test subcommand instead of test target #328

Merged
merged 12 commits into from
Jun 2, 2024
1 change: 0 additions & 1 deletion .github/workflows/ci-xmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
run: xmake build --yes -vD
- name: test
run: |
xmake run --yes -vD --group=tests
xmake test -vD
- name: benchmark
run: xmake run --yes --group=bench
1 change: 0 additions & 1 deletion .github/workflows/ci-xmake-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ jobs:
run: xmake build --yes -vD
- name: test
run: |
xmake run --yes -vD --group=tests
xmake test -vD
- name: benchmark
run: xmake run --yes --group=bench
4 changes: 2 additions & 2 deletions .github/workflows/ci-xmake-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
${{ github.workspace }}/build/.build_cache
key: ${{ runner.os }}-wasm-${{ hashFiles('**/xmake.lua') }}
- name: config
run: xmake config --yes -p wasm -vD
run: xmake config --yes -p wasm -vD --enable_tests=true
- name: build
run: xmake build --yes -vD
- name: test
Expand Down Expand Up @@ -84,5 +84,5 @@ jobs:
- name: build
run: xmake build --yes -vD
- name: test
run: elvish bin/test_wasm
run: elvish bin/test_wasm "tests/*"

3 changes: 1 addition & 2 deletions .github/workflows/ci-xmake-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
steps:
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: v2.8.7
da-liii marked this conversation as resolved.
Show resolved Hide resolved
xmake-version: v2.9.2
- name: update repo
run: xmake repo -u
- name: git crlf
Expand All @@ -55,7 +55,6 @@ jobs:
run: xmake build --yes -vD
- name: test
run: |
xmake run --yes -vD --group=tests
xmake test -vD
- name: benchmark
run: xmake run --yes --group=bench
4 changes: 2 additions & 2 deletions bin/test_wasm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if $platform:is-windows {


if (== (count $args) 0) {
xmake run
xmake test
} else {
xmake run $args[0]
xmake test $args[0]
}
129 changes: 44 additions & 85 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,86 +206,6 @@ end

local mingw_copied = false

function add_test_target(filepath)
local testname = path.basename(filepath)
target(testname) do
set_group("tests")
add_deps("test_base")
set_languages("c++17")
set_policy("check.auto_ignore_flags", false)
set_exceptions("cxx")

if is_plat("mingw") then
add_packages("mingw-w64")
end
add_packages("tbox")
add_packages("doctest")

if is_plat("linux") then
add_syslinks("stdc++", "m")
end

if is_plat("windows") then
set_encodings("utf-8")
add_ldflags("/LTCG")
end

if is_plat("windows") or is_plat("mingw") then
add_syslinks("secur32", "shell32")
end

add_includedirs("$(buildir)/L1")
add_includedirs(lolly_includedirs)
add_includedirs("tests")
add_forceincludes(path.absolute("$(buildir)/L1/config.h"))
add_files(filepath)

if is_plat("wasm") then
add_cxxflags("-s DISABLE_EXCEPTION_CATCHING=0")
set_values("wasm.preloadfiles", {"xmake.lua", "tests", "LICENSE"})
add_ldflags("-s DISABLE_EXCEPTION_CATCHING=0")
on_run(function (target)
node = os.getenv("EMSDK_NODE")
os.cd("$(buildir)/wasm/wasm32/$(mode)/")
print("> cd $(buildir)/wasm/wasm32/$(mode)/")
cmd = node .. " " .. testname .. ".js"
print("> " .. cmd)
os.exec(cmd)
end)
end

if is_plat("linux", "macosx") then
on_run(function (target)
cmd = "$(buildir)/$(plat)/$(arch)/$(mode)/" .. testname
print("> " .. cmd)
os.exec(cmd)
end)
end

if is_plat("windows") or (is_plat ("mingw") and is_host ("windows")) then
on_run(function (target)
cmd = "$(buildir)/$(plat)/$(arch)/$(mode)/" .. testname .. ".exe"
print("> " .. cmd)
os.exec(cmd)
end)
end

if is_plat("mingw") and is_host("linux") then
on_run(function (target)
cmd = "wine $(buildir)/mingw/x86_64/$(mode)/" .. testname .. ".exe"
print("> " .. cmd)
if not mingw_copied then
mingw_copied = true
os.cp("/usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll", "$(buildir)/mingw/x86_64/$(mode)/")
os.cp("/usr/lib/gcc/x86_64-w64-mingw32/10-win32/libgcc_s_seh-1.dll", "$(buildir)/mingw/x86_64/$(mode)/")
os.cp("/usr/lib/gcc/x86_64-w64-mingw32/10-win32/libstdc++-6.dll", "$(buildir)/mingw/x86_64/$(mode)/")
end
os.exec(cmd)
end)
end
end
end

function add_bench_target(filepath)
local benchname = path.basename(filepath)
target(benchname) do
Expand Down Expand Up @@ -390,24 +310,67 @@ if has_config("enable_tests") then
packages = "doctest",
defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"})
end
target("test_base")do
target("tests")do
set_kind("object")
add_deps("liblolly")
set_languages("c++17")
set_policy("check.auto_ignore_flags", false)
set_exceptions("cxx")
if not is_plat("wasm") then
set_rundir("$(projectdir)")
end

if is_plat("mingw") then
add_packages("mingw-w64")
end
add_packages("tbox")
add_packages("doctest")

if is_plat("linux") then
add_syslinks("stdc++", "m")
elseif is_plat("windows") or is_plat("mingw") then
add_syslinks("secur32", "shell32")
end

if is_plat("windows") then
set_encodings("utf-8")
add_ldflags("/LTCG")
elseif is_plat("wasm") then
add_cxxflags("-s DISABLE_EXCEPTION_CATCHING=0")
add_ldflags("-s DISABLE_EXCEPTION_CATCHING=0")
set_values("wasm.preloadfiles", {"xmake.lua", "tests", "LICENSE"})
on_test(function (target)
node = os.getenv("EMSDK_NODE")
os.cd("$(buildir)/wasm/wasm32/$(mode)/")
print("> cd $(buildir)/wasm/wasm32/$(mode)/")
cmd = node .. " " .. testname .. ".js"
print("> " .. cmd)
local retval = try {
function ()
os.exec(cmd)
return true
end,
catch {
function (errors)
return false
end
}
}
return retval;
end)
end
add_includedirs("$(buildir)/L1")
add_includedirs(lolly_includedirs)
add_includedirs("tests")
add_forceincludes(path.absolute("$(buildir)/L1/config.h"))
add_files("tests/a_tbox_main.cpp")

local cpp_tests_on_all_plat = os.files("tests/**_test.cpp|**/shared_lib_test.cpp")
for _, testfile in ipairs(cpp_tests_on_all_plat) do
add_tests(path.basename(testfile), {
kind = "binary",
files = testfile})
end
end
target("bench_base")do
set_kind("object")
Expand All @@ -421,10 +384,6 @@ if has_config("enable_tests") then
add_files("bench/nanobench.cpp")
end

cpp_tests_on_all_plat = os.files("tests/**_test.cpp|**/shared_lib_test.cpp")
for _, filepath in ipairs(cpp_tests_on_all_plat) do
add_test_target (filepath)
end
cpp_bench_on_all_plat = os.files("bench/**_bench.cpp")
for _, filepath in ipairs(cpp_bench_on_all_plat) do
add_bench_target (filepath)
Expand Down
Loading