Patchwork [RFAv2,2/3] Add tests for new leading-args related commands and arguments.

login
register
mail settings
Submitter Philippe Waroquiers
Date Aug. 5, 2019, 8:51 p.m.
Message ID <20190805205159.31689-3-philippe.waroquiers@skynet.be>
Download mbox | patch
Permalink /patch/33970/
State New
Headers show

Comments

Philippe Waroquiers - Aug. 5, 2019, 8:51 p.m.
Test the new leading-args behaviour and completion.
Note that gdb.base/leading-args.exp is somewhat copied from
with.exp (the test of the with command), while leading-exp.c
is a plain copy of with.c.

gdb/testsuite/ChangeLog
2019-08-04  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/leading-args.exp: New test.
	* gdb.base/leading.c: New file.
	* gdb.base/alias.exp: Update expected error msg for alias foo=bar.
---
 gdb/testsuite/gdb.base/alias.exp        |   2 +-
 gdb/testsuite/gdb.base/leading-args.c   |  41 +++++++
 gdb/testsuite/gdb.base/leading-args.exp | 151 ++++++++++++++++++++++++
 3 files changed, 193 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.base/leading-args.c
 create mode 100644 gdb/testsuite/gdb.base/leading-args.exp

Patch

diff --git a/gdb/testsuite/gdb.base/alias.exp b/gdb/testsuite/gdb.base/alias.exp
index 20722e5dea..764d3ff8ff 100644
--- a/gdb/testsuite/gdb.base/alias.exp
+++ b/gdb/testsuite/gdb.base/alias.exp
@@ -56,7 +56,7 @@  test_abbrev_alias set6 "alias -a -- set6 = set" 46
 test_abbrev_alias -a "alias -a -- -a = set" 47
 
 gdb_test "alias set2=set" "already exists: set2"
-gdb_test "alias foo=bar" "Invalid command to alias to: bar"
+gdb_test "alias foo=bar" "Undefined command: \"bar\".  Try \"help\"."
 
 gdb_test_no_output "alias spe = set p elem"
 gdb_test_no_output "spe 50"
