diff --git a/.github/workflows/ci-xmake-linux.yml b/.github/workflows/ci-xmake-linux.yml index 73ac43ad6..f92d7312e 100644 --- a/.github/workflows/ci-xmake-linux.yml +++ b/.github/workflows/ci-xmake-linux.yml @@ -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 diff --git a/.github/workflows/ci-xmake-macos.yml b/.github/workflows/ci-xmake-macos.yml index b80e10975..fa874961e 100644 --- a/.github/workflows/ci-xmake-macos.yml +++ b/.github/workflows/ci-xmake-macos.yml @@ -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 diff --git a/.github/workflows/ci-xmake-wasm.yml b/.github/workflows/ci-xmake-wasm.yml index 6499ea4de..4c561957d 100644 --- a/.github/workflows/ci-xmake-wasm.yml +++ b/.github/workflows/ci-xmake-wasm.yml @@ -48,11 +48,11 @@ 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 - run: elvish bin/test_wasm + run: elvish bin/test_wasm "tests/*" windowsbuild: runs-on: windows-2019 env: @@ -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/*" diff --git a/.github/workflows/ci-xmake-windows.yml b/.github/workflows/ci-xmake-windows.yml index ef4e37ae1..ac1978d7e 100644 --- a/.github/workflows/ci-xmake-windows.yml +++ b/.github/workflows/ci-xmake-windows.yml @@ -34,7 +34,7 @@ jobs: steps: - uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: v2.8.7 + xmake-version: v2.8.9 - name: update repo run: xmake repo -u - name: git crlf @@ -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 diff --git a/bin/test_wasm b/bin/test_wasm index 7ffd8ab01..c799eb738 100755 --- a/bin/test_wasm +++ b/bin/test_wasm @@ -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] } diff --git a/xmake.lua b/xmake.lua index 432649102..908869ace 100644 --- a/xmake.lua +++ b/xmake.lua @@ -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 @@ -390,24 +310,70 @@ if has_config("enable_tests") then packages = "doctest", defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"}) end - target("test_base")do - set_kind("object") + target("tests")do + set_kind("binary") 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") + elseif is_plat("wasm") then + add_packages("emscripten") + 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, opt) + node_table = path.splitenv(os.getenv("EMSDK_NODE")) + node = node_table[table.maxn(node_table)] + os.cd(target:targetdir()) + print("> cd " .. target:targetdir()) + cmd = node .. " " .. path.join(target:targetdir(), target:basename() .. ".js") + print("> " .. cmd) + local retval = try { + function () + os.exec(cmd) + return true + end, + catch { + function (errors) + return false, errors + 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") @@ -421,10 +387,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)