Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
28ef8737
Unverified
Commit
28ef8737
authored
Jul 06, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚨
fix warning
parent
99fc6b16
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
Makefile
Makefile
+2
-0
test/src/unit-assert_macro.cpp
test/src/unit-assert_macro.cpp
+19
-10
No files found.
Makefile
View file @
28ef8737
...
...
@@ -97,6 +97,7 @@ doctest:
# -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-missing-prototypes: for NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
# -Wno-padded: padding is nothing to warn about
# -Wno-range-loop-analysis: items tests "for(const auto i...)"
# -Wno-switch-enum -Wno-covered-switch-default: pedantic/contradicting warnings about switches
...
...
@@ -113,6 +114,7 @@ pedantic_clang:
-Wno-exit-time-destructors
\
-Wno-float-equal
\
-Wno-keyword-macro
\
-Wno-missing-prototypes
\
-Wno-padded
\
-Wno-range-loop-analysis
\
-Wno-switch-enum -Wno-covered-switch-default
\
...
...
test/src/unit-assert_macro.cpp
View file @
28ef8737
...
...
@@ -27,24 +27,33 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// avoid warning when assert does not abort
#if defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wstrict-overflow"
#endif
#include "doctest_compatibility.h"
/// 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)
#define JSON_ASSERT(x)
if (!(x)) ++assert_counter;
#define JSON_ASSERT(x)
{if (!(x)) ++assert_counter; }
#include <nlohmann/json.hpp>
using
nlohmann
::
json
;
TEST_CASE
(
"JSON_ASSERT(x)"
)
{
const
json
j
=
{{
"bar"
,
1
}};
CHECK
(
assert_counter
==
0
);
// accessing non-exising key in const value would assert
j
[
"foo"
]
==
1
;
CHECK
(
assert_counter
==
1
);
}
\ No newline at end of file
assert_counter
=
0
;
const
json
j
=
{{
"bar"
,
1
}};
CHECK
(
assert_counter
==
0
);
// accessing non-existing key in const value would assert
if
(
j
[
"foo"
]
==
1
)
{
CHECK
(
true
);
}
CHECK
(
assert_counter
==
1
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment