Skip to content

Commit

Permalink
Merge pull request #19 from dwd/msvc-tests
Browse files Browse the repository at this point in the history
Tests running under MSVC
  • Loading branch information
dwd authored Jul 18, 2024
2 parents 10e3e9d + 6711cb5 commit 3c18941
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/gtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ on:
push:
branches:
- master
pull_request_target:
branches:
- master
pull_request:

jobs:
gtest:
Expand Down
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.24)
project(rapidxml)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(RAPIDXML_PERF_TESTS "Enable (very slow) performance tests" OFF)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
FetchContent_MakeAvailable(googletest)
# Used on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

file(DOWNLOAD https://www.w3.org/TR/xml/REC-xml-20081126.xml ${CMAKE_CURRENT_BINARY_DIR}/REC-xml-20081126.xml)
FetchContent_MakeAvailable(googletest)

enable_testing()
add_executable(rapidxml-test
Expand All @@ -35,6 +37,14 @@ target_include_directories(rapidxml-test
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(rapidxml-test PRIVATE RAPIDXML_TESTING=1)
if (RAPIDXML_PERF_TESTS)
message("Running performance tests")
file(DOWNLOAD https://www.w3.org/TR/xml/REC-xml-20081126.xml ${CMAKE_CURRENT_BINARY_DIR}/REC-xml-20081126.xml)
target_compile_definitions(rapidxml-test PRIVATE RAPIDXML_TESTING=1 RAPIDXML_PERF_TESTS=1)
else()
message("Will skip performance tests")
target_compile_definitions(rapidxml-test PRIVATE RAPIDXML_TESTING=1)
endif()

include(GoogleTest)
gtest_discover_tests(rapidxml-test)
10 changes: 10 additions & 0 deletions test/perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@

const auto xml_sample_file = "REC-xml-20081126.xml";

#ifdef RAPIDXML_PERF_TESTS
#define PERF_TEST() (void)0
#else
#define PERF_TEST() GTEST_SKIP() << "Skipping performance test"
#endif

TEST(Perf, Parse) {
using std::chrono::high_resolution_clock;
using std::chrono::duration_cast;
using std::chrono::microseconds;

PERF_TEST();
rapidxml::file source(xml_sample_file);

std::vector<unsigned long long> timings;
Expand All @@ -40,6 +47,7 @@ TEST(Perf, Parse2) {
using std::chrono::duration_cast;
using std::chrono::microseconds;

PERF_TEST();
rapidxml::file source(xml_sample_file);

std::vector<unsigned long long> timings;
Expand All @@ -64,6 +72,7 @@ TEST(Perf, PrintClean) {
using std::chrono::duration_cast;
using std::chrono::microseconds;

PERF_TEST();
rapidxml::file source(xml_sample_file);

std::vector<unsigned long long> timings;
Expand All @@ -89,6 +98,7 @@ TEST(Perf, PrintDirty) {
using std::chrono::duration_cast;
using std::chrono::microseconds;

PERF_TEST();
rapidxml::file source(xml_sample_file);

std::vector<unsigned long long> timings;
Expand Down

0 comments on commit 3c18941

Please sign in to comment.