Skip to content

Commit

Permalink
Merge pull request #46 from JohanMabille/doctest
Browse files Browse the repository at this point in the history
Migrated from gtest to doctest
  • Loading branch information
JohanMabille authored Jun 4, 2024
2 parents 1dfb441 + 6273dd4 commit 98dd83c
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 149 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
-DCMAKE_PREFIX_PATH=$CONDA_PREFIX \
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DDOWNLOAD_GTEST=ON
-DXVEGA_BUILD_TESTS=ON
working-directory: build

- name: Build
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
-DCMAKE_PREFIX_PATH="%CONDA_PREFIX%\Library" ^
-DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX% ^
-DCMAKE_BUILD_TYPE=Release ^
-DDOWNLOAD_GTEST=ON
-DXVEGA_BUILD_TESTS=ON
working-directory: build

- name: Build
Expand Down
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ OPTION(XVEGA_DISABLE_TUNE_GENERIC "disable -mtune=generic flag" OFF)
OPTION(XVEGA_BUILD_STATIC "Build xvega static library" ON)
OPTION(XVEGA_BUILD_SHARED "Split xvega build into executable and library" ON)

OPTION(XVEGA_BUILD_TESTS "xvega test suite" OFF)

# Dependencies
# ============

Expand Down Expand Up @@ -456,14 +458,7 @@ endif ()
# Tests
# =====

OPTION(BUILD_TESTS "xvega test suite" OFF)
OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)

if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
set(BUILD_TESTS ON)
endif()

if(BUILD_TESTS)
if(XVEGA_BUILD_TESTS)
add_subdirectory(test)
endif()

Expand Down
3 changes: 2 additions & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ dependencies:
- xtl=0.7.0
- xproperty=0.11.0
- nlohmann_json=3.11.2

# Test dependencies
- doctest
50 changes: 4 additions & 46 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,44 +67,9 @@ else()
message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()

if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
if(DOWNLOAD_GTEST)
# Download and unpack googletest at configure time
configure_file(downloadGTest.cmake.in googletest-download/CMakeLists.txt)
else()
# Copy local source of googletest at configure time
configure_file(copyGTest.cmake.in googletest-download/CMakeLists.txt)
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)

set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
set(GTEST_BOTH_LIBRARIES gtest_main gtest)
else()
find_package(GTest REQUIRED)
endif()

find_package(doctest REQUIRED)
find_package(Threads)

include_directories(${GTEST_INCLUDE_DIRS} SYSTEM)

set(XVEGA_TESTS
main.cpp
test_marks.cpp
Expand All @@ -118,12 +83,9 @@ set(XVEGA_TESTS

foreach(filename IN LISTS XVEGA_TESTS)
string(REPLACE ".cpp" "" targetname ${filename})
add_executable(${targetname} ${filename} ${XVEGA_HEADERS})
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
add_dependencies(${targetname} gtest_main)
endif()
add_executable(${targetname} ${filename} main.cpp ${XVEGA_HEADERS})
target_include_directories(${targetname} PRIVATE ${XVEGA_INCLUDE_DIR})
target_link_libraries(${targetname} PRIVATE xvega ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${targetname} PRIVATE xvega doctest::doctest Threads::Threads)
add_custom_target(
x${targetname}
COMMAND ${targetname}
Expand All @@ -132,11 +94,7 @@ endforeach()

add_executable(test_xvega_lib ${XVEGA_TESTS} ${XVEGA_HEADERS})

if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
add_dependencies(test_xvega_lib gtest_main)
endif()

target_include_directories(test_xvega_lib PRIVATE ${XVEGA_INCLUDE_DIR})
target_link_libraries(test_xvega_lib PRIVATE xvega ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(test_xvega_lib PRIVATE xvega doctest::doctest Threads::Threads)

add_custom_target(xtest COMMAND test_xvega_lib DEPENDS test_xvega_lib)
20 changes: 0 additions & 20 deletions test/copyGTest.cmake.in

This file was deleted.

21 changes: 0 additions & 21 deletions test/downloadGTest.cmake.in

This file was deleted.

9 changes: 2 additions & 7 deletions test/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
#include <gtest/gtest.h>

int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"
9 changes: 6 additions & 3 deletions test/test_configurations.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <gtest/gtest.h>
#include "doctest/doctest.h"
#include <xvega/xvega.hpp>

using namespace xv;

TEST(JsonSpecOutput, DoubleGlobalConfig)
TEST_SUITE("JsonSpecOutput")
{
TEST_CASE("DoubleGlobalConfig")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto mp = mark_point();
Expand Down Expand Up @@ -32,5 +34,6 @@ TEST(JsonSpecOutput, DoubleGlobalConfig)
"mark": {"type": "point"},
"width": 400
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}
}
17 changes: 10 additions & 7 deletions test/test_data.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <gtest/gtest.h>
#include "doctest/doctest.h"
#include <xvega/xvega.hpp>

using namespace xv;

TEST(JsonSpecOutput, UrlData)
TEST_SUITE("JsonSpecOutput")
{
TEST_CASE("UrlData")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto fig = Chart().data(df);
Expand All @@ -13,10 +15,10 @@ TEST(JsonSpecOutput, UrlData)
"data": {"url": "https://vega.github.io/vega-datasets/data/cars.json"},
"mark": null
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}

TEST(JsonSpecOutput, Dataframe)
TEST_CASE("Dataframe")
{
df_type val;
val["country"] = {"India", "France", "France", "Germany", "India", "Germany", "France"};
Expand All @@ -40,10 +42,10 @@ TEST(JsonSpecOutput, Dataframe)
},
"mark": null
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}

TEST(JsonSpecOutput, SequenceGenerator)
TEST_CASE("SequenceGenerator")
{
auto seq = sequence_params().start(0).stop(12.7).step(0.1).as("x");
auto df = sequence_generator().sequence(seq);
Expand All @@ -55,6 +57,7 @@ TEST(JsonSpecOutput, SequenceGenerator)
"data": {"sequence": {"as": "x", "start": 0, "step": 0.1, "stop": 12.7}},
"mark": null
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}
}

22 changes: 12 additions & 10 deletions test/test_encodings.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <gtest/gtest.h>
#include "doctest/doctest.h"
#include <xvega/xvega.hpp>

using namespace xv;

TEST(JsonSpecOutput, SingleEncodingChannel)
TEST_SUITE("JsonSpecOutput")
{
TEST_CASE("SingleEncodingChannel")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto mp = mark_point();
Expand All @@ -19,10 +20,10 @@ TEST(JsonSpecOutput, SingleEncodingChannel)
"mark": {"type": "point"},
"width": 400
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}

TEST(JsonSpecOutput, DoubleEncodingChannel)
TEST_CASE("DoubleEncodingChannel")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto mp = mark_point();
Expand All @@ -44,10 +45,10 @@ TEST(JsonSpecOutput, DoubleEncodingChannel)
"title": "Simple 2D Chart",
"width": 400
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}

TEST(JsonSpecOutput, TripleEncodingChannel)
TEST_CASE("TripleEncodingChannel")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto mp = mark_point();
Expand All @@ -70,10 +71,10 @@ TEST(JsonSpecOutput, TripleEncodingChannel)
"mark": {"type": "point"},
"width": 400
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}

TEST(JsonSpecOutput, DoubleEncodingWithChannelOptions)
TEST_CASE("DoubleEncodingWithChannelOptions")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto mb = mark_bar();
Expand All @@ -99,5 +100,6 @@ TEST(JsonSpecOutput, DoubleEncodingWithChannelOptions)
"mark": {"type": "bar"},
"width": 400
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}
}
17 changes: 10 additions & 7 deletions test/test_marks.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <gtest/gtest.h>
#include "doctest/doctest.h"
#include <xvega/xvega.hpp>

using namespace xv;

TEST(JsonSpecOutput, MarkPoint)
TEST_SUITE("JsonSpecOutput")
{
TEST_CASE("MarkPoint")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto mp = mark_point();
Expand All @@ -14,10 +16,10 @@ TEST(JsonSpecOutput, MarkPoint)
"data": {"url": "https://vega.github.io/vega-datasets/data/cars.json"},
"mark": {"type": "point"}
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}

TEST(JsonSpecOutput, MarkPointWithCommonProperty)
TEST_CASE("MarkPointWithCommonProperty")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto mp = mark_point().color("red");
Expand All @@ -28,10 +30,10 @@ TEST(JsonSpecOutput, MarkPointWithCommonProperty)
"data": {"url": "https://vega.github.io/vega-datasets/data/cars.json"},
"mark": {"color": "red", "type": "point"}
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}

TEST(JsonSpecOutput, MarkPointWithSpecificProperty)
TEST_CASE("MarkPointWithSpecificProperty")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto mp = mark_point().color("red").size(100);
Expand All @@ -42,5 +44,6 @@ TEST(JsonSpecOutput, MarkPointWithSpecificProperty)
"data": {"url": "https://vega.github.io/vega-datasets/data/cars.json"},
"mark": {"color": "red", "size": 100, "type": "point"}
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}
}
9 changes: 6 additions & 3 deletions test/test_selections.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <gtest/gtest.h>
#include "doctest/doctest.h"
#include <xvega/xvega.hpp>

using namespace xv;

TEST(JsonSpecOutput, IntervalSelection)
TEST_SUITE("JsonSpecOutput")
{
TEST_CASE("IntervalSelection")
{
auto df = url_data().url("https://vega.github.io/vega-datasets/data/cars.json");
auto mp = mark_point();
Expand Down Expand Up @@ -32,5 +34,6 @@ TEST(JsonSpecOutput, IntervalSelection)
"selection": {"selector_interval_nws23": {"type": "interval"}},
"width": 400
})"_json;
ASSERT_EQ(expected, result["application/vnd.vegalite.v3+json"]);
REQUIRE_EQ(expected, result["application/vnd.vegalite.v3+json"]);
}
}
Loading

0 comments on commit 98dd83c

Please sign in to comment.