Share the "multi_line" helper among all Ada testcases

Message ID 54FEDB92.9060808@adacore.com
State New, archived
Headers

Commit Message

Pierre-Marie de Rodat March 10, 2015, 11:54 a.m. UTC
  Hello,

This patch is a tiny cleanup for the Ada testsuite: it put the 
"multi_line" helper (currently defined in 6 testcases) in a common 
place: ada.exp. It triggers no regression (tested on x86_64-linux).

Ok to push?
Thank you in advance,

     gdb/testsuite/ChangeLog:
     2015-03-10  Pierre-Marie de Rodat  <derodat@adacore.com>

         * gdb.ada/complete.exp: Remove "multi_line".
         * gdb.ada/info_exc.exp: Remove "multi_line".
         * gdb.ada/packed_tagged.exp: Remove "multi_line".
         * gdb.ada/ptype_field.exp: Remove "multi_line".
         * gdb.ada/sym_print_name.exp: Remove "multi_line".
         * gdb.ada/tagged.exp: Remove "multi_line".
         * lib/ada.exp: Add the "multi_line" helper.
  

Comments

Joel Brobecker March 17, 2015, 8:08 p.m. UTC | #1
> This patch is a tiny cleanup for the Ada testsuite: it put the
> "multi_line" helper (currently defined in 6 testcases) in a common
> place: ada.exp. It triggers no regression (tested on x86_64-linux).
> 
> Ok to push?
> Thank you in advance,
> 
>     gdb/testsuite/ChangeLog:
>     2015-03-10  Pierre-Marie de Rodat  <derodat@adacore.com>
> 
>         * gdb.ada/complete.exp: Remove "multi_line".
>         * gdb.ada/info_exc.exp: Remove "multi_line".
>         * gdb.ada/packed_tagged.exp: Remove "multi_line".
>         * gdb.ada/ptype_field.exp: Remove "multi_line".
>         * gdb.ada/sym_print_name.exp: Remove "multi_line".
>         * gdb.ada/tagged.exp: Remove "multi_line".
>         * lib/ada.exp: Add the "multi_line" helper.

At the time I introduced this function, I thought it should even
be in gdb.exp, but others did not agree with its usefulness, which
explains why I ended up duplicating it everywhere.

Let's do the following: Let's give people a week to comment on
this, and if there are no objection, let's put it in ada.exp.
If others agree that this should be in gdb.exp, then let's do that
instead, and then add some documentation in our "testcase cookbook"
wiki page about this routine.

Thanks, Pierre-Marie.
  
Pedro Alves March 18, 2015, 9:45 a.m. UTC | #2
On 03/17/2015 08:08 PM, Joel Brobecker wrote:

> At the time I introduced this function, I thought it should even
> be in gdb.exp, but others did not agree with its usefulness, which
> explains why I ended up duplicating it everywhere.

Do you have a pointer?  I'm curious to see the alternatives
proposed.  If there's something better, I'd argue for instead
converting the Ada tests to use it.

All I found was this though:

 https://sourceware.org/ml/gdb-patches/2008-01/msg00824.html

which didn't sound like an objection, only a pointer to existing
functions that may or not cover your use case.

Note gdb_expect_list does not work for this though, as that has an
implicit ".*" between elements of the expected list.

Meanwhile, we grew many tests that do [join [list ... "\r\n"]],
like this:

# start by listing all functions
gdb_test "record function-call-history /ci 1, +20" [join [list \
  "1\tmain\tinst 1,1" \
  "2\t  fun4\tinst 2,4" \
  "3\t    fun1\tinst 5,8" \
  "4\t  fun4\tinst 9,9" \
  "5\t    fun2\tinst 10,12" \
  "6\t      fun1\tinst 13,16" \
  "7\t    fun2\tinst 17,18" \
  "8\t  fun4\tinst 19,19" \
  "9\t    fun3\tinst 20,22" \
  "10\t      fun1\tinst 23,26" \
  "11\t    fun3\tinst 27,27" \
  "12\t      fun2\tinst 28,30" \
  "13\t        fun1\tinst 31,34" \
  "14\t      fun2\tinst 35,36" \
  "15\t    fun3\tinst 37,38" \
  "16\t  fun4\tinst 39,40" \
  ] "\r\n"]

Your multi_line looks like almost the same, except that it's
a tiny bit more lax:

proc multi_line { args } {
    return [join $args "\[\r\n\]*"]
}

That will accept _no_ newline between list elements, and
multiple newlines too.  How about making multi_line join
with strict "\r\n" too?  Then if you need to match one
empty line, you can do:

         [multi_line "line1" \
	             ""
                     "line3"]

and if you need multiple, you can always do:

         [multi_line "line1" \
	             "\[\r\n\]*"
                     "lineNN"]

