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 E0F5F385802F for ; Thu, 22 Dec 2022 21:43:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E0F5F385802F 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=1671745413; 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=SnWlcyAoa4nwhDvFDrsB/4Mx15np1Ph/dZGe00SaZaA=; b=IZ6TinwlOR2RPWpIxrVFemVfaDCVLQr9aPveDR8Sz9+GQsxBethBQMvKyday1f+2HEtvFN 0n57SnqOdnJuGCAPUrGRIwiJWJ6dMbIY5+KApOIL7KSQRPYimSYGLu4FanGEQtRzb7pz35 w1jNPwpbCM2oZBpZMQp1WjGjPGeBPaw= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-653-3K9I8FnNP2y1X0j4CD4PKw-1; Thu, 22 Dec 2022 16:43:27 -0500 X-MC-Unique: 3K9I8FnNP2y1X0j4CD4PKw-1 Received: by mail-qt1-f198.google.com with SMTP id l11-20020ac8148b000000b003a81fbc3b3bso1242885qtj.12 for ; Thu, 22 Dec 2022 13:43:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SnWlcyAoa4nwhDvFDrsB/4Mx15np1Ph/dZGe00SaZaA=; b=ffp2FMZIfSwCI+8KvLIRjuVwnCcu/yoKG2rV8xO3k36gy/Wgl84nXkXG+1sNfn2Vh3 tNdx1MOoRlzsZdTF8agzC8HJsQjsKNyDSgcczw55oFHiNt12JHZl0Nv5R4RF/s/JMk9N Y45H8aieqUKmiGfpDVBqdy1aiZlb5nXXhKBU01xlprx8ReytbZHy8d4eZvv1JVvNouP/ QOIyd+EVULls338n0LUAOLbDCpbfdC1ZKVklDBCKIGdHqKYe65XdF9WqU+/Yv7PCdRwl 2wOSNCXENJMI7iuBsILm/VqXZgmqyYTW5ZIbcLkg8BxLhE8mLTnZF45vYLtl1s/ku2wU NaAA== X-Gm-Message-State: AFqh2kpEI1QkDPy2XHgi5JatUO+rts5BZC5+WSBeJ32S4kjZJlJy6nMs RfRhWH3Q8kEcSmtwJIRd4M+HQCPgR86Fb/XdUy8pExMbjDrfumi3Y8qY8rPUTXUNT/y7Kl5YF09 MkUytIwuqFLyWfNM= X-Received: by 2002:a05:6214:3c8c:b0:4c6:ff2d:29b1 with SMTP id ok12-20020a0562143c8c00b004c6ff2d29b1mr11108328qvb.1.1671745406716; Thu, 22 Dec 2022 13:43:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXvNZl/85wfEF4dTsgZCSgkxNgf6W9syZRS0M1WIrYNNoz7S4srdnRXMt8I0Penh+K0JbO45rA== X-Received: by 2002:a05:6214:3c8c:b0:4c6:ff2d:29b1 with SMTP id ok12-20020a0562143c8c00b004c6ff2d29b1mr11108306qvb.1.1671745406372; Thu, 22 Dec 2022 13:43:26 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id m13-20020a05620a290d00b007023fc46b64sm1025978qkp.113.2022.12.22.13.43.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Dec 2022 13:43:25 -0800 (PST) Message-ID: Date: Thu, 22 Dec 2022 16:43:24 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH 3/3] contrib: Add dg-out-generator.pl To: =?UTF-8?Q?Arsen_Arsenovi=c4=87?= Cc: gcc-patches@gcc.gnu.org, jwakely@redhat.com, libstdc++@gcc.gnu.org References: <20221222110306.3869396-3-arsen@aarsen.me> From: Jason Merrill In-Reply-To: <20221222110306.3869396-3-arsen@aarsen.me> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 12/22/22 06:03, Arsen Arsenović 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. > --- > 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)*/; Isn't specifically handling \\r\\n redundant with the * operator? > + # 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: