]> git.ipfire.org Git - thirdparty/gcc.git/commit
diagnostics: add selftests for SARIF output
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 24 Jul 2024 22:07:56 +0000 (18:07 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 24 Jul 2024 22:07:56 +0000 (18:07 -0400)
commit68c7747dd29016d51e6f04e7fe1d8543423f093f
tree9702dd377ea477c6830328686ac018d9f11c4651
parentd7a688fc960f78c62aacdc5acb8432873fed300e
diagnostics: add selftests for SARIF output

The existing DejaGnu-based tests for our SARIF output used regexes
to verify the JSON at the string level, which lets us test for
the presence of properties, but doesn't check the overall structure.

This patch uses the selftest framework to verify the structure of
the tree of JSON values for a log containing one diagnostic.

No functional change intended.

gcc/ChangeLog:
* diagnostic-format-sarif.cc (sarif_builder::flush_to_object):
New, using code moved from...
(sarif_builder::end_group): ...here.
(class selftest::test_sarif_diagnostic_context): New.
(selftest::test_simple_log): New.
(selftest::diagnostic_format_sarif_cc_tests): Call it.
* json.h (json::object::is_empty): New.
* selftest-diagnostic.cc (test_diagnostic_context::report): New.
* selftest-diagnostic.h (test_diagnostic_context::report): New
decl.
* selftest-json.cc (selftest::assert_json_string_eq): New.
(selftest::expect_json_object_with_string_property): New.
(selftest::assert_json_string_property_eq): New.
* selftest-json.h (selftest::assert_json_string_eq): New decl.
(ASSERT_JSON_STRING_EQ): New macro.
(selftest::expect_json_object_with_string_property): New decl.
(EXPECT_JSON_OBJECT_WITH_STRING_PROPERTY): New macro.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/diagnostic-format-sarif.cc
gcc/json.h
gcc/selftest-diagnostic.cc
gcc/selftest-diagnostic.h
gcc/selftest-json.cc
gcc/selftest-json.h