From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5E0DC3857C43 for ; Tue, 20 Dec 2022 15:57:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5E0DC3857C43 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671551869; 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=aQ1Pz9fJSdEnpIxiCKfC7QqphLIBdUs0kowtAHiEzY8=; b=AJ0UwidrIWZu71WsRkSBUq+n3x5RXlgg0MWZKvSAMfp+zlkHNsT9dOTwIoDV/2HllJXo6b yv6fAThFAHpIVKTcuZEU18HIxHUjOSOaMM1oqTSpKzv+VvAxTtz3oOCLiIjWkziWYpZ9Jc UZCGfDoKzBUPhh606Gq8m1CUemBBR2c= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-554-yWi1NtNYNMOcI6MLKiEw1g-1; Tue, 20 Dec 2022 10:57:46 -0500 X-MC-Unique: yWi1NtNYNMOcI6MLKiEw1g-1 Received: by mail-lf1-f71.google.com with SMTP id g15-20020a0565123b8f00b004b5b4d1f2e0so5171315lfv.0 for ; Tue, 20 Dec 2022 07:57:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aQ1Pz9fJSdEnpIxiCKfC7QqphLIBdUs0kowtAHiEzY8=; b=d5+Z+YrcOkBfXDH5r+IzVgCh8O7NXMNZgaobWVUlv9JKRWPB+Cv97+zK2UFPmodrHz ChTODqMYD7oFuCnzGeeeLKxorJFF7kypHfXcHL3AFdVLzqHlIvHBO+dxEp1PLhUOWwPY HzXo3BVcXeaZ5+xVG08/JSG36bwuTpt1MxTiIQ/JwJOZPrk/ku8L5NYwyXpxvAme3UI1 FlwuwmghIE0DRJ+TbRCketdFcLF2qEVr5OJUPj8UZ0V0IdBT07/a3/oaF6jI/iJVfq+d gTl+5YCYyqzLYRvl2SmLo1rMuzdnbWNwEZZcf7zlEx3txmJSTkHJDz6fQbmSF4G505e8 UQIA== X-Gm-Message-State: ANoB5pkpbvNcwf4Jbfej2Ez75eItvVIxxs8k7A7hyFY4tDXj5y+OSJ+T 7g28vv0VVmt74ZQYCnB2rQewP/EMeGJFgJuGUuyvxWw+WL2BpYl+BBK6sA6g8v6pDKKiMhARLpH G4u25kriuFBRR/1QZHYiB/diZvq1EFJeIbA== X-Received: by 2002:ac2:5fb0:0:b0:4b0:65b0:7f30 with SMTP id s16-20020ac25fb0000000b004b065b07f30mr27362206lfe.385.1671551865184; Tue, 20 Dec 2022 07:57:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf4BCYC33G1KCJFAK4c3WRJ84HN3V97DBP2Bgr2eaOb5aJ5IGRpj9hm+McIEuiAqn8V0zGcxAFGT1Bd34yPcn70= X-Received: by 2002:ac2:5fb0:0:b0:4b0:65b0:7f30 with SMTP id s16-20020ac25fb0000000b004b065b07f30mr27362200lfe.385.1671551864793; Tue, 20 Dec 2022 07:57:44 -0800 (PST) MIME-Version: 1.0 References: <86ilictvdt.fsf@aarsen.me> <20221220104916.3000540-1-arsen@aarsen.me> <20221220104916.3000540-3-arsen@aarsen.me> In-Reply-To: <20221220104916.3000540-3-arsen@aarsen.me> From: Jonathan Wakely Date: Tue, 20 Dec 2022 15:57:32 +0000 Message-ID: Subject: Re: [PATCH 3/3] contrib: Add dg-out-generator.pl To: =?UTF-8?Q?Arsen_Arsenovi=C4=87?= Cc: Jason Merrill , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.2 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_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 20 Dec 2022 at 10:49, Arsen Arsenovi=C4=87 wrote: > > 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. > --- > 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..663b00fa496 > --- /dev/null > +++ b/contrib/dg-out-generator.pl > @@ -0,0 +1,79 @@ > +#!/usr/bin/env perl > +# > +# Copyright (C) 2022 GCC Contributors. As discussed on IRC, this form of copyright notice is novel, and should probably be the usual FSF copyright notice instead, since you have an assignment in place. > +# Contributed by Arsen Arsenovi=C4=87. > +# > +# 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 bl= ock of > +# dg-output lines that can be yanked at the end of a file. It will esca= pe > +# special ARE and Tcl constructs automatically. > +# > +# Each argument passed on the standard input is treated as a string to b= e > +# 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 =3D '(' . join ('|', map { quotemeta } @ARGV) . ')'; > + > +sub gboundary($) > +{ > + my $str =3D shift; > + my $sz =3D 10.0; > + for (;;) > + { > + my $bnd =3D join '', (map chr 64 + rand 27, 1 .. floor $sz); > + return $bnd unless index ($str, $bnd) >=3D 0; > + $sz +=3D 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 =3D 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 ident= ical 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 /* kee= p in > + # mind that if your string contains */ it could terminate the commen= t > + # early. Maybe add an extra s!\*/!*()/!g or something. > + print "// { dg-output {$_} }\n"; > + } > + > +# File Local Vars: > +# indent-tabs-mode: nil > +# End: > -- > 2.39.0 >