Merge pull request #1439 from onqtam/doctest
moved from Catch to doctest for unit tests
This commit is contained in:
commit
d1ef75316e
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@ -32,7 +32,7 @@ To make changes, you need to edit the following files:
|
||||
|
||||
1. [`include/nlohmann/*`](https://github.com/nlohmann/json/tree/develop/include/nlohmann) - These files are the sources of the library. Before testing or creating a pull request, execute `make amalgamate` to regenerate `single_include/nlohmann/json.hpp`.
|
||||
|
||||
2. [`test/src/unit-*.cpp`](https://github.com/nlohmann/json/tree/develop/test/src) - These files contain the [Catch](https://github.com/philsquared/Catch) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code.
|
||||
2. [`test/src/unit-*.cpp`](https://github.com/nlohmann/json/tree/develop/test/src) - These files contain the [doctest](https://github.com/onqtam/doctest) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code.
|
||||
|
||||
If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled and executed with
|
||||
|
||||
|
2
Makefile
2
Makefile
@ -100,7 +100,7 @@ doctest:
|
||||
# -Wno-c++2a-compat: u8 literals will behave differently in C++20...
|
||||
# -Wno-deprecated-declarations: the library deprecated some functions
|
||||
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
|
||||
# -Wno-exit-time-destructors: warning in Catch code
|
||||
# -Wno-exit-time-destructors: warning in json code triggered by NLOHMANN_JSON_SERIALIZE_ENUM
|
||||
# -Wno-float-equal: not all comparisons in the tests can be replaced by Approx
|
||||
# -Wno-keyword-macro: unit-tests use "#define private public"
|
||||
# -Wno-padded: padding is nothing to warn about
|
||||
|
@ -1270,13 +1270,13 @@ The library itself consists of a single header file licensed under the MIT licen
|
||||
- [**American fuzzy lop**](http://lcamtuf.coredump.cx/afl/) for fuzz testing
|
||||
- [**AppVeyor**](https://www.appveyor.com) for [continuous integration](https://ci.appveyor.com/project/nlohmann/json) on Windows
|
||||
- [**Artistic Style**](http://astyle.sourceforge.net) for automatic source code identation
|
||||
- [**Catch**](https://github.com/philsquared/Catch) for the unit tests
|
||||
- [**Clang**](http://clang.llvm.org) for compilation with code sanitizers
|
||||
- [**CMake**](https://cmake.org) for build automation
|
||||
- [**Codacity**](https://www.codacy.com) for further [code analysis](https://www.codacy.com/app/nlohmann/json)
|
||||
- [**Coveralls**](https://coveralls.io) to measure [code coverage](https://coveralls.io/github/nlohmann/json)
|
||||
- [**Coverity Scan**](https://scan.coverity.com) for [static analysis](https://scan.coverity.com/projects/nlohmann-json)
|
||||
- [**cppcheck**](http://cppcheck.sourceforge.net) for static analysis
|
||||
- [**doctest**](https://github.com/onqtam/doctest) for the unit tests
|
||||
- [**Doozer**](https://doozer.io) for [continuous integration](https://doozer.io/nlohmann/json) on Linux (CentOS, Raspbian, Fedora)
|
||||
- [**Doxygen**](http://www.stack.nl/~dimitri/doxygen/) to generate [documentation](https://nlohmann.github.io/json/)
|
||||
- [**git-update-ghpages**](https://github.com/rstacruz/git-update-ghpages) to upload the documentation to gh-pages
|
||||
|
@ -22,7 +22,7 @@ if(JSON_NoExceptions)
|
||||
if(NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJSON_NOEXCEPTION")
|
||||
endif()
|
||||
set(CATCH_TEST_FILTER -e)
|
||||
set(DOCTEST_TEST_FILTER --no-throw)
|
||||
endif()
|
||||
|
||||
if(JSON_Coverage)
|
||||
@ -54,22 +54,22 @@ if(JSON_Coverage)
|
||||
endif()
|
||||
|
||||
#############################################################################
|
||||
# Catch library with the main function to speed up build
|
||||
# doctest library with the main function to speed up build
|
||||
#############################################################################
|
||||
|
||||
add_library(catch_main OBJECT
|
||||
add_library(doctest_main OBJECT
|
||||
"src/unit.cpp"
|
||||
)
|
||||
set_target_properties(catch_main PROPERTIES
|
||||
set_target_properties(doctest_main PROPERTIES
|
||||
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
|
||||
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
|
||||
)
|
||||
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
|
||||
target_compile_features(catch_main PUBLIC cxx_range_for)
|
||||
target_compile_features(doctest_main PUBLIC cxx_range_for)
|
||||
else()
|
||||
target_compile_features(catch_main PUBLIC cxx_std_11)
|
||||
target_compile_features(doctest_main PUBLIC cxx_std_11)
|
||||
endif()
|
||||
target_include_directories(catch_main PRIVATE "thirdparty/catch")
|
||||
target_include_directories(doctest_main PRIVATE "thirdparty/doctest")
|
||||
|
||||
# https://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake
|
||||
if(MSVC)
|
||||
@ -99,10 +99,9 @@ foreach(file ${files})
|
||||
get_filename_component(file_basename ${file} NAME_WE)
|
||||
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename})
|
||||
|
||||
add_executable(${testcase} $<TARGET_OBJECTS:catch_main> ${file})
|
||||
add_executable(${testcase} $<TARGET_OBJECTS:doctest_main> ${file})
|
||||
target_compile_definitions(${testcase} PRIVATE
|
||||
CATCH_CONFIG_FAST_COMPILE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>
|
||||
DOCTEST_CONFIG_SUPER_FAST_ASSERTS
|
||||
)
|
||||
target_compile_options(${testcase} PRIVATE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
|
||||
@ -110,26 +109,26 @@ foreach(file ${files})
|
||||
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
||||
)
|
||||
target_include_directories(${testcase} PRIVATE
|
||||
thirdparty/catch
|
||||
thirdparty/doctest
|
||||
thirdparty/fifo_map
|
||||
)
|
||||
target_link_libraries(${testcase} ${NLOHMANN_JSON_TARGET_NAME})
|
||||
|
||||
add_test(NAME "${testcase}_default"
|
||||
COMMAND ${testcase} ${CATCH_TEST_FILTER}
|
||||
COMMAND ${testcase} ${DOCTEST_TEST_FILTER}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
set_tests_properties("${testcase}_default" PROPERTIES LABELS "default")
|
||||
|
||||
add_test(NAME "${testcase}_all"
|
||||
COMMAND ${testcase} ${CATCH_TEST_FILTER} "*"
|
||||
COMMAND ${testcase} ${DOCTEST_TEST_FILTER} --no-skip
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
set_tests_properties("${testcase}_all" PROPERTIES LABELS "all")
|
||||
|
||||
if(JSON_Valgrind)
|
||||
add_test(NAME "${testcase}_valgrind"
|
||||
COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${testcase} ${CATCH_TEST_FILTER}
|
||||
COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${testcase} ${DOCTEST_TEST_FILTER}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
set_tests_properties("${testcase}_valgrind" PROPERTIES LABELS "valgrind")
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
# additional flags
|
||||
CXXFLAGS += -std=c++11 -Wall -Wextra -pedantic -Wcast-align -Wcast-qual -Wno-ctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder -Wdeprecated -Wno-float-equal
|
||||
CPPFLAGS += -I ../single_include -I . -I thirdparty/catch -I thirdparty/fifo_map -DCATCH_CONFIG_FAST_COMPILE
|
||||
CPPFLAGS += -I ../single_include -I . -I thirdparty/doctest -I thirdparty/fifo_map -DDOCTEST_CONFIG_SUPER_FAST_ASSERTS
|
||||
|
||||
SOURCES = src/unit.cpp \
|
||||
src/unit-algorithms.cpp \
|
||||
@ -63,11 +63,11 @@ clean:
|
||||
# single test file
|
||||
##############################################################################
|
||||
|
||||
json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/catch/catch.hpp
|
||||
json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
|
||||
@echo "[CXXLD] $@"
|
||||
@$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJECTS) -o $@
|
||||
|
||||
%.o: %.cpp ../single_include/nlohmann/json.hpp thirdparty/catch/catch.hpp
|
||||
%.o: %.cpp ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
|
||||
@echo "[CXX] $@"
|
||||
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
@ -76,7 +76,7 @@ json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/catch/catch
|
||||
# individual test cases
|
||||
##############################################################################
|
||||
|
||||
test-%: src/unit-%.o src/unit.o ../single_include/nlohmann/json.hpp thirdparty/catch/catch.hpp
|
||||
test-%: src/unit-%.o src/unit.o ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
|
||||
@echo "[CXXLD] $@"
|
||||
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $< src/unit.o -o $@
|
||||
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
// special test case to check if memory is leaked if constructor throws
|
||||
|
||||
|
@ -27,9 +27,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
|
@ -27,11 +27,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
TEST_CASE("BSON")
|
||||
{
|
||||
@ -1138,7 +1140,7 @@ TEST_CASE("BSON numerical data")
|
||||
};
|
||||
|
||||
CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.407] integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64");
|
||||
CHECK_THROWS_WITH_STD_STR(json::to_bson(j), "[json.exception.out_of_range.407] integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1146,7 +1148,7 @@ TEST_CASE("BSON numerical data")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("BSON roundtrips", "[hide]")
|
||||
TEST_CASE("BSON roundtrips" * doctest::skip())
|
||||
{
|
||||
SECTION("reference files")
|
||||
{
|
||||
@ -1161,8 +1163,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
|
||||
{
|
||||
CAPTURE(filename)
|
||||
|
||||
SECTION(filename + ": std::vector<uint8_t>")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1179,8 +1181,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": std::ifstream")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::ifstream");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1194,8 +1196,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": uint8_t* and size")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": uint8_t* and size");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1212,8 +1214,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": output to output adapters")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output to output adapters");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1224,8 +1226,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
|
||||
(std::istreambuf_iterator<char>(f_bson)),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
||||
SECTION(filename + ": output adapters: std::vector<uint8_t>")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
std::vector<uint8_t> vec;
|
||||
json::to_bson(j1, vec);
|
||||
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,12 +27,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <set>
|
||||
|
||||
class SaxCountdown
|
||||
{
|
||||
@ -1586,7 +1590,8 @@ TEST_CASE("single CBOR roundtrip")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("CBOR regressions", "[!throws]")
|
||||
#if not defined(JSON_NOEXCEPTION)
|
||||
TEST_CASE("CBOR regressions")
|
||||
{
|
||||
SECTION("fuzz test results")
|
||||
{
|
||||
@ -1655,12 +1660,13 @@ TEST_CASE("CBOR regressions", "[!throws]")
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("CBOR roundtrips", "[hide]")
|
||||
TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
{
|
||||
SECTION("input from flynn")
|
||||
{
|
||||
// most of these are exluded due to differences in key order (not a real problem)
|
||||
// most of these are excluded due to differences in key order (not a real problem)
|
||||
auto exclude_packed = std::set<std::string>
|
||||
{
|
||||
"test/data/json.org/1.json",
|
||||
@ -1827,8 +1833,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
|
||||
{
|
||||
CAPTURE(filename)
|
||||
|
||||
SECTION(filename + ": std::vector<uint8_t>")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1845,8 +1851,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": std::ifstream")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::ifstream");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1860,8 +1866,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": uint8_t* and size")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": uint8_t* and size");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1878,8 +1884,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": output to output adapters")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output to output adapters");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1892,8 +1898,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
|
||||
|
||||
if (!exclude_packed.count(filename))
|
||||
{
|
||||
SECTION(filename + ": output adapters: std::vector<uint8_t>")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
std::vector<uint8_t> vec;
|
||||
json::to_cbor(j1, vec);
|
||||
CHECK(vec == packed);
|
||||
@ -1904,7 +1910,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("all CBOR first bytes", "[!throws]")
|
||||
#if not defined(JSON_NOEXCEPTION)
|
||||
TEST_CASE("all CBOR first bytes")
|
||||
{
|
||||
// these bytes will fail immediately with exception parse_error.112
|
||||
std::set<uint8_t> unsupported =
|
||||
@ -1968,7 +1975,7 @@ TEST_CASE("all CBOR first bytes", "[!throws]")
|
||||
{
|
||||
// check that parse_error.112 is only thrown if the
|
||||
// first byte is in the unsupported set
|
||||
CAPTURE(e.what())
|
||||
INFO_WITH_TEMP(e.what());
|
||||
if (std::find(unsupported.begin(), unsupported.end(), byte) != unsupported.end())
|
||||
{
|
||||
CHECK(e.id == 112);
|
||||
@ -1980,6 +1987,7 @@ TEST_CASE("all CBOR first bytes", "[!throws]")
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("examples from RFC 7049 Appendix A")
|
||||
{
|
||||
|
@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
TEST_CASE("const_iterator class")
|
||||
{
|
||||
|
@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
TEST_CASE("iterator class")
|
||||
{
|
||||
|
@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
// shortcut to scan a string literal
|
||||
json::lexer::token_type scan_string(const char* s);
|
||||
|
@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
#include <valarray>
|
||||
|
||||
@ -1105,8 +1106,8 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'");
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1181,8 +1182,8 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s1.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'");
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s1.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s2)
|
||||
@ -1190,8 +1191,8 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s2.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'");
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s2.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s3)
|
||||
@ -1199,8 +1200,8 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s3.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'");
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s3.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s4)
|
||||
@ -1208,8 +1209,8 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s4.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'");
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s4.c_str()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,16 +27,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <fstream>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <valarray>
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,11 +27,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void check_escaped(const char* original, const char* escaped = "", const bool ensure_ascii = false);
|
||||
void check_escaped(const char* original, const char* escaped, const bool ensure_ascii)
|
||||
|
@ -27,15 +27,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <valarray>
|
||||
|
@ -27,12 +27,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <valarray>
|
||||
|
||||
struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
@ -1072,7 +1072,8 @@ TEST_CASE("element access 2")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("element access 2 (throwing tests)", "[!throws]")
|
||||
#if not defined(JSON_NOEXCEPTION)
|
||||
TEST_CASE("element access 2 (throwing tests)")
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
@ -1105,3 +1106,4 @@ TEST_CASE("element access 2 (throwing tests)", "[!throws]")
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -27,12 +27,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
TEST_CASE("object inspection")
|
||||
{
|
||||
SECTION("convenience type checker")
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
TEST_CASE("iterators 1")
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
@ -342,7 +342,7 @@ TEST_CASE("JSON patch")
|
||||
|
||||
// check that evaluation throws
|
||||
CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
|
||||
CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
|
||||
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
|
||||
}
|
||||
|
||||
SECTION("A.10. Adding a Nested Member Object")
|
||||
@ -483,7 +483,7 @@ TEST_CASE("JSON patch")
|
||||
|
||||
// check that evaluation throws
|
||||
CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
|
||||
CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
|
||||
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
|
||||
}
|
||||
|
||||
SECTION("A.16. Adding an Array Value")
|
||||
@ -1182,7 +1182,7 @@ TEST_CASE("JSON patch")
|
||||
|
||||
// the test will fail
|
||||
CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
|
||||
CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
|
||||
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1268,7 +1268,7 @@ TEST_CASE("JSON patch")
|
||||
|
||||
for (const auto& test : suite)
|
||||
{
|
||||
CAPTURE(test.value("comment", ""))
|
||||
INFO_WITH_TEMP(test.value("comment", ""));
|
||||
|
||||
// skip tests marked as disabled
|
||||
if (test.value("disabled", false))
|
||||
|
@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
TEST_CASE("JSON pointers")
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,12 +27,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <set>
|
||||
|
||||
class SaxCountdown
|
||||
{
|
||||
@ -1345,7 +1348,7 @@ TEST_CASE("single MessagePack roundtrip")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("MessagePack roundtrips", "[hide]")
|
||||
TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
{
|
||||
SECTION("input from msgpack-python")
|
||||
{
|
||||
@ -1519,8 +1522,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
|
||||
{
|
||||
CAPTURE(filename)
|
||||
|
||||
SECTION(filename + ": std::vector<uint8_t>")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1537,8 +1540,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": std::ifstream")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::ifstream");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1552,8 +1555,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": uint8_t* and size")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": uint8_t* and size");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1570,8 +1573,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": output to output adapters")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output to output adapters");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1584,8 +1587,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
|
||||
|
||||
if (!exclude_packed.count(filename))
|
||||
{
|
||||
SECTION(filename + ": output adapters: std::vector<uint8_t>")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
std::vector<uint8_t> vec;
|
||||
json::to_msgpack(j1, vec);
|
||||
CHECK(vec == packed);
|
||||
|
@ -27,7 +27,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using nlohmann::json;
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,7 +27,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
@ -35,16 +36,19 @@ using nlohmann::json;
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable : 4189) // local variable is initialized but not referenced
|
||||
#endif
|
||||
|
||||
TEST_CASE("README", "[hide]")
|
||||
TEST_CASE("README" * doctest::skip())
|
||||
{
|
||||
{
|
||||
// redirect std::cout for the README file
|
||||
|
@ -27,7 +27,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -27,11 +27,21 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
|
||||
|
||||
// for some reason including this after the json header leads to linker errors with VS 2017...
|
||||
#include <locale>
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <list>
|
||||
#include <cstdio>
|
||||
|
||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
||||
#define JSON_HAS_CPP_17
|
||||
@ -43,10 +53,6 @@ using nlohmann::json;
|
||||
|
||||
#include "fifo_map.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <list>
|
||||
#include <cstdio>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #972
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
@ -287,7 +293,7 @@ TEST_CASE("regression tests")
|
||||
int number = j["Number"];
|
||||
CHECK(number == 100);
|
||||
float foo = j["Foo"];
|
||||
CHECK(foo == Approx(42.42));
|
||||
CHECK(static_cast<double>(foo) == Approx(42.42));
|
||||
}
|
||||
|
||||
SECTION("issue #89 - nonstandard integer type")
|
||||
@ -297,8 +303,7 @@ TEST_CASE("regression tests")
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, int32_t, uint32_t, float>;
|
||||
custom_json j;
|
||||
j["int_1"] = 1;
|
||||
// we need to cast to int to compile with Catch - the value is int32_t
|
||||
CHECK(static_cast<int>(j["int_1"]) == 1);
|
||||
CHECK(j["int_1"] == 1);
|
||||
|
||||
// tests for correct handling of non-standard integers that overflow the type selected by the user
|
||||
|
||||
@ -1780,7 +1785,8 @@ TEST_CASE("regression tests")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("regression tests, exceptions dependent", "[!throws]")
|
||||
#if not defined(JSON_NOEXCEPTION)
|
||||
TEST_CASE("regression tests, exceptions dependent")
|
||||
{
|
||||
SECTION("issue #1340 - eof not set on exhausted input stream")
|
||||
{
|
||||
@ -1792,3 +1798,4 @@ TEST_CASE("regression tests, exceptions dependent", "[!throws]")
|
||||
CHECK(s.eof());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -27,11 +27,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
TEST_CASE("serialization")
|
||||
{
|
||||
SECTION("operator<<")
|
||||
|
@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
@ -31,7 +31,7 @@ SOFTWARE.
|
||||
// Only compile these tests if 'float' and 'double' are IEEE-754 single- and
|
||||
// double-precision numbers, resp.
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::detail::dtoa_impl::reinterpret_bits;
|
||||
|
@ -27,12 +27,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
|
||||
class SaxCountdown
|
||||
{
|
||||
@ -2113,7 +2114,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("all UBJSON first bytes", "[!throws]")
|
||||
#if not defined(JSON_NOEXCEPTION)
|
||||
TEST_CASE("all UBJSON first bytes")
|
||||
{
|
||||
// these bytes will fail immediately with exception parse_error.112
|
||||
std::set<uint8_t> supported =
|
||||
@ -2134,7 +2136,7 @@ TEST_CASE("all UBJSON first bytes", "[!throws]")
|
||||
{
|
||||
// check that parse_error.112 is only thrown if the
|
||||
// first byte is not in the supported set
|
||||
CAPTURE(e.what())
|
||||
INFO_WITH_TEMP(e.what());
|
||||
if (std::find(supported.begin(), supported.end(), byte) == supported.end())
|
||||
{
|
||||
CHECK(e.id == 112);
|
||||
@ -2146,8 +2148,9 @@ TEST_CASE("all UBJSON first bytes", "[!throws]")
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("UBJSON roundtrips", "[hide]")
|
||||
TEST_CASE("UBJSON roundtrips" * doctest::skip())
|
||||
{
|
||||
SECTION("input from self-generated UBJSON files")
|
||||
{
|
||||
@ -2199,8 +2202,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
|
||||
{
|
||||
CAPTURE(filename)
|
||||
|
||||
SECTION(filename + ": std::vector<uint8_t>")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2217,8 +2220,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": std::ifstream")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::ifstream");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2232,8 +2235,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": uint8_t* and size")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": uint8_t* and size");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2250,8 +2253,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": output to output adapters")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output to output adapters");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2262,8 +2265,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
|
||||
(std::istreambuf_iterator<char>(f_ubjson)),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
||||
SECTION(filename + ": output adapters: std::vector<uint8_t>")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
std::vector<uint8_t> vec;
|
||||
json::to_ubjson(j1, vec);
|
||||
CHECK(vec == packed);
|
||||
|
@ -27,10 +27,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
#include <array>
|
||||
@ -236,7 +235,7 @@ void from_json(const nlohmann::json& j, contact_book& cb)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("basic usage", "[udt]")
|
||||
TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
{
|
||||
|
||||
// a bit narcissic maybe :) ?
|
||||
@ -392,7 +391,7 @@ struct adl_serializer<udt::legacy_type>
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("adl_serializer specialization", "[udt]")
|
||||
TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
|
||||
{
|
||||
SECTION("partial specialization")
|
||||
{
|
||||
@ -468,7 +467,7 @@ struct adl_serializer<std::vector<float>>
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("even supported types can be specialized", "[udt]")
|
||||
TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt"))
|
||||
{
|
||||
json j = std::vector<float> {1.0, 2.0, 3.0};
|
||||
CHECK(j.dump() == R"("hijacked!")");
|
||||
@ -509,7 +508,7 @@ struct adl_serializer<std::unique_ptr<T>>
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("Non-copyable types", "[udt]")
|
||||
TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
|
||||
{
|
||||
SECTION("to_json")
|
||||
{
|
||||
@ -650,7 +649,7 @@ std::ostream& operator<<(std::ostream& os, small_pod l)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("custom serializer for pods", "[udt]")
|
||||
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
|
||||
{
|
||||
using custom_json =
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool,
|
||||
@ -691,7 +690,7 @@ struct another_adl_serializer
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("custom serializer that does adl by default", "[udt]")
|
||||
TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("udt"))
|
||||
{
|
||||
using json = nlohmann::json;
|
||||
|
||||
@ -797,7 +796,7 @@ template <typename T>
|
||||
struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {};
|
||||
}
|
||||
|
||||
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context", "[udt]")
|
||||
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context" * doctest::test_suite("udt"))
|
||||
{
|
||||
static_assert(not is_constructible_patched<json, incomplete>::value, "");
|
||||
}
|
||||
|
@ -27,14 +27,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
// for some reason including this after the json header leads to linker errors with VS 2017...
|
||||
#include <locale>
|
||||
|
||||
#define private public
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
#undef private
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
extern size_t calls;
|
||||
size_t calls = 0;
|
||||
@ -160,7 +166,7 @@ void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Unicode", "[hide]")
|
||||
TEST_CASE("Unicode" * doctest::skip())
|
||||
{
|
||||
SECTION("RFC 3629")
|
||||
{
|
||||
|
@ -27,10 +27,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
bool wstring_is_utf16();
|
||||
|
@ -27,5 +27,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest_compatibility.h"
|
||||
|
23
test/thirdparty/catch/LICENSE_1_0.txt
vendored
23
test/thirdparty/catch/LICENSE_1_0.txt
vendored
@ -1,23 +0,0 @@
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
11689
test/thirdparty/catch/catch.hpp
vendored
11689
test/thirdparty/catch/catch.hpp
vendored
File diff suppressed because it is too large
Load Diff
21
test/thirdparty/doctest/LICENSE.txt
vendored
Normal file
21
test/thirdparty/doctest/LICENSE.txt
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2018 Viktor Kirilov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
6025
test/thirdparty/doctest/doctest.h
vendored
Normal file
6025
test/thirdparty/doctest/doctest.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
37
test/thirdparty/doctest/doctest_compatibility.h
vendored
Normal file
37
test/thirdparty/doctest/doctest_compatibility.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef DOCTEST_COMPATIBILITY
|
||||
#define DOCTEST_COMPATIBILITY
|
||||
|
||||
#define DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
|
||||
#define DOCTEST_THREAD_LOCAL // enable single-threaded builds on XCode 6/7 - https://github.com/onqtam/doctest/issues/172
|
||||
#include "doctest.h"
|
||||
|
||||
// Catch doesn't require a semicolon after CAPTURE but doctest does
|
||||
#undef CAPTURE
|
||||
#define CAPTURE(x) DOCTEST_CAPTURE(x);
|
||||
|
||||
// Sections from Catch are called Subcases in doctest and don't work with std::string by default
|
||||
#undef SUBCASE
|
||||
#define SECTION(x) DOCTEST_SUBCASE(x)
|
||||
|
||||
// convenience macro around INFO since it doesn't support temporaries (it is optimized to avoid allocations for runtime speed)
|
||||
#define INFO_WITH_TEMP_IMPL(x, var_name) const auto var_name = x; INFO(var_name) // lvalue!
|
||||
#define INFO_WITH_TEMP(x) INFO_WITH_TEMP_IMPL(x, DOCTEST_ANONYMOUS(DOCTEST_STD_STRING_))
|
||||
|
||||
// doctest doesn't support THROWS_WITH for std::string out of the box (has to include <string>...)
|
||||
#define CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, var_name) \
|
||||
do { \
|
||||
std::string var_name = str; \
|
||||
CHECK_THROWS_WITH(expr, var_name.c_str()); \
|
||||
} while (false)
|
||||
#define CHECK_THROWS_WITH_STD_STR(expr, str) \
|
||||
CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, DOCTEST_ANONYMOUS(DOCTEST_STD_STRING_))
|
||||
|
||||
// included here because for some tests in the json repository private is defined as
|
||||
// public and if no STL header is included before that then in the json include when STL
|
||||
// stuff is included the MSVC STL complains (errors) that C++ keywords are being redefined
|
||||
#include <iosfwd>
|
||||
|
||||
// Catch does this by default
|
||||
using doctest::Approx;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user