public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC] [gdb/testsuite] Add gdb/contrib/testsuite-normalize.sh
@ 2023-03-24 11:46 Tom de Vries
  2023-03-24 13:52 ` Simon Marchi
  2023-03-24 14:16 ` Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Tom de Vries @ 2023-03-24 11:46 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-24 14:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24 11:46 [RFC] [gdb/testsuite] Add gdb/contrib/testsuite-normalize.sh Tom de Vries
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

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).