> Let's do the following: Let's give people a week to comment on
> this, and if there are no objection, let's put it in ada.exp.
> If others agree that this should be in gdb.exp, then let's do that
> instead, and then add some documentation in our "testcase cookbook"
> wiki page about this routine.

Thanks,
Pedro Alves
  
Joel Brobecker March 18, 2015, 2:12 p.m. UTC | #3
> Meanwhile, we grew many tests that do [join [list ... "\r\n"]],
> like this:
> 
> # start by listing all functions
> gdb_test "record function-call-history /ci 1, +20" [join [list \
>   "1\tmain\tinst 1,1" \
>   "2\t  fun4\tinst 2,4" \
>   "3\t    fun1\tinst 5,8" \
>   "4\t  fun4\tinst 9,9" \
>   "5\t    fun2\tinst 10,12" \
>   "6\t      fun1\tinst 13,16" \
>   "7\t    fun2\tinst 17,18" \
>   "8\t  fun4\tinst 19,19" \
>   "9\t    fun3\tinst 20,22" \
>   "10\t      fun1\tinst 23,26" \
>   "11\t    fun3\tinst 27,27" \
>   "12\t      fun2\tinst 28,30" \
>   "13\t        fun1\tinst 31,34" \
>   "14\t      fun2\tinst 35,36" \
>   "15\t    fun3\tinst 37,38" \
>   "16\t  fun4\tinst 39,40" \
>   ] "\r\n"]
> 
> Your multi_line looks like almost the same, except that it's
> a tiny bit more lax:
> 
> proc multi_line { args } {
>     return [join $args "\[\r\n\]*"]
> }
> 
> That will accept _no_ newline between list elements, and
> multiple newlines too.  How about making multi_line join
> with strict "\r\n" too?  Then if you need to match one
> empty line, you can do:
> 
>          [multi_line "line1" \
> 	             ""
>                      "line3"]
> 
> and if you need multiple, you can always do:
> 
>          [multi_line "line1" \
> 	             "\[\r\n\]*"
>                      "lineNN"]

Very good suggestion, I like it! Pierre-Marie?
  

Patch

From 855c84ea47c0b4f873af31f7cf10b6eefff3f6c2 Mon Sep 17 00:00:00 2001
From: Pierre-Marie de Rodat <derodat@adacore.com>
Date: Tue, 10 Mar 2015 09:51:27 +0100
Subject: [PATCH] Share the "multi_line" helper among all Ada testcases

gdb/testsuite/ChangeLog:
2015-03-10  Pierre-Marie de Rodat  <derodat@adacore.com>

	* gdb.ada/complete.exp: Remove "multi_line".
	* gdb.ada/info_exc.exp: Remove "multi_line".
	* gdb.ada/packed_tagged.exp: Remove "multi_line".
	* gdb.ada/ptype_field.exp: Remove "multi_line".
	* gdb.ada/sym_print_name.exp: Remove "multi_line".
	* gdb.ada/tagged.exp: Remove "multi_line".
	* lib/ada.exp: Add the "multi_line" helper.
---
 gdb/testsuite/gdb.ada/complete.exp       | 10 ----------
 gdb/testsuite/gdb.ada/info_exc.exp       | 11 -----------
 gdb/testsuite/gdb.ada/packed_tagged.exp  | 11 -----------
 gdb/testsuite/gdb.ada/ptype_field.exp    | 11 -----------
 gdb/testsuite/gdb.ada/sym_print_name.exp | 11 -----------
 gdb/testsuite/gdb.ada/tagged.exp         | 11 -----------
 gdb/testsuite/lib/ada.exp                | 11 +++++++++++
 7 files changed, 11 insertions(+), 65 deletions(-)

diff --git a/gdb/testsuite/gdb.ada/complete.exp b/gdb/testsuite/gdb.ada/complete.exp
index 1dc9cba..9919bdf 100644
--- a/gdb/testsuite/gdb.ada/complete.exp
+++ b/gdb/testsuite/gdb.ada/complete.exp
@@ -44,16 +44,6 @@  proc test_gdb_no_completion { expr } {
     gdb_test_no_output "complete p $expr"
 }
 
-# A convenience function that joins all the arguments together,
-# with a regexp that matches zero-or-more end of lines in between
-# each argument.  This function is ideal to write the expected output
-# of a GDB command that generates more than a couple of lines, as
-# this allows us to write each line as a separate string, which is
-# easier to read by a human being.
-
-proc multi_line { args } {
-    return [join $args "\[\r\n\]*"]
-}
 # Try a global variable, only one match should be found:
 
 test_gdb_complete "my_glob" \
diff --git a/gdb/testsuite/gdb.ada/info_exc.exp b/gdb/testsuite/gdb.ada/info_exc.exp
index 3f21218..add83c5 100644
--- a/gdb/testsuite/gdb.ada/info_exc.exp
+++ b/gdb/testsuite/gdb.ada/info_exc.exp
@@ -21,17 +21,6 @@  if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" }
   return -1
 }
 
