Add "style" proc to the test suite
authorTom Tromey <tromey@adacore.com>
Tue, 14 May 2019 14:04:22 +0000 (08:04 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 22 May 2019 17:59:52 +0000 (13:59 -0400)
This adds a "style" helper proc to the test suite, and updates
existing style tests to use it.  Thanks to Sergio for the idea.

Tested on x86-64 Fedora 29.

gdb/testsuite/ChangeLog
2019-05-22  Tom Tromey  <tromey@adacore.com>

* gdb.base/info-shared.exp (check_info_shared): Use "style".
* gdb.base/style.exp: Use "style".
* lib/gdb-utils.exp (style): New proc.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/info-shared.exp
gdb/testsuite/gdb.base/style.exp
gdb/testsuite/lib/gdb-utils.exp

index 2f90b874d494acbb175dff5ade8e4dcf4b48bb64..2950a41b4cbdba7d27d9f9f5a2b406db075a9b15 100644 (file)
@@ -1,3 +1,9 @@
+2019-05-22  Tom Tromey  <tromey@adacore.com>
+
+       * gdb.base/info-shared.exp (check_info_shared): Use "style".
+       * gdb.base/style.exp: Use "style".
+       * lib/gdb-utils.exp (style): New proc.
+
 2019-05-22  Tom de Vries  <tdevries@suse.de>
 
        * gdb.base/align.exp: Require c++11.
index e1314bf5dd79515749815adb012fdfcae6a6267d..c21f3c36f503135b6ab20c3ab3d15a0dde6d80b3 100644 (file)
@@ -161,8 +161,10 @@ with_test_prefix styled {
 
        # Simple test for "info sharedlibrary" styling.  Look for styled
        # addresses and file name.
-       set addr "\033\\\[34m${hex}\033\\\[m"
-       set sofile "\033\\\[32m\[^\033\]+\033\\\[m"
+       set addr [style $hex address]
+       # Use a non-greedy match here to avoid accidentally picking up
+       # other escape sequences.
+       set sofile [style ".*?" file]
        gdb_test_no_output "set style enabled on"
        gdb_test "info sharedlibrary" \
            "$addr\[ \t\]+$addr.*$sofile\r\n.*"
index 369c1f59a88b32127232e9f7223d5034113489ab..15de05cdafb68b5cccb27c69f6a7963a1e797bd0 100644 (file)
@@ -41,10 +41,10 @@ save_vars { env(TERM) } {
 
     gdb_test_no_output "set style enabled on"
 
-    set main_expr "\033\\\[33mmain\033\\\[m"
-    set base_file_expr "\033\\\[32m.*style\\.c\033\\\[m"
+    set main_expr [style main function]
+    set base_file_expr [style ".*style\\.c" file]
     set file_expr "$base_file_expr:\[0-9\]"
-    set arg_expr "\033\\\[36marg.\033\\\[m"
+    set arg_expr [style "arg." variable]
 
     gdb_test "frame" \
        "$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*"
@@ -58,7 +58,7 @@ save_vars { env(TERM) } {
 
     gdb_test "break main" "file $base_file_expr.*"
 
-    gdb_test "print &main" " = .* \033\\\[34m$hex\033\\\[m <$main_expr>"
+    gdb_test "print &main" " = .* [style $hex address] <$main_expr>"
 
     # Regression test for a bug where line-wrapping would occur at the
     # wrong spot with styling.  There were different bugs at different
@@ -86,11 +86,12 @@ save_vars { env(TERM) } {
     gdb_exit
     gdb_spawn
 
-    gdb_test "" "\033\\\[35;1mGNU gdb.*\033\\\[m.*" \
+    set vers [style "GNU gdb.*" "35;1"]
+    gdb_test "" "${vers}.*" \
        "version is styled"
 
     set quoted [string_to_regexp $binfile]
     gdb_test "file $binfile" \
-       "Reading symbols from \033\\\[32m${quoted}\033\\\[m..." \
+       "Reading symbols from [style $quoted file]..." \
        "filename is styled when loading symbol file"
 }
index 26bbbf593c6fcb4f3c2d0c66674141999f05b555..a6567884426ac358e535a8130518f0fc845e70de 100644 (file)
@@ -37,3 +37,21 @@ proc string_to_regexp {str} {
     regsub -all {[]*+.|(){}^$\[\\]} $str {\\&} result
     return $result
 }
+
+# Wrap STR in an ANSI terminal escape sequences -- one to set the
+# style to STYLE, and one to reset the style to the default.  The
+# return value is suitable for use as a regular expression.
+
+# STYLE can either be the payload part of an ANSI terminal sequence,
+# or a shorthand for one of the gdb standard styles: "file",
+# "function", "variable", or "address".
+
+proc style {str style} {
+    switch -exact -- $style {
+       file { set style 32 }
+       function { set style 33 }
+       variable { set style 36 }
+       address { set style 34 }
+    }
+    return "\033\\\[${style}m${str}\033\\\[m"
+}
This page took 0.03634 seconds and 4 git commands to generate.