public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-5473] json.cc: use SELFTEST_LOCATION in selftests
Date: Wed, 15 Nov 2023 00:50:59 +0000 (GMT) [thread overview]
Message-ID: <20231115005059.EBEF93858D32@sourceware.org> (raw)
https://gcc.gnu.org/g:2220263f0e032a6af3cea44a17735833baa5fd93
commit r14-5473-g2220263f0e032a6af3cea44a17735833baa5fd93
Author: David Malcolm <dmalcolm@redhat.com>
Date: Tue Nov 14 19:48:48 2023 -0500
json.cc: use SELFTEST_LOCATION in selftests
gcc/ChangeLog:
* json.cc (selftest::assert_print_eq): Add "loc" param and use
ASSERT_STREQ_AT.
(ASSERT_PRINT_EQ): New macro.
(selftest::test_writing_objects): Use ASSERT_PRINT_EQ to capture
source location of assertion.
(selftest::test_writing_arrays): Likewise.
(selftest::test_writing_float_numbers): Likewise.
(selftest::test_writing_integer_numbers): Likewise.
(selftest::test_writing_strings): Likewise.
(selftest::test_writing_literals): Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/json.cc | 51 +++++++++++++++++++++++++++------------------------
1 file changed, 27 insertions(+), 24 deletions(-)
diff --git a/gcc/json.cc b/gcc/json.cc
index f5398ece066..d0f157f0dfe 100644
--- a/gcc/json.cc
+++ b/gcc/json.cc
@@ -322,13 +322,16 @@ namespace selftest {
/* Verify that JV->print () prints EXPECTED_JSON. */
static void
-assert_print_eq (const json::value &jv, const char *expected_json)
+assert_print_eq (const location &loc, const json::value &jv, const char *expected_json)
{
pretty_printer pp;
jv.print (&pp);
- ASSERT_STREQ (expected_json, pp_formatted_text (&pp));
+ ASSERT_STREQ_AT (loc, expected_json, pp_formatted_text (&pp));
}
+#define ASSERT_PRINT_EQ(JV, EXPECTED_JSON) \
+ assert_print_eq (SELFTEST_LOCATION, JV, EXPECTED_JSON)
+
/* Verify that object::get works as expected. */
static void
@@ -351,7 +354,7 @@ test_writing_objects ()
obj.set_string ("baz", "quux");
/* This test relies on json::object writing out key/value pairs
in key-insertion order. */
- assert_print_eq (obj, "{\"foo\": \"bar\", \"baz\": \"quux\"}");
+ ASSERT_PRINT_EQ (obj, "{\"foo\": \"bar\", \"baz\": \"quux\"}");
}
/* Verify that JSON arrays are written correctly. */
@@ -360,13 +363,13 @@ static void
test_writing_arrays ()
{
array arr;
- assert_print_eq (arr, "[]");
+ ASSERT_PRINT_EQ (arr, "[]");
arr.append (new json::string ("foo"));
- assert_print_eq (arr, "[\"foo\"]");
+ ASSERT_PRINT_EQ (arr, "[\"foo\"]");
arr.append (new json::string ("bar"));
- assert_print_eq (arr, "[\"foo\", \"bar\"]");
+ ASSERT_PRINT_EQ (arr, "[\"foo\", \"bar\"]");
}
/* Verify that JSON numbers are written correctly. */
@@ -374,20 +377,20 @@ test_writing_arrays ()
static void
test_writing_float_numbers ()
{
- assert_print_eq (float_number (0), "0");
- assert_print_eq (float_number (42), "42");
- assert_print_eq (float_number (-100), "-100");
- assert_print_eq (float_number (123456789), "1.23457e+08");
+ ASSERT_PRINT_EQ (float_number (0), "0");
+ ASSERT_PRINT_EQ (float_number (42), "42");
+ ASSERT_PRINT_EQ (float_number (-100), "-100");
+ ASSERT_PRINT_EQ (float_number (123456789), "1.23457e+08");
}
static void
test_writing_integer_numbers ()
{
- assert_print_eq (integer_number (0), "0");
- assert_print_eq (integer_number (42), "42");
- assert_print_eq (integer_number (-100), "-100");
- assert_print_eq (integer_number (123456789), "123456789");
- assert_print_eq (integer_number (-123456789), "-123456789");
+ ASSERT_PRINT_EQ (integer_number (0), "0");
+ ASSERT_PRINT_EQ (integer_number (42), "42");
+ ASSERT_PRINT_EQ (integer_number (-100), "-100");
+ ASSERT_PRINT_EQ (integer_number (123456789), "123456789");
+ ASSERT_PRINT_EQ (integer_number (-123456789), "-123456789");
}
/* Verify that JSON strings are written correctly. */
@@ -396,16 +399,16 @@ static void
test_writing_strings ()
{
string foo ("foo");
- assert_print_eq (foo, "\"foo\"");
+ ASSERT_PRINT_EQ (foo, "\"foo\"");
string contains_quotes ("before \"quoted\" after");
- assert_print_eq (contains_quotes, "\"before \\\"quoted\\\" after\"");
+ ASSERT_PRINT_EQ (contains_quotes, "\"before \\\"quoted\\\" after\"");
const char data[] = {'a', 'b', 'c', 'd', '\0', 'e', 'f'};
string not_terminated (data, 3);
- assert_print_eq (not_terminated, "\"abc\"");
+ ASSERT_PRINT_EQ (not_terminated, "\"abc\"");
string embedded_null (data, sizeof data);
- assert_print_eq (embedded_null, "\"abcd\\0ef\"");
+ ASSERT_PRINT_EQ (embedded_null, "\"abcd\\0ef\"");
}
/* Verify that JSON literals are written correctly. */
@@ -413,12 +416,12 @@ test_writing_strings ()
static void
test_writing_literals ()
{
- assert_print_eq (literal (JSON_TRUE), "true");
- assert_print_eq (literal (JSON_FALSE), "false");
- assert_print_eq (literal (JSON_NULL), "null");
+ ASSERT_PRINT_EQ (literal (JSON_TRUE), "true");
+ ASSERT_PRINT_EQ (literal (JSON_FALSE), "false");
+ ASSERT_PRINT_EQ (literal (JSON_NULL), "null");
- assert_print_eq (literal (true), "true");
- assert_print_eq (literal (false), "false");
+ ASSERT_PRINT_EQ (literal (true), "true");
+ ASSERT_PRINT_EQ (literal (false), "false");
}
/* Run all of the selftests within this file. */
reply other threads:[~2023-11-15 0:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231115005059.EBEF93858D32@sourceware.org \
--to=dmalcolm@gcc.gnu.org \
--cc=gcc-cvs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).