Skip to content

Commit 2d468d7

Browse files
authored
Replaces catch2 with doctest (#25)
Decreases compile time while everything stays the same. It is also possible to increase the warning levels.
1 parent eddc3e3 commit 2d468d7

File tree

7 files changed

+7213
-23848
lines changed

7 files changed

+7213
-23848
lines changed

include/vdf_parser.hpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ template <typename T> struct literal_macro_help
8282
{
8383
return c;
8484
}
85-
static CONSTEXPR const char result(const char c, const wchar_t) NOEXCEPT
85+
static CONSTEXPR char result(const char c, const wchar_t) NOEXCEPT
8686
{
8787
return c;
8888
}
@@ -95,7 +95,7 @@ template <> struct literal_macro_help<wchar_t>
9595
{
9696
return wc;
9797
}
98-
static CONSTEXPR const wchar_t result(const char, const wchar_t wc) NOEXCEPT
98+
static CONSTEXPR wchar_t result(const char, const wchar_t wc) NOEXCEPT
9999
{
100100
return wc;
101101
}
@@ -109,10 +109,18 @@ inline std::string string_converter(const std::wstring &w) NOEXCEPT
109109
{
110110
std::mbstate_t state = std::mbstate_t();
111111
auto wstr = w.data();
112+
// unsafe: ignores any error handling
113+
// and disables warning that wcsrtombs_s should be used
114+
#ifdef WIN32
115+
#pragma warning(push)
116+
#pragma warning(disable : 4996)
117+
#endif
112118
std::size_t len = 1 + std::wcsrtombs(nullptr, &wstr, 0, &state);
113119
std::string mbstr(len, '\0');
114-
// unsafe: ignores any error handling
115120
std::wcsrtombs(&mbstr[0], &wstr, mbstr.size(), &state);
121+
#ifdef WIN32
122+
#pragma warning(pop)
123+
#endif
116124
return mbstr;
117125
}
118126

@@ -258,7 +266,7 @@ std::basic_string<typename iStreamT::char_type> read_file(iStreamT &inStream)
258266
return str;
259267

260268
inStream.seekg(0, std::ios::beg);
261-
inStream.read(&str[0], str.size());
269+
inStream.read(&str[0], static_cast<std::streamsize>(str.size()));
262270
return str;
263271
}
264272

@@ -502,8 +510,7 @@ std::vector<std::unique_ptr<OutputT>> read_internal(
502510

503511
curIter = skip_whitespaces(curIter, last);
504512

505-
auto conditional = conditional_fullfilled(curIter, last);
506-
if (!conditional)
513+
if (!conditional_fullfilled(curIter, last))
507514
continue;
508515
if (curIter == last)
509516
throw std::runtime_error{"key declared, but no value"};
@@ -538,8 +545,7 @@ std::vector<std::unique_ptr<OutputT>> read_internal(
538545
curIter =
539546
valueEnd + ((*valueEnd == TYTI_L(charT, '\"')) ? 1 : 0);
540547

541-
auto conditional = conditional_fullfilled(curIter, last);
542-
if (!conditional)
548+
if (!conditional_fullfilled(curIter, last))
543549
continue;
544550

545551
// process value

tests/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
set(SRCS
33
"main.cpp"
44
"vdf_parser_test.cpp"
5-
"catch.cpp"
65
"../Readme.md")
76

87
add_executable(tests ${SRCS})
98
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT tests) #requires cmake 3.6
109
set_property(TARGET tests PROPERTY COMPILE_WARNING_AS_ERROR ON)
11-
add_definitions("-DSOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"" "-DCATCH_AMALGAMATED_CUSTOM_MAIN")
10+
add_definitions("-DSOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"")
1211
target_compile_features(tests PUBLIC cxx_std_17)
1312
target_link_libraries(tests PRIVATE ValveFileVDF)
1413

14+
target_compile_options(tests PRIVATE
15+
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
16+
-Wall -Wextra -Wconversion -pedantic-errors -Wsign-conversion>
17+
$<$<CXX_COMPILER_ID:MSVC>:
18+
/W4>)
19+
1520
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
1621
target_link_libraries(tests PUBLIC -fsanitize=address,undefined)
1722
endif()

0 commit comments

Comments
 (0)