From patchwork Sat Dec 10 09:43:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Arsen_Arsenovi=C4=87?= X-Patchwork-Id: 32001 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1224983wrr; Sat, 10 Dec 2022 01:54:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf5EFs0M1ieAO3cV2wyLpXUjvKyY9J9llCooPYoQ9X/KKnVEyFV73xw/0uiyajPaWRk1Rz7W X-Received: by 2002:aa7:cd6f:0:b0:46c:3f90:f5d9 with SMTP id ca15-20020aa7cd6f000000b0046c3f90f5d9mr8543131edb.5.1670666039966; Sat, 10 Dec 2022 01:53:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670666039; cv=none; d=google.com; s=arc-20160816; b=sjX6kQb+mEe8ipgprSf3AQEgN18TSZUo0XWdemsJ1kH4IhNayBcWgMsK+MaqecVXVA 3s3GmXIt+jYmqQHFXjCzQ8ao+WDdeHaVJVqIPYkoI/VZGK9SzJziJ7mJrBO0TreTJqlt VZZoYRr/PKN8Onv9XnNULmwsodocdEJG5sxF+8IV03J73a43sCOcrwYKRd+MIg/t2If8 OJUiC7yrsVUOPQAr2EPgFcTPtHGDqIk/M3hl0lfORk0sVNBqD389yKMokUmhnzrxcIwz XQzfZj/M1EtnMohfDxRwmqIV3332e0tEf6zFmsi7XUa3yrnrEMK9DCWtcbc5lpPq2sp7 bqyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=+Tc1wBHMn1A6XVR/7/Wn20K6S+8saDrN7a8GTIrpunk=; b=i6RKktTdZKC77H6KvVAx0+thD5/Z/omp/G4ZbJsDcuWPe/Qnn9d6QqZD9fSqfb+xoc nEokXM+hYVc17BTd52LNK39aHzez52hvZVfgYgObp75bk4RQkj/gMAgBMNw17Cv3w6lu xk20thtWRrl+mqDScQGmcvdsFxLTDHtsjT0jwntLZN4vqL4azUpD4gb1cN6y4BX8LFqt K0zIj1YuOW7HkqB1BMyko7sTcHNuk7oqJtSTaSVnfmC8s/XWat2dz7/+twyzI2IWRcto m6ry/htEBIyBureKFd6O3PEsf21ihYfyvvHTfvYhbUAnIjqTJhhlusdyITvt/g96SNq+ 2RUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cY6v8yna; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b61-20020a509f43000000b0046b55b17f1fsi3133490edf.567.2022.12.10.01.53.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Dec 2022 01:53:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cY6v8yna; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D7CF3834C06 for ; Sat, 10 Dec 2022 09:52:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D7CF3834C06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670665924; bh=+Tc1wBHMn1A6XVR/7/Wn20K6S+8saDrN7a8GTIrpunk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=cY6v8ynaFqGn7eCBzYQvTZP1yx6h0cHNW+VfSsGzvz0Xva48iTTfmsHt3ZvEGwWdA CIyMWwGLA0KLhah/lHNplfmbuikPMuQoAPpXv+hDinZGoNKhJwbF6atlbtsp/PXIZo GWpmfE2tUrUqLE/Wd7Ow6dMhTX4wD2VOMMJ1GRzk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by sourceware.org (Postfix) with ESMTPS id EE3DA383D8C8; Sat, 10 Dec 2022 09:49:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EE3DA383D8C8 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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-103.mailbox.org (Postfix) with ESMTPS id 4NTjln0dxwz9sTC; Sat, 10 Dec 2022 10:49:25 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, jwakely@redhat.com, libstdc++@gcc.gnu.org, =?utf-8?q?A?= =?utf-8?q?rsen_Arsenovi=C4=87?= Subject: [PATCH 4/4] contrib: Add dg-out-generator.pl Date: Sat, 10 Dec 2022 10:43:03 +0100 Message-Id: <20221210094303.2180127-5-arsen@aarsen.me> In-Reply-To: <20221210094303.2180127-1-arsen@aarsen.me> References: <20221210094303.2180127-1-arsen@aarsen.me> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4NTjln0dxwz9sTC X-Spam-Status: No, score=-11.2 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Arsen_Arsenovi=C4=87_via_Gcc-patches?= From: =?utf-8?q?Arsen_Arsenovi=C4=87?= Reply-To: =?utf-8?q?Arsen_Arsenovi=C4=87?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751820313713895086?= X-GMAIL-MSGID: =?utf-8?q?1751820313713895086?= 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 | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 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..38aed2aa38d --- /dev/null +++ b/contrib/dg-out-generator.pl @@ -0,0 +1,67 @@ +#!/usr/bin/env perl +# +# Copyright (C) 2022 GCC Contributors. +# 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 = gboundary $_; + s/$escapees/$boundary/; + + # Quote stuff special in Tcl ARE. + s/([[\]*+?{}()\\])/\\$1/g; + + # Then, special stuff in TCL itself. + s/([\][\\])/\\$1/g; + + # Newlines should be more tolerant. + s/\n$/(\\n|\\r\\n|\\r)*/; + + # Then split out the boundary, replacing it with .*. + s/$boundary/.*/; + + # Then, let's print it in a dg-output block. + print "// { dg-output \"$_\" }\n"; + }