From: Jason Merrill <jason@redhat.com>
To: "Arsen Arsenović" <arsen@aarsen.me>, gcc-patches@gcc.gnu.org
Cc: jwakely@redhat.com, libstdc++@gcc.gnu.org
Subject: Re: [PATCH 4/4] contrib: Add dg-out-generator.pl
Date: Thu, 15 Dec 2022 11:30:53 -0500 [thread overview]
Message-ID: <3e56cf50-344b-fbb1-fb12-4f44330cf560@redhat.com> (raw)
In-Reply-To: <20221210094303.2180127-5-arsen@aarsen.me>
On 12/10/22 04:43, 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.
> ---
> 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 (<STDIN>)
> + {
> + # 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";
I wonder if you want to wrap the pattern in {} instead of "" so you
don't need the "special stuff in TCL itself" quoting?
Jason
next prev parent reply other threads:[~2022-12-15 16:30 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-10 9:42 [PATCH 0/4] c++: Small tweaks to contracts Arsen Arsenović
2022-12-10 9:43 ` [PATCH 1/4] contracts: Lowercase {MAYBE,NEVER}_CONTINUE Arsen Arsenović
2022-12-10 11:15 ` Jonathan Wakely
2022-12-15 16:25 ` Jason Merrill
2022-12-15 17:39 ` Arsen Arsenović
2022-12-20 17:16 ` Jason Merrill
2022-12-10 9:43 ` [PATCH 2/4] libstdc++: Improve output of default contract violation handler [PR107792] Arsen Arsenović
2022-12-15 16:28 ` Jason Merrill
2022-12-15 17:43 ` Arsen Arsenović
2022-12-20 10:49 ` [PATCH 1/3] " Arsen Arsenović
2022-12-20 10:49 ` [PATCH 2/3] contracts: Update testsuite against new default viol. handler format Arsen Arsenović
2022-12-20 10:49 ` [PATCH 3/3] contrib: Add dg-out-generator.pl Arsen Arsenović
2022-12-20 15:57 ` Jonathan Wakely
2022-12-20 17:23 ` [PATCH 1/3] libstdc++: Improve output of default contract violation handler [PR107792] Jason Merrill
2022-12-22 11:03 ` Arsen Arsenović
2022-12-22 21:40 ` Jason Merrill
2022-12-22 22:02 ` Jonathan Wakely
2022-12-22 11:03 ` [PATCH 2/3] contracts: Update testsuite against new default viol. handler format Arsen Arsenović
2022-12-22 11:03 ` [PATCH 3/3] contrib: Add dg-out-generator.pl Arsen Arsenović
2022-12-22 21:43 ` Jason Merrill
2022-12-22 21:56 ` Arsen Arsenović
2022-12-22 22:21 ` Jason Merrill
2022-12-22 22:56 ` Arsen Arsenović
2022-12-10 9:43 ` [PATCH 3/4] contracts: Update testsuite against new default viol. handler format Arsen Arsenović
2022-12-10 9:43 ` [PATCH 4/4] contrib: Add dg-out-generator.pl Arsen Arsenović
2022-12-15 16:30 ` Jason Merrill [this message]
2022-12-15 17:30 ` Arsen Arsenović
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3e56cf50-344b-fbb1-fb12-4f44330cf560@redhat.com \
--to=jason@redhat.com \
--cc=arsen@aarsen.me \
--cc=gcc-patches@gcc.gnu.org \
--cc=jwakely@redhat.com \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).