Introduce structure to the test/ directory

This introduces a clear separation between test data and test
binaries. Test data is moved into test/data, and the test binaries
move into test/src. A new CMake script specific to building the
tests is introduced in /test to slightly clean up the toplevel
one.

As well as tidying things up, this makes the next step trivial...
This commit is contained in:
Chris Kitching committed 2016-05-11 01:30:08 +01:00
1 parent 4e6aacda36
commit af76508fe7
87 files changed
+103 -98

No files matched your search

+1 -1
View File
@@ -35,7 +35,7 @@ There are currently two files which need to be edited:
To run [`re2c`](http://re2c.org) and generate/overwrite file `src/json.hpp` with your changes in file `src/json.hpp.re2c`. To run [`re2c`](http://re2c.org) and generate/overwrite file `src/json.hpp` with your changes in file `src/json.hpp.re2c`.
2. [`test/unit.cpp`](https://github.com/nlohmann/json/blob/master/test/unit.cpp) - This contains 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/blob/master/test/unit.cpp) - This contains the [Catch](https://github.com/philsquared/Catch) 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 with If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled with
+1 -1
View File
@@ -14,7 +14,7 @@ There are currently two files which need to be edited:
To run [`re2c`](http://re2c.org) and generate/overwrite file `src/json.hpp` with your changes in file `src/json.hpp.re2c`. To run [`re2c`](http://re2c.org) and generate/overwrite file `src/json.hpp` with your changes in file `src/json.hpp.re2c`.
2. [`test/unit.cpp`](https://github.com/nlohmann/json/blob/master/test/unit.cpp) - This contains 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/blob/master/test/unit.cpp) - This contains the [Catch](https://github.com/philsquared/Catch) 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 with If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled with
+1 -1
View File
@@ -19,7 +19,7 @@ matrix:
- touch src/json.hpp - touch src/json.hpp
- make json_unit CXXFLAGS="-fprofile-arcs -ftest-coverage -std=c++11 -lstdc++" CXX=$COMPILER - make json_unit CXXFLAGS="-fprofile-arcs -ftest-coverage -std=c++11 -lstdc++" CXX=$COMPILER
- ./json_unit "*" - ./json_unit "*"
- coveralls --exclude test/catch.hpp --exclude test/unit.cpp --include src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9' - coveralls --exclude test/src/catch.hpp --exclude test/src/unit.cpp --include src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9'
env: COMPILER=g++-4.9 env: COMPILER=g++-4.9
- os: linux - os: linux
+1 -11
View File
@@ -22,17 +22,7 @@ target_include_directories(${JSON_TARGET_NAME} INTERFACE
# create and configure the unit test target # create and configure the unit test target
if (BuildTests) if (BuildTests)
add_executable(json_unit add_subdirectory(test)
"test/catch.hpp"
"test/unit.cpp"
)
set_target_properties(json_unit PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>")
target_include_directories(json_unit PRIVATE "test")
target_link_libraries(json_unit ${JSON_TARGET_NAME})
endif() endif()
# generate a config and config version file for the package # generate a config and config version file for the package
+5 -5
View File
@@ -19,8 +19,8 @@ clean:
# additional flags # additional flags
FLAGS = -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wctor-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 -Wfloat-equal FLAGS = -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wctor-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 -Wfloat-equal
# build unit tests # build unit tests (TODO: Does this want its own makefile?)
json_unit: test/unit.cpp src/json.hpp test/catch.hpp json_unit: test/src/unit.cpp src/json.hpp test/src/catch.hpp
$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src -I test $< $(LDFLAGS) -o $@ $(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src -I test $< $(LDFLAGS) -o $@
@@ -43,11 +43,11 @@ fuzz_testing:
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
$(MAKE) fuzz CXX=afl-clang++ $(MAKE) fuzz CXX=afl-clang++
mv fuzz fuzz-testing mv fuzz fuzz-testing
find test/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases find test/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzz" @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzz"
# the fuzzer binary # the fuzzer binary
fuzz: test/fuzz.cpp src/json.hpp fuzz: test/src/fuzz.cpp src/json.hpp
$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src $< $(LDFLAGS) -o $@ $(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src $< $(LDFLAGS) -o $@
@@ -75,7 +75,7 @@ pretty:
--indent-col1-comments --pad-oper --pad-header --align-pointer=type \ --indent-col1-comments --pad-oper --pad-header --align-pointer=type \
--align-reference=type --add-brackets --convert-tabs --close-templates \ --align-reference=type --add-brackets --convert-tabs --close-templates \
--lineend=linux --preserve-date --suffix=none --formatted \ --lineend=linux --preserve-date --suffix=none --formatted \
src/json.hpp src/json.hpp.re2c test/unit.cpp test/fuzz.cpp benchmarks/benchmarks.cpp doc/examples/*.cpp src/json.hpp src/json.hpp.re2c test/src/unit.cpp test/src/fuzz.cpp benchmarks/benchmarks.cpp doc/examples/*.cpp
########################################################################## ##########################################################################
+1 -1
View File
@@ -17,7 +17,7 @@ There are myriads of [JSON](http://json.org) libraries out there, and each may e
- **Trivial integration**. Our whole code consists of a single header file `json.hpp`. That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. - **Trivial integration**. Our whole code consists of a single header file `json.hpp`. That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings.
- **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks. - **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/src/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks.
Other aspects were not so important to us: Other aspects were not so important to us:
+15
View File
@@ -0,0 +1,15 @@
# The unit test executable.
add_executable(json_unit
"src/catch.hpp"
"src/unit.cpp"
)
set_target_properties(json_unit PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
)
target_include_directories(json_unit PRIVATE "src")
target_link_libraries(json_unit ${JSON_TARGET_NAME})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View File
File renamed without changes.
+78 -78
View File
@@ -1314,7 +1314,7 @@ TEST_CASE("constructors")
SECTION("std::ifstream") SECTION("std::ifstream")
{ {
std::ifstream f("test/json_tests/pass1.json"); std::ifstream f("test/data/json_tests/pass1.json");
json j(f); json j(f);
} }
} }
@@ -11652,39 +11652,39 @@ TEST_CASE("compliance tests from json.org")
{ {
for (auto filename : for (auto filename :
{ {
//"test/json_tests/fail1.json", //"test/data/json_tests/fail1.json",
"test/json_tests/fail2.json", "test/data/json_tests/fail2.json",
"test/json_tests/fail3.json", "test/data/json_tests/fail3.json",
"test/json_tests/fail4.json", "test/data/json_tests/fail4.json",
"test/json_tests/fail5.json", "test/data/json_tests/fail5.json",
"test/json_tests/fail6.json", "test/data/json_tests/fail6.json",
"test/json_tests/fail7.json", "test/data/json_tests/fail7.json",
"test/json_tests/fail8.json", "test/data/json_tests/fail8.json",
"test/json_tests/fail9.json", "test/data/json_tests/fail9.json",
"test/json_tests/fail10.json", "test/data/json_tests/fail10.json",
"test/json_tests/fail11.json", "test/data/json_tests/fail11.json",
"test/json_tests/fail12.json", "test/data/json_tests/fail12.json",
"test/json_tests/fail13.json", "test/data/json_tests/fail13.json",
"test/json_tests/fail14.json", "test/data/json_tests/fail14.json",
"test/json_tests/fail15.json", "test/data/json_tests/fail15.json",
"test/json_tests/fail16.json", "test/data/json_tests/fail16.json",
"test/json_tests/fail17.json", "test/data/json_tests/fail17.json",
//"test/json_tests/fail18.json", //"test/data/json_tests/fail18.json",
"test/json_tests/fail19.json", "test/data/json_tests/fail19.json",
"test/json_tests/fail20.json", "test/data/json_tests/fail20.json",
"test/json_tests/fail21.json", "test/data/json_tests/fail21.json",
"test/json_tests/fail22.json", "test/data/json_tests/fail22.json",
"test/json_tests/fail23.json", "test/data/json_tests/fail23.json",
"test/json_tests/fail24.json", "test/data/json_tests/fail24.json",
"test/json_tests/fail25.json", "test/data/json_tests/fail25.json",
"test/json_tests/fail26.json", "test/data/json_tests/fail26.json",
"test/json_tests/fail27.json", "test/data/json_tests/fail27.json",
"test/json_tests/fail28.json", "test/data/json_tests/fail28.json",
"test/json_tests/fail29.json", "test/data/json_tests/fail29.json",
"test/json_tests/fail30.json", "test/data/json_tests/fail30.json",
"test/json_tests/fail31.json", "test/data/json_tests/fail31.json",
"test/json_tests/fail32.json", "test/data/json_tests/fail32.json",
"test/json_tests/fail33.json" "test/data/json_tests/fail33.json"
}) })
{ {
CAPTURE(filename); CAPTURE(filename);
@@ -11698,9 +11698,9 @@ TEST_CASE("compliance tests from json.org")
{ {
for (auto filename : for (auto filename :
{ {
"test/json_tests/pass1.json", "test/data/json_tests/pass1.json",
"test/json_tests/pass2.json", "test/data/json_tests/pass2.json",
"test/json_tests/pass3.json" "test/data/json_tests/pass3.json"
}) })
{ {
CAPTURE(filename); CAPTURE(filename);
@@ -11873,42 +11873,42 @@ TEST_CASE("compliance tests from nativejson-benchmark")
SECTION("roundtrip") SECTION("roundtrip")
{ {
// test cases are from https://github.com/miloyip/nativejson-benchmark/tree/master/data/roundtrip // test cases are from https://github.com/miloyip/nativejson-benchmark/tree/master/test/data/roundtrip
for (auto filename : for (auto filename :
{ {
"test/json_roundtrip/roundtrip01.json", "test/data/json_roundtrip/roundtrip01.json",
"test/json_roundtrip/roundtrip02.json", "test/data/json_roundtrip/roundtrip02.json",
"test/json_roundtrip/roundtrip03.json", "test/data/json_roundtrip/roundtrip03.json",
"test/json_roundtrip/roundtrip04.json", "test/data/json_roundtrip/roundtrip04.json",
"test/json_roundtrip/roundtrip05.json", "test/data/json_roundtrip/roundtrip05.json",
"test/json_roundtrip/roundtrip06.json", "test/data/json_roundtrip/roundtrip06.json",
"test/json_roundtrip/roundtrip07.json", "test/data/json_roundtrip/roundtrip07.json",
"test/json_roundtrip/roundtrip08.json", "test/data/json_roundtrip/roundtrip08.json",
"test/json_roundtrip/roundtrip09.json", "test/data/json_roundtrip/roundtrip09.json",
"test/json_roundtrip/roundtrip10.json", "test/data/json_roundtrip/roundtrip10.json",
"test/json_roundtrip/roundtrip11.json", "test/data/json_roundtrip/roundtrip11.json",
"test/json_roundtrip/roundtrip12.json", "test/data/json_roundtrip/roundtrip12.json",
"test/json_roundtrip/roundtrip13.json", "test/data/json_roundtrip/roundtrip13.json",
"test/json_roundtrip/roundtrip14.json", "test/data/json_roundtrip/roundtrip14.json",
"test/json_roundtrip/roundtrip15.json", "test/data/json_roundtrip/roundtrip15.json",
"test/json_roundtrip/roundtrip16.json", "test/data/json_roundtrip/roundtrip16.json",
"test/json_roundtrip/roundtrip17.json", "test/data/json_roundtrip/roundtrip17.json",
"test/json_roundtrip/roundtrip18.json", "test/data/json_roundtrip/roundtrip18.json",
"test/json_roundtrip/roundtrip19.json", "test/data/json_roundtrip/roundtrip19.json",
"test/json_roundtrip/roundtrip20.json", "test/data/json_roundtrip/roundtrip20.json",
"test/json_roundtrip/roundtrip21.json", "test/data/json_roundtrip/roundtrip21.json",
"test/json_roundtrip/roundtrip22.json", "test/data/json_roundtrip/roundtrip22.json",
"test/json_roundtrip/roundtrip23.json", "test/data/json_roundtrip/roundtrip23.json",
"test/json_roundtrip/roundtrip24.json", "test/data/json_roundtrip/roundtrip24.json",
"test/json_roundtrip/roundtrip25.json", "test/data/json_roundtrip/roundtrip25.json",
"test/json_roundtrip/roundtrip26.json", "test/data/json_roundtrip/roundtrip26.json",
"test/json_roundtrip/roundtrip27.json", "test/data/json_roundtrip/roundtrip27.json",
"test/json_roundtrip/roundtrip28.json", "test/data/json_roundtrip/roundtrip28.json",
"test/json_roundtrip/roundtrip29.json", "test/data/json_roundtrip/roundtrip29.json",
"test/json_roundtrip/roundtrip30.json", "test/data/json_roundtrip/roundtrip30.json",
"test/json_roundtrip/roundtrip31.json", "test/data/json_roundtrip/roundtrip31.json",
"test/json_roundtrip/roundtrip32.json" "test/data/json_roundtrip/roundtrip32.json"
}) })
{ {
CAPTURE(filename); CAPTURE(filename);
@@ -11928,7 +11928,7 @@ TEST_CASE("test suite from json-test-suite")
{ {
// read a file with all unicode characters stored as single-character // read a file with all unicode characters stored as single-character
// strings in a JSON array // strings in a JSON array
std::ifstream f("test/json_testsuite/sample.json"); std::ifstream f("test/data/json_testsuite/sample.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
@@ -11943,35 +11943,35 @@ TEST_CASE("json.org examples")
SECTION("1.json") SECTION("1.json")
{ {
std::ifstream f("test/json.org/1.json"); std::ifstream f("test/data/json.org/1.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
} }
SECTION("2.json") SECTION("2.json")
{ {
std::ifstream f("test/json.org/2.json"); std::ifstream f("test/data/json.org/2.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
} }
SECTION("3.json") SECTION("3.json")
{ {
std::ifstream f("test/json.org/3.json"); std::ifstream f("test/data/json.org/3.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
} }
SECTION("4.json") SECTION("4.json")
{ {
std::ifstream f("test/json.org/4.json"); std::ifstream f("test/data/json.org/4.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
} }
SECTION("5.json") SECTION("5.json")
{ {
std::ifstream f("test/json.org/5.json"); std::ifstream f("test/data/json.org/5.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
} }
@@ -12105,7 +12105,7 @@ TEST_CASE("Unicode", "[hide]")
{ {
// read a file with all unicode characters stored as single-character // read a file with all unicode characters stored as single-character
// strings in a JSON array // strings in a JSON array
std::ifstream f("test/json_nlohmann_tests/all_unicode.json"); std::ifstream f("test/data/json_nlohmann_tests/all_unicode.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
@@ -12146,7 +12146,7 @@ TEST_CASE("Unicode", "[hide]")
SECTION("ignore byte-order-mark") SECTION("ignore byte-order-mark")
{ {
// read a file with a UTF-8 BOM // read a file with a UTF-8 BOM
std::ifstream f("test/json_nlohmann_tests/bom.json"); std::ifstream f("test/data/json_nlohmann_tests/bom.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
} }