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.129.124]) by sourceware.org (Postfix) with ESMTPS id 523E13857C5A for ; Tue, 20 Dec 2022 15:57:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 523E13857C5A 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=1671551867; 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=Asb2IQDIct2ZcWEN5c6Q1o0FUDTNuloRZa3OQQ6nm4xl4trsJxMizpSMh+H1A+eDO05FRS ULUayEtrUmevM9bPS/Z4Q/ijGnhG+B87EFpKAJ6nUpBG+EKSsu+kxGLYid5kPJgPeXZRIH /Hj9ECjakWkeo4ukBRZgyEeRXZDph7g= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-81-qK7g6iOkOfadaxKVd5eKzA-1; Tue, 20 Dec 2022 10:57:46 -0500 X-MC-Unique: qK7g6iOkOfadaxKVd5eKzA-1 Received: by mail-lj1-f200.google.com with SMTP id x32-20020a2ea9a0000000b0027b52e5e56cso3324446ljq.10 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=ispYzJ3dg9IDPxbF/BEdl2tacGZZP3IAg4J1FaYCDHobUltuZb3a2FvzZ4lJXhW1Pg gluSgu8e+NKNB3Rqb1Q5uSjy+Ym+EZiI9OyY1ZcYkyESN4f3OltxX1g9KVNWE8zjIDA9 aX+bGNVwkCq3BIlRoAurLVwpcMMW4mmOUmZyE8a61LHL7jpAeohpu3QEt031fZzpr5p/ jMk9R5D2IufiKdSBP15lzuXqAbj8SVyHVqx73JgXeDRG/1+NoW3HGnL+R/qAzNrZLaTt Bi0FXthfG2tD/de4dhs4JnxryQ1A0353UpzvwZ/TkUwG0zyCL3sjFaaLrXerJQGhQ5q3 c8Hw== X-Gm-Message-State: ANoB5plB0ROQBQNwqwllXobZYOFqOzFY7F5pD6oTns6QMc6xOk3q8ADE wUADNF4nySVg8cEYiY5K3O1viR7R+fgwfxeGsJ82Fhsvs57IrjP9wuspTtxhbTjkMfzbcaH9JG2 x8QZV6zqN7hBzHA6ox78vWhuJW8j5q3Y= X-Received: by 2002:ac2:5fb0:0:b0:4b0:65b0:7f30 with SMTP id s16-20020ac25fb0000000b004b065b07f30mr27362205lfe.385.1671551865067; 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.5 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=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: 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 >