From patchwork Wed Nov 15 00:52:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 165134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp2303821rwb; Tue, 14 Nov 2023 16:52:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxY5P6DjvnoXAKC62kyLASJr78tFCKRoxbQjsS8sGUW+6ivJhxkELh34IipWvODXxzUutD X-Received: by 2002:ae9:e917:0:b0:779:de52:8743 with SMTP id x23-20020ae9e917000000b00779de528743mr4258368qkf.27.1700009553275; Tue, 14 Nov 2023 16:52:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700009553; cv=pass; d=google.com; s=arc-20160816; b=Hz+MRTb+2HM32Hjh9i2dmnWXGC0dfMC3Xtam2DXahWtP/xrhAxYCREGR/55VjnFHIH GCzkax1yQBzptFs1FBU6eepRfPwIajS+c38/DENXluPzSAO36zg6HuVHXCmxBMVc0JXE ScnQ2OxrzOJuq/7BFpanlIHx3k1tQAdmsKhNhWL4wTU6OOA7xGzd8kXzPRw/efBG6ZPn NMm82n73WIoIfZBOYt62LXA5DgffhBo7uR9T1gNR98nmszu0cNvQk9B3JHT3juI256ki h1PljyUnXF1Ui7+dJQi6SxW1k/pV5QezLv/6T0Of6EaYzNOGJALtGFap5Nw2zCBmqIR9 mYbw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=A9iMxDMNqS14X9BonIrI+IZtsgKeVZNyFzQGGTHaVTE=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=ikAgjcwv1uN6XpR+Cf/V4xqqqH+knzcAVcMyHxMexv3Z1I7vQEAnIUUBIbya2b4RMH 50E42kP9vxWQb/hYrh9cxmFXZ1z+xy8H9IquyiXWeHdhhbwJZ8VVGLPITcrztyZWgxA1 E6EXOQYoF0RT6MRI3cWuxf5r2RyAr8no/P0CptUyyWf8alo8AAvKCxLeVfCPiw/Bo/ON 1pCHqkzMamzBIE0DVo3Hl5+K2K9y4SRJqXvEmOqXSE2jDgf+J60NKlvFVZ+nlEIlXi1U WboAcQaBeHswWrBXiUaNJNBggRRUEMd/XSXaBwQj+Bffxqn56jKK7C2Utlz4WxT4E1R0 Etlg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=L7QO4FZ4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i5-20020a05620a404500b0076d9d0b221csi8233202qko.366.2023.11.14.16.52.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 16:52:33 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=L7QO4FZ4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0AC793858D37 for ; Wed, 15 Nov 2023 00:52:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 884433858D32 for ; Wed, 15 Nov 2023 00:52:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 884433858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 884433858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700009528; cv=none; b=E9StE3bmcvPvoQlgDN6usda7ENSmm3cvt112Q3byu8PXY1rwQ/rbI2znTbO8NejmZdARHXMYF/hJzyTSH8PuMJ57wXRpZ6bD6YJ2qxQhXcfRQqQB5mY+WR1pa2U/DlPljpyZiFLAGbdZfWCnTefWgoaJ7J8JyIVhSNk7holdgsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700009528; c=relaxed/simple; bh=ZCn7OYTuoMTgdkhImTxT+snK8DHcKvprsnS9YNlNswE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=SPmJ7vI9DeZzCsELsplAypS+mcA6kiCpEawavJ54zCbTSwlqnrfEM4RhBrS8rAxxNQDxM9aUNXg/gy4WVZHv/9hj0PnQ9pWf8hXnCCOVQ/0A5OlKJEAnRC6vuOfbu/ADgprXSdy2liKAryYfTxssBqwvDxrVcXnXee30DkOnGx0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700009526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=A9iMxDMNqS14X9BonIrI+IZtsgKeVZNyFzQGGTHaVTE=; b=L7QO4FZ48R1yUZdswOfinfv/uGV/wzub9+9ql/mkOBEx+t50qN/QJJO/dhl3ZByOunqk7S 2BViCfknpCe096d+KwhaJIWvCe7SD8eSa+JkfW/zyNqI+K2J+F0zhwGs+8sjfqtKUL6YNX AiA0n1gX6PjJDLiJnHmMX7Panrt/Lwo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-TMVmr0_5PyKIjP5SzBf7aw-1; Tue, 14 Nov 2023 19:52:04 -0500 X-MC-Unique: TMVmr0_5PyKIjP5SzBf7aw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 53D2585A58A for ; Wed, 15 Nov 2023 00:52:04 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 185541C060AE; Wed, 15 Nov 2023 00:52:04 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] json.cc: use SELFTEST_LOCATION in selftests Date: Tue, 14 Nov 2023 19:52:03 -0500 Message-Id: <20231115005203.3748210-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782589217370696175 X-GMAIL-MSGID: 1782589217370696175 Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-5473-g2220263f0e032a. 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. --- gcc/json.cc | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/gcc/json.cc b/gcc/json.cc index f5398ece066a..d0f157f0dfe7 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. */