🚨 fix warning
This commit is contained in:
parent
99fc6b16ab
commit
28ef87370b
2 changed files with 19 additions and 8 deletions
2
Makefile
2
Makefile
|
@ -97,6 +97,7 @@ doctest:
|
||||||
# -Wno-exit-time-destructors: warning in json code triggered by NLOHMANN_JSON_SERIALIZE_ENUM
|
# -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-float-equal: not all comparisons in the tests can be replaced by Approx
|
||||||
# -Wno-keyword-macro: unit-tests use "#define private public"
|
# -Wno-keyword-macro: unit-tests use "#define private public"
|
||||||
|
# -Wno-missing-prototypes: for NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
|
||||||
# -Wno-padded: padding is nothing to warn about
|
# -Wno-padded: padding is nothing to warn about
|
||||||
# -Wno-range-loop-analysis: items tests "for(const auto i...)"
|
# -Wno-range-loop-analysis: items tests "for(const auto i...)"
|
||||||
# -Wno-switch-enum -Wno-covered-switch-default: pedantic/contradicting warnings about switches
|
# -Wno-switch-enum -Wno-covered-switch-default: pedantic/contradicting warnings about switches
|
||||||
|
@ -113,6 +114,7 @@ pedantic_clang:
|
||||||
-Wno-exit-time-destructors \
|
-Wno-exit-time-destructors \
|
||||||
-Wno-float-equal \
|
-Wno-float-equal \
|
||||||
-Wno-keyword-macro \
|
-Wno-keyword-macro \
|
||||||
|
-Wno-missing-prototypes \
|
||||||
-Wno-padded \
|
-Wno-padded \
|
||||||
-Wno-range-loop-analysis \
|
-Wno-range-loop-analysis \
|
||||||
-Wno-switch-enum -Wno-covered-switch-default \
|
-Wno-switch-enum -Wno-covered-switch-default \
|
||||||
|
|
|
@ -27,24 +27,33 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// avoid warning when assert does not abort
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#pragma GCC diagnostic ignored "-Wstrict-overflow"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "doctest_compatibility.h"
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
/// global variable to record side effect of assert calls
|
/// global variable to record side effect of assert calls
|
||||||
int assert_counter = 0;
|
static int assert_counter;
|
||||||
|
|
||||||
/// set failure variable to true instead of calling assert(x)
|
/// set failure variable to true instead of calling assert(x)
|
||||||
#define JSON_ASSERT(x) if (!(x)) ++assert_counter;
|
#define JSON_ASSERT(x) {if (!(x)) ++assert_counter; }
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
TEST_CASE("JSON_ASSERT(x)")
|
TEST_CASE("JSON_ASSERT(x)")
|
||||||
{
|
{
|
||||||
const json j = {{"bar", 1}};
|
assert_counter = 0;
|
||||||
CHECK(assert_counter == 0);
|
const json j = {{"bar", 1}};
|
||||||
|
CHECK(assert_counter == 0);
|
||||||
|
|
||||||
// accessing non-exising key in const value would assert
|
// accessing non-existing key in const value would assert
|
||||||
j["foo"] == 1;
|
if (j["foo"] == 1)
|
||||||
|
{
|
||||||
|
CHECK(true);
|
||||||
|
}
|
||||||
|
|
||||||
CHECK(assert_counter == 1);
|
CHECK(assert_counter == 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue