From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by sourceware.org (Postfix) with ESMTPS id 7353C3858284; Thu, 22 Dec 2022 11:03:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7353C3858284 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4Nd6rD2VZfz9sX0; Thu, 22 Dec 2022 12:03:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1671707036; 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: in-reply-to:in-reply-to:references:references; bh=cHthhgKXxjTnq3GhekfOM6oDCp/vZXuo0WZ9AB203VA=; b=vJBLVbDjv/76NVRq/uefKB2XuQd/GNe5la1/VwHBZrGjMBXTApmmRnQ8+Q4rHiF33pqawn ssCQYK+FfH8GyC9xseNOwrI5EePUkIL5R5TyUX2iLdOHneOy65jdv5hHYE1LgU7L49PsB/ hhWBFwtsq19oZNob+U1CduOU801CRb6ebP1yLCVSUDHpiaxkRkdXZ8WHtzJq21A1kyiMA5 q2cc/jhmsj0KFHxb50zMEZA0EwihrnybNX5LyL10pNh3qqlWyq+HDOG9/OowrE8l//PW6Z vbb7jugTToHwZER0guujKznQoTKTjRkAdGaLLw/hU9k64+sswBAxDq/st9K8Gw== From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, jwakely@redhat.com, libstdc++@gcc.gnu.org, =?UTF-8?q?Arsen=20Arsenovi=C4=87?= Subject: [PATCH 3/3] contrib: Add dg-out-generator.pl Date: Thu, 22 Dec 2022 12:03:08 +0100 Message-Id: <20221222110306.3869396-3-arsen@aarsen.me> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4Nd6rD2VZfz9sX0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This script is a helper used to generate dg-output lines from an existing program output conveniently. It takes care of escaping Tcl and ARE stuff. contrib/ChangeLog: * dg-out-generator.pl: New file. --- I updated this file to include the proper copyright header, after dkm notified me that I got it wrong on IRC ;D contrib/dg-out-generator.pl | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 contrib/dg-out-generator.pl diff --git a/contrib/dg-out-generator.pl b/contrib/dg-out-generator.pl new file mode 100755 index 00000000000..1e9247165b2 --- /dev/null +++ b/contrib/dg-out-generator.pl @@ -0,0 +1,79 @@ +#!/usr/bin/env perl +# +# Copyright (C) 2022 Free Software Foundation, Inc. +# Contributed by Arsen Arsenović. +# +# This script is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. + +# This script reads program output on STDIN, and out of it produces a block of +# dg-output lines that can be yanked at the end of a file. It will escape +# special ARE and Tcl constructs automatically. +# +# Each argument passed on the standard input is treated as a string to be +# replaced by ``.*'' in the final result. This is intended to mask out build +# paths, filenames, etc. +# +# Usage example: + +# $ g++-13 -fcontracts -o test \ +# 'g++.dg/contracts/contracts-access1.C' && \ +# ./test |& dg-out-generator.pl 'g++.dg/contracts/contracts-access1.C' +# // { dg-output {contract violation in function Base::b at .*:11: pub > 0(\n|\r\n|\r)*} } +# // { dg-output {\[level:default, role:default, continuation mode:never\](\n|\r\n|\r)*} } +# // { dg-output {terminate called without an active exception(\n|\r\n|\r)*} } + +# You can now freely dump the above into your testcase. + +use strict; +use warnings; +use POSIX 'floor'; + +my $escapees = '(' . join ('|', map { quotemeta } @ARGV) . ')'; + +sub gboundary($) +{ + my $str = shift; + my $sz = 10.0; + for (;;) + { + my $bnd = join '', (map chr 64 + rand 27, 1 .. floor $sz); + return $bnd unless index ($str, $bnd) >= 0; + $sz += 0.1; + } +} + +while () + { + # Escape our escapees. + my $boundary; + if (@ARGV) { + # Checking this is necessary to avoid a spurious .* between all + # characters if no arguments are passed. + $boundary = gboundary $_; + s/$escapees/$boundary/g; + } + + # Quote stuff special in Tcl ARE. This step also effectively nulls any + # concern about escaping. As long as all curly braces are escaped, the + # string will, when passing through the braces rule of Tcl, be identical to + # the input. + s/([[\]*+?{}()\\])/\\$1/g; + + # Newlines should be more tolerant. + s/\n$/(\\n|\\r\\n|\\r)*/; + + # Then split out the boundary, replacing it with .*. + s/$boundary/.*/g if defined $boundary; + + # Then, let's print it in a dg-output block. If you'd prefer /* keep in + # mind that if your string contains */ it could terminate the comment + # early. Maybe add an extra s!\*/!*()/!g or something. + print "// { dg-output {$_} }\n"; + } + +# File Local Vars: +# indent-tabs-mode: nil +# End: -- 2.39.0