-# A convenience function that joins all the arguments together,
-# with a regexp that matches zero-or-more end of lines in between
-# each argument.  This function is ideal to write the expected output
-# of a GDB command that generates more than a couple of lines, as
-# this allows us to write each line as a separate string, which is
-# easier to read by a human being.
-
-proc multi_line { args } {
-    return [join $args "\[\r\n\]*"]
-}
-
 clean_restart ${testfile}
 
 if ![runto_main] then {
diff --git a/gdb/testsuite/gdb.ada/packed_tagged.exp b/gdb/testsuite/gdb.ada/packed_tagged.exp
index 02e02ea..4187702 100644
--- a/gdb/testsuite/gdb.ada/packed_tagged.exp
+++ b/gdb/testsuite/gdb.ada/packed_tagged.exp
@@ -21,17 +21,6 @@  if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" }
   return -1
 }
 
-# A convenience function that joins all the arguments together,
-# with a regexp that matches zero-or-more end of lines in between
-# each argument.  This function is ideal to write the expected output
-# of a GDB command that generates more than a couple of lines, as
-# this allows us to write each line as a separate string, which is
-# easier to read by a human being.
-
-proc multi_line { args } {
-    return [join $args "\[\r\n\]*"]
-}
-
 clean_restart ${testfile}
 
 set bp_location [gdb_get_line_number "STOP" ${testdir}/comp_bug.adb]
diff --git a/gdb/testsuite/gdb.ada/ptype_field.exp b/gdb/testsuite/gdb.ada/ptype_field.exp
index caf99ba..b4eb8f6 100644
--- a/gdb/testsuite/gdb.ada/ptype_field.exp
+++ b/gdb/testsuite/gdb.ada/ptype_field.exp
@@ -21,17 +21,6 @@  if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional
   return -1
 }
 
-# A convenience function that joins all the arguments together,
-# with a regexp that matches zero-or-more end of lines in between
-# each argument.  This function is ideal to write the expected output
-# of a GDB command that generates more than a couple of lines, as
-# this allows us to write each line as a separate string, which is
-# easier to read by a human being.
-
-proc multi_line { args } {
-    return [join $args "\[\r\n\]*"]
-}
-
 clean_restart ${testfile}
 
 set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb]
diff --git a/gdb/testsuite/gdb.ada/sym_print_name.exp b/gdb/testsuite/gdb.ada/sym_print_name.exp
index c78793e..f942fdf 100644
--- a/gdb/testsuite/gdb.ada/sym_print_name.exp
+++ b/gdb/testsuite/gdb.ada/sym_print_name.exp
@@ -21,17 +21,6 @@  if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" }
   return -1
 }
 
-# A convenience function that joins all the arguments together,
-# with a regexp that matches zero-or-more end of lines in between
-# each argument.  This function is ideal to write the expected output
-# of a GDB command that generates more than a couple of lines, as
-# this allows us to write each line as a separate string, which is
-# easier to read by a human being.
-
-proc multi_line { args } {
-    return [join $args "\[\r\n\]*"]
-}
-
 clean_restart ${testfile}
 
 set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb]
diff --git a/gdb/testsuite/gdb.ada/tagged.exp b/gdb/testsuite/gdb.ada/tagged.exp
index 9f40a96..f428148 100644
--- a/gdb/testsuite/gdb.ada/tagged.exp
+++ b/gdb/testsuite/gdb.ada/tagged.exp
@@ -21,17 +21,6 @@  if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" }
   return -1
 }
 
-# A convenience function that joins all the arguments together,
-# with a regexp that matches zero-or-more end of lines in between
-# each argument.  This function is ideal to write the expected output
-# of a GDB command that generates more than a couple of lines, as
-# this allows us to write each line as a separate string, which is
-# easier to read by a human being.
-
-proc multi_line { args } {
-    return [join $args "\[\r\n\]*"]
-}
-
 clean_restart ${testfile}
 
 set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp
index 6a1e192..903ef45 100644
--- a/gdb/testsuite/lib/ada.exp
+++ b/gdb/testsuite/lib/ada.exp
@@ -60,3 +60,14 @@  proc standard_ada_testfile {base_file {dir ""}} {
 
     file mkdir [standard_output_file $testdir]
 }
+
+# A convenience function that joins all the arguments together,
+# with a regexp that matches zero-or-more end of lines in between
+# each argument.  This function is ideal to write the expected output
+# of a GDB command that generates more than a couple of lines, as
+# this allows us to write each line as a separate string, which is
+# easier to read by a human being.
+
+proc multi_line { args } {
+    return [join $args "\[\r\n\]*"]
+}
-- 
2.3.1