]> 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)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 28 Jul 2024 17:05:54 +0000 (19:05 +0200)
commite82aa0832a9ef222ce4a9340c2986019c168b8c0
tree69c44e272b8b8b2092cf6518a137cfe5614416e7
parent4068969756b961ccf3f16ab8a07e788f600bee13
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