diff --git a/gdb/testsuite/gdb.base/leading-args.c b/gdb/testsuite/gdb.base/leading-args.c
new file mode 100644
index 0000000000..c6426625d4
--- /dev/null
+++ b/gdb/testsuite/gdb.base/leading-args.c
@@ -0,0 +1,41 @@ 
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2019 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int xxx1 = 123;
+
+struct S
+{
+  int a;
+  int b;
+  int c;
+};
+
+struct S g_s = {1, 2, 3};
+
+static void
+inc ()
+{
+  g_s.a++;;
+}
+
+int
+main ()
+{
+  inc ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/leading-args.exp b/gdb/testsuite/gdb.base/leading-args.exp
new file mode 100644
index 0000000000..ecc308fb51
--- /dev/null
+++ b/gdb/testsuite/gdb.base/leading-args.exp
@@ -0,0 +1,151 @@ 
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2019 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test the "leading-args" related commands and arguments.
+
+load_lib completion-support.exp
+
+standard_testfile .c
+
+if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
+    return -1
+}
+
+clean_restart $binfile
+
+# Basic/core tests using user-visible commands.
+with_test_prefix "basics" {
+    # Define an alias to pretty print something.
+    gdb_test "print g_s" " = {a = 1, b = 2, c = 3}" "simple print"
+    gdb_test_no_output "alias PP = print -pretty --" "alias PP"
+    gdb_test "show leading-args PP" "leading-args PP = -pretty --"
+    gdb_test "PP g_s" \
+	[multi_line  \
+	     " = {" \
+	     "  a = 1," \
+	     "  b = 2," \
+	     "  c = 3" \
+	     "}"]
+
+    # Define leading-args for "inspect", should not impact "print".
+    gdb_test_no_output "set leading-args inspect -pretty --" "inspect -pretty"
+    gdb_test "show leading-args inspect" "leading-args inspect = -pretty --"
+    gdb_test "print g_s" " = {a = 1, b = 2, c = 3}" "simple print not impacted"
+    gdb_test "inspect g_s" \
+	[multi_line  \
+	     " = {" \
+	     "  a = 1," \
+	     "  b = 2," \
+	     "  c = 3" \
+	     "}"]
+
+    # Set hex as default FMT for print.
+    gdb_test_no_output "set leading-args print -- /x" "print hex"
+    gdb_test "inspect g_s" \
+	[multi_line  \
+	     " = {" \
+	     "  a = 1," \
+	     "  b = 2," \
+	     "  c = 3" \
+	     "}"] "inspect g_s still pretty"
+    gdb_test "print g_s" " = {a = 0x1, b = 0x2, c = 0x3}" "simple print hex"
+
+    # Test disabling leading args.
+    gdb_test "show enable-leading-args" \
+	"Whether GDB prepends leading args when running a command is on\."
+    gdb_test_no_output "set enable-leading-args off"
+    gdb_test "print g_s" " = {a = 1, b = 2, c = 3}" \
+	"simple print with enable-leading-args off"
+    gdb_test_no_output "set enable-leading-args on"
+    
+
+    # Define leading-args for an alias of frame apply all
+    gdb_test_no_output "alias frame apply tout = frame apply all -past-entry -past-main" \
+	"alias frame apply tout"
+    gdb_test "show leading-args frame apply tout" \
+	"leading-args frame apply tout = -past-entry -past-main"
+
+    # Show all leading args.
+    gdb_test "show leading-args" \
+	[multi_line  \
+	     "leading-args PP = -pretty --" \
+	     "leading-args frame apply tout = -past-entry -past-main" \
+	     "leading-args inspect = -pretty --" \
+	     "leading-args print = -- /x"] "show leading-args"
+
+    # Clear the leading-args of "inspect".
+    gdb_test_no_output "set leading-args inspect" "clear inspect leading-args"
+    gdb_test "show leading-args inspect" "leading-args inspect = <no leading args>"
+    gdb_test "inspect g_s" " = {a = 1, b = 2, c = 3}" "simple inspect"
+
+}
+
+# Check errors.
+with_test_prefix "errors" {
+    # Try an unknown root setting.
+    gdb_test "set leading-args xxxx yyyy -someoption" \
+	"Undefined command: \"xxxx\".  Try \"help\"\\."
+
+    # Try ambiguous command.
+    gdb_test "set leading-args a" \
+	"Ambiguous command \"a\":.*" "ambiguous a"
+    gdb_test "set leading-args frame a" \
+	"Ambiguous frame command \"a\":.*" "ambiguous frame a"
+}
+
+
+# Check completion.
+with_test_prefix "completion" {
+    test_gdb_complete_unique \
+	"alias set pri" \
+	"alias set print"
+
+    test_gdb_complete_unique \
+	"alias set print items = set pri" \
+	"alias set print items = set print"
+
+    test_gdb_complete_unique \
+	"alias set print items = set print ele" \
+	"alias set print items = set print elements"
+
+   test_gdb_complete_unique \
+	"alias btfu = backt" \
+	"alias btfu = backtrace"
+
+   test_gdb_complete_unique \
+	"alias btfu = backtrace -fu" \
+	"alias btfu = backtrace -full"
+
+   test_gdb_complete_unique \
+	"alias btfu = backtrace -full -past-e" \
+	"alias btfu = backtrace -full -past-entry"
+
+    gdb_test_no_output "alias btfu = backtrace -full -past-entry" \
+	"alias btfu"
+
+    # Test completion of 'set leading-args' (sharing most
+    # of the code that alias command uses to complete after
+    # the first =.
+    test_gdb_complete_unique \
+	"set leading-args btf" \
+	"set leading-args btfu"
+
+    test_gdb_complete_unique \
+	"set leading-args btfu -frame-a" \
+	"set leading-args btfu -frame-arguments"
+
+}