[v2] testsuite: prune DOS drive letter in test outputs

Message ID 20230222151639.588269-1-chigot@adacore.com
State Unresolved
Headers
Series [v2] testsuite: prune DOS drive letter in test outputs |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Clément Chigot Feb. 22, 2023, 3:16 p.m. UTC
  On DOS systems, absolute paths start with the drive letter. This can
trigger failures in the regexp from dump tests, especially for those
checking for warnings or errors. They are usually skipping everything
before the first ":" as it has to be the file path.
  | [^:]*: warning: ...

In order to avoid modifying many regexps to allow such drive letters,
prune them from all the outputs if they are found at the beginning of
a line.

binutils/ChangeLog:

	* testsuite/lib/binutils-common.exp (prune_dump_output): New
	(run_dump_test): Use it.

ld/ChangeLog:

	* testsuite/ld-elf/noinit-sections-2.l: Remove DOS drive letter
	handler.
---
 binutils/testsuite/lib/binutils-common.exp | 18 +++++++++++++++++-
 ld/testsuite/ld-elf/noinit-sections-2.l    |  4 ++--
 2 files changed, 19 insertions(+), 3 deletions(-)
  

Comments

Andreas Schwab Feb. 22, 2023, 3:42 p.m. UTC | #1
On Feb 22 2023, Clément Chigot via Binutils wrote:

> +	regsub -all "(^|\n)\[\[:alpha:\]\]:(/|\)" $output "\\1\\2" output

If you want to match a backslash, you need to double it, and double it
again to please the double quote syntax.  If you fear the leaning
toothpick syndrom, change the quoting of the regexp by using {} instead
of "".  Note that Tcl regexps support \n as an escape sequence for
newline.
  
Clément Chigot Feb. 22, 2023, 4:13 p.m. UTC | #2
On Wed, Feb 22, 2023 at 4:42 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Feb 22 2023, Clément Chigot via Binutils wrote:
>
> > +     regsub -all "(^|\n)\[\[:alpha:\]\]:(/|\)" $output "\\1\\2" output
>
> If you want to match a backslash, you need to double it, and double it
> again to please the double quote syntax.  If you fear the leaning
> toothpick syndrom, change the quoting of the regexp by using {} instead
> of "".  Note that Tcl regexps support \n as an escape sequence for
> newline.

It seems that both are working.
  | $ cat ~/tmp/test.tcl
  | set output "C:\\home\\c"
  | regsub -all "(^|\n)\[\[:upper:\]\]:(/|\)" $output "\\1\\2" output
  | puts $output
  | regsub -all "(^|\n)\[\[:upper:\]\]:(/|\\\\)" $output "\\1\\2" output
  | puts $output

  | $ tclsh8.6 ~/tmp/test.tcl
  | \home\c
  | \home\c

Can it because of my tcl version (8.6.10) ?

Thanks,
Clément
  
Andreas Schwab Feb. 22, 2023, 4:37 p.m. UTC | #3
On Feb 22 2023, Clément Chigot wrote:

> It seems that both are working.
>   | $ cat ~/tmp/test.tcl
>   | set output "C:\\home\\c"
>   | regsub -all "(^|\n)\[\[:upper:\]\]:(/|\)" $output "\\1\\2" output
>   | puts $output
>   | regsub -all "(^|\n)\[\[:upper:\]\]:(/|\\\\)" $output "\\1\\2" output
>   | puts $output
>
>   | $ tclsh8.6 ~/tmp/test.tcl
>   | \home\c
>   | \home\c

The first regexp is equivalent to {(^|\n)[[:upper:]]:(/|)}, and the
second group matches the empty string.
  
Clément Chigot Feb. 23, 2023, 8:01 a.m. UTC | #4
On Wed, Feb 22, 2023 at 5:37 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Feb 22 2023, Clément Chigot wrote:
>
> > It seems that both are working.
> >   | $ cat ~/tmp/test.tcl
> >   | set output "C:\\home\\c"
> >   | regsub -all "(^|\n)\[\[:upper:\]\]:(/|\)" $output "\\1\\2" output
> >   | puts $output
> >   | regsub -all "(^|\n)\[\[:upper:\]\]:(/|\\\\)" $output "\\1\\2" output
> >   | puts $output
> >
> >   | $ tclsh8.6 ~/tmp/test.tcl
> >   | \home\c
> >   | \home\c
>
> The first regexp is equivalent to {(^|\n)[[:upper:]]:(/|)}, and the
> second group matches the empty string.

Yeah indeed, you're right !
So just to be sure before submitted a new patch version,
"(^|\n)\[\[:alpha:\]\]:(/|\\\\)" is correct ? (I've changed upper by
alpha as it's supposed to be).

Thanks a lot for your help
Clément
  
Andreas Schwab Feb. 23, 2023, 9:07 a.m. UTC | #5
On Feb 23 2023, Clément Chigot wrote:

> "(^|\n)\[\[:alpha:\]\]:(/|\\\\)" is correct ?

You can write it as {(^|\n)[[:alpha:]]:(/|\\)} to be easier to read.
  

Patch

diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
index ab752417295..a52ef7f3b90 100644
--- a/binutils/testsuite/lib/binutils-common.exp
+++ b/binutils/testsuite/lib/binutils-common.exp
@@ -687,6 +687,22 @@  if ![string length [info proc prune_warnings]] {
     }
 }
 
+# prune_dump_output OUTPUT
+#
+# Clean up the output from system specific or unwanted characters.
+# This allows to simplify the regexp inside dump tests.
+proc prune_dump_output { output } {
+    if [ishost "*-*-mingw*"] {
+	# Prune DOS drive letter from an absolute path if it appears
+	# at the beginning of a line.
+	regsub -all "(^|\n)\[\[:alpha:\]\]:(/|\)" $output "\\1\\2" output
+    }
+
+    # Prune last end of line.
+    regsub "\n$" $output "" output
+    return $output
+}
+
 # run_dump_test FILE (optional:) EXTRA_OPTIONS
 #
 # Assemble a .s file, then run some utility on it and check the output.
@@ -1450,7 +1466,7 @@  proc run_dump_test { name {extra_options {}} } {
 	    }
 	}
 
-	regsub "\n$" $comp_output "" comp_output
+	set comp_output [prune_dump_output $comp_output]
 	if { $cmdret != 0 || $comp_output != "" || $want_out(source) != "" } {
 	    set exitstat "succeeded"
 	    if { $cmdret != 0 } { set exitstat "failed" }
diff --git a/ld/testsuite/ld-elf/noinit-sections-2.l b/ld/testsuite/ld-elf/noinit-sections-2.l
index 8ed2716c549..0784c9e3e12 100644
--- a/ld/testsuite/ld-elf/noinit-sections-2.l
+++ b/ld/testsuite/ld-elf/noinit-sections-2.l
@@ -1,5 +1,5 @@ 
 #...
-(|.:)[^:]*: warning: orphan section `.noinit.var_noinit' from \S+ being placed in section `.noinit.var_noinit'
+[^:]*: warning: orphan section `.noinit.var_noinit' from \S+ being placed in section `.noinit.var_noinit'
 #...
-(|.:)[^:]*: warning: orphan section `.gnu.linkonce.n.var_noinit2' from \S+ being placed in section `.gnu.linkonce.n.var_noinit2'
+[^:]*: warning: orphan section `.gnu.linkonce.n.var_noinit2' from \S+ being placed in section `.gnu.linkonce.n.var_noinit2'
 #pass