Skip to content

Commit f50145f

Browse files
committed
Merge pull request open-source-parsers#201 from open-source-parsers/vs
* Copy .dll for running unit-tests in VisualStudio. * Stop using `do{}while(0)` idiom b/c VisualStudio warns. * Fix a warning in a test.
2 parents eaa3fd8 + b3e6f3d commit f50145f

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

include/json/assertions.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
#if JSON_USE_EXCEPTION
1717
#include <stdexcept>
1818
#define JSON_ASSERT(condition) \
19-
if (!(condition)) {throw std::logic_error( "assert json failed" );} // @todo <= add detail about condition in exception
20-
#define JSON_FAIL_MESSAGE(message) do{std::ostringstream oss; oss << message; throw std::logic_error(oss.str());}while(0)
19+
{if (!(condition)) {throw std::logic_error( "assert json failed" );}} // @todo <= add detail about condition in exception
20+
#define JSON_FAIL_MESSAGE(message) \
21+
{ \
22+
std::ostringstream oss; oss << message; \
23+
throw std::logic_error(oss.str()); \
24+
}
2125
//#define JSON_FAIL_MESSAGE(message) throw std::logic_error(message)
2226
#else // JSON_USE_EXCEPTION
23-
#define JSON_ASSERT(condition) assert(condition);
27+
#define JSON_ASSERT(condition) assert(condition)
2428

2529
// The call to assert() will show the failure message in debug builds. In
2630
// release bugs we abort, for a core-dump or debugger.

src/test_lib_json/CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# vim: et ts=4 sts=4 sw=4 tw=0
12

23
IF(JSONCPP_LIB_BUILD_SHARED)
34
ADD_DEFINITIONS( -DJSON_DLL )
@@ -22,9 +23,19 @@ ENDIF(JSONCPP_LIB_BUILD_SHARED)
2223
# Run unit tests in post-build
2324
# (default cmake workflow hides away the test result into a file, resulting in poor dev workflow?!?)
2425
IF(JSONCPP_WITH_POST_BUILD_UNITTEST)
25-
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
26-
POST_BUILD
27-
COMMAND $<TARGET_FILE:jsoncpp_test>)
26+
IF(JSONCPP_LIB_BUILD_SHARED)
27+
# First, copy the shared lib, for Microsoft.
28+
# Then, run the test executable.
29+
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
30+
POST_BUILD
31+
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:jsoncpp_lib> $<TARGET_FILE_DIR:jsoncpp_test>
32+
COMMAND $<TARGET_FILE:jsoncpp_test>)
33+
ELSE(JSONCPP_LIB_BUILD_SHARED)
34+
# Just run the test executable.
35+
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
36+
POST_BUILD
37+
COMMAND $<TARGET_FILE:jsoncpp_test>)
38+
ENDIF(JSONCPP_LIB_BUILD_SHARED)
2839
ENDIF(JSONCPP_WITH_POST_BUILD_UNITTEST)
2940

3041
SET_TARGET_PROPERTIES(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test)

src/test_lib_json/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,7 @@ JSONTEST_FIXTURE(IteratorTest, distance) {
22032203
Json::Value json;
22042204
json["k1"] = "a";
22052205
json["k2"] = "b";
2206-
int dist;
2206+
int dist = 0;
22072207
std::string str;
22082208
for (Json::ValueIterator it = json.begin(); it != json.end(); ++it) {
22092209
dist = it - json.begin();

0 commit comments

Comments
 (0)