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

tests: replace doctest with googletest #431

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@
[submodule "3rdparty/pareto"]
path = 3rdparty/pareto
url = https://github.com/alandefreitas/pareto.git
[submodule "3rdparty/doctest"]
path = 3rdparty/doctest
url = https://github.com/doctest/doctest
11 changes: 10 additions & 1 deletion 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
add_subdirectory(fmt EXCLUDE_FROM_ALL)
add_subdirectory(doctest EXCLUDE_FROM_ALL)
add_subdirectory(json EXCLUDE_FROM_ALL)
add_subdirectory(nanobench EXCLUDE_FROM_ALL)

set(BUILD_WITH_PEDANTIC_WARNINGS OFF CACHE BOOL "prevent pareto from adding /WX" FORCE)
add_subdirectory(pareto EXCLUDE_FROM_ALL)

include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # v1.14.0
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
1 change: 0 additions & 1 deletion 3rdparty/doctest
Submodule doctest deleted from b7c21e
2 changes: 1 addition & 1 deletion build-appveyor.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if ( $? -eq $false ) {
throw "package failed"
}

.\tests\Release\tests.exe --no-skip
.\tests\Release\tests.exe

if ( $? -eq $false ) {
throw "tests failed"
Expand Down
6 changes: 1 addition & 5 deletions build-linux-64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ export ASAN_OPTIONS=detect_leaks=false
make -j8 VERBOSE=1 package || exit 1

# run tests
if [ "$USE_ASAN" != "YES" ]; then
./tests/tests --no-skip || exit 1 # run hidden tests (releaseonly)
else
./tests/tests || exit 1
fi
./tests/tests || exit 1

# check rpath
readelf -d ./light/light
6 changes: 1 addition & 5 deletions build-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,4 @@ otool -L ./bspinfo/bspinfo
otool -L ./bsputil/bsputil

# run tests
if [ "$USE_ASAN" != "YES" ]; then
./tests/tests --no-skip || exit 1 # run hidden tests (releaseonly)
else
./tests/tests || exit 1
fi
./tests/tests || exit 1
2 changes: 1 addition & 1 deletion build-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if ( $? -eq $false ) {
throw "build failed"
}

.\tests\tests.exe --no-skip
.\tests\tests.exe

if ( $? -eq $false ) {
throw "tests failed"
Expand Down
6 changes: 1 addition & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
enable_testing()

add_executable(tests
test.cc
test_main.cc
Expand Down Expand Up @@ -29,9 +27,7 @@ if (NOT EMBREE_TBB_DLL STREQUAL EMBREE_TBB_DLL-NOTFOUND)
message(STATUS "Found embree EMBREE_TBB_DLL: ${EMBREE_TBB_DLL}")
endif()

target_link_libraries(tests libqbsp liblight libvis libbsputil common TBB::tbb TBB::tbbmalloc doctest::doctest fmt::fmt nanobench::nanobench)

target_compile_definitions(tests PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
target_link_libraries(tests libqbsp liblight libvis libbsputil common TBB::tbb TBB::tbbmalloc GTest::gtest fmt::fmt nanobench::nanobench)

# HACK: copy .dll dependencies
add_custom_command(TARGET tests POST_BUILD
Expand Down
34 changes: 17 additions & 17 deletions tests/benchmark.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <nanobench.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
#include <vis/vis.hh>
#include <common/qvec.hh>
#include <common/polylib.hh>

#include <array>
#include <vector>

TEST_CASE("winding" * doctest::test_suite("benchmark") * doctest::skip())
TEST(benchmark, winding)
{
ankerl::nanobench::Bench bench;

Expand Down Expand Up @@ -52,35 +52,35 @@ static void test_polylib(bool check_results)
ankerl::nanobench::doNotOptimizeAway(back);

if (check_results) {
REQUIRE(front);
REQUIRE(back);
ASSERT_TRUE(front);
ASSERT_TRUE(back);

CHECK(front->size() == 4);
CHECK(back->size() == 4);
EXPECT_EQ(front->size(), 4);
EXPECT_EQ(back->size(), 4);

// check front polygon
CHECK(front->at(0) == qvec3d{0, 64, 16});
CHECK(front->at(1) == qvec3d{64, 64, 16});
CHECK(front->at(2) == qvec3d{64, -64, 16});
CHECK(front->at(3) == qvec3d{0, -64, 16});
EXPECT_EQ(front->at(0), qvec3d(0, 64, 16));
EXPECT_EQ(front->at(1), qvec3d(64, 64, 16));
EXPECT_EQ(front->at(2), qvec3d(64, -64, 16));
EXPECT_EQ(front->at(3), qvec3d(0, -64, 16));

// check back polygon
CHECK(back->at(0) == qvec3d{-64, 64, 16});
CHECK(back->at(1) == qvec3d{0, 64, 16});
CHECK(back->at(2) == qvec3d{0, -64, 16});
CHECK(back->at(3) == qvec3d{-64, -64, 16});
EXPECT_EQ(back->at(0), qvec3d(-64, 64, 16));
EXPECT_EQ(back->at(1), qvec3d(0, 64, 16));
EXPECT_EQ(back->at(2), qvec3d(0, -64, 16));
EXPECT_EQ(back->at(3), qvec3d(-64, -64, 16));
}
}

TEST_CASE("SplitFace" * doctest::test_suite("benchmark"))
TEST(benchmark, SplitFace)
{
ankerl::nanobench::Bench().run("create and split a face (polylib)", [&]() { test_polylib(false); });

// run with doctest assertions, to validate that they actually work
test_polylib(true);
}

TEST_CASE("vis windings")
TEST(benchmark, visWindings)
{
ankerl::nanobench::Bench b;
b.run("create pstack_t", [&]() {
Expand Down Expand Up @@ -143,7 +143,7 @@ TEST_CASE("vis windings")
});
}

TEST_CASE("vector math")
TEST(benchmark, vectorMath)
{
ankerl::nanobench::Bench b;
ankerl::nanobench::Rng rng;
Expand Down
Loading
Loading