From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [RFC] [gdb/testsuite] Add gdb/contrib/testsuite-normalize.sh
Date: Fri, 24 Mar 2023 12:46:51 +0100 [thread overview]
Message-ID: <20230324114651.2987-1-tdevries@suse.de> (raw)
There are a number of different ways to express the same thing in TCL.
For instance, $foo and ${foo}:
...
% set foo "foo bar"
foo bar
% puts ${foo}
foo bar
% puts $foo
foo bar
...
The braces make things (IMO) harder to read, but are necessary in some cases
though, for instance ${foo-bar} and $foo-bar are not the same thing:
...
% set foo "foo var"
foo var
% set foo-bar "foo-bar var"
foo-bar var
% puts ${foo-bar}
foo-bar var
% puts $foo-bar
foo var-bar
...
Furthermore, there's the tendency to use "$foo" (as is often necessary in shell
scripting), while in TCL using $foo is sufficient:
...
% set foo "bar bar"
bar bar
% puts "$foo"
bar bar
% puts $foo
bar bar
...
Add a script gdb/contrib/testsuite-normalize.sh, which rewrites test-cases
in a normal form, using $foo instead of ${foo}, and $foo instead of "$foo",
where possible.
This patch doesn't contain the effects of running it, because that would make
the patch too large:
...
$ git diff | wc
63705 273146 2457187
...
If this approach is acceptable, I'll commit the effects as a seperate patch.
Tested on x86_64-linux.
---
gdb/contrib/testsuite-normalize.sh | 44 ++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100755 gdb/contrib/testsuite-normalize.sh
diff --git a/gdb/contrib/testsuite-normalize.sh b/gdb/contrib/testsuite-normalize.sh
new file mode 100755
index 00000000000..0cbde3526ce
--- /dev/null
+++ b/gdb/contrib/testsuite-normalize.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+handle_file ()
+{
+ f="$1"
+
+ # Rewrite '${foo}' -> '$foo''.
+ # Don't rewrite '\${foo}' -> '\$foo'.
+ # Don't rewrite '${foo}(bar)' -> '$foo(bar).
+ # Don't rewrite '${foo}bar' -> '$foobar'.
+ # Don't rewrite '${foo}::bar' -> '$foo::bar'.
+ # Two variants, first one matching '${foo}<eol>'.
+ sed -i 's/\([^\\]\)${\([a-zA-Z0-9_]*\)}$/\1$\2/g' "$f"
+ sed -i 's/\([^\\]\)${\([a-zA-Z0-9_]*\)}\([^a-zA-Z0-9_(:]\)/\1$\2\3/g' "$f"
+
+ # Rewrite ' "$foo" ' -> ' $foo '.
+ # Rewrite ' "$foo"<eol>' -> ' $foo<eol>'.
+ sed -i 's/\([ \t][ \t]*\)"\$\([a-zA-Z0-9_]*\)"$/\1$\2/g' "$f"
+ sed -i 's/\([ \t][ \t]*\)"\$\([a-zA-Z0-9_]*\)"\([ \t][ \t]*\)/\1$\2\3/g' "$f"
+}
+
+main ()
+{
+ if [ $# -eq 0 ]; then
+ mapfile files < <(find gdb/testsuite -type f -name "*.exp*")
+ else
+ files=("$@")
+ fi
+
+ for f in "${files[@]}"; do
+ f=$(echo $f)
+ sum=$(md5sum "$f")
+ while true; do
+ handle_file "$f"
+ prev=$sum
+ sum=$(md5sum "$f")
+ if [ "$sum" == "$prev" ]; then
+ break
+ fi
+ done
+ done
+}
+
+main "$@"
base-commit: ca357a9359f5d09058d27fc1f84f1d53c2717ba1
--
2.35.3
next reply other threads:[~2023-03-24 11:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-24 11:46 Tom de Vries [this message]
2023-03-24 13:52 ` Simon Marchi
2023-03-24 14:39 ` Tom de Vries
2023-03-24 14:16 ` Tom Tromey
2023-03-24 14:42 ` Tom de Vries
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=20230324114651.2987-1-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.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).