public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: gdb-patches@sourceware.org
Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Subject: [RFAv3 2/4] Test define-prefix.
Date: Thu, 28 Nov 2019 20:09:00 -0000	[thread overview]
Message-ID: <20191128200901.27511-3-philippe.waroquiers@skynet.be> (raw)
In-Reply-To: <20191128200901.27511-1-philippe.waroquiers@skynet.be>

Adds a test testing the new define-prefix command.

2019-11-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/define-prefix.exp: New file.
---
 gdb/testsuite/gdb.base/define-prefix.exp | 164 +++++++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/define-prefix.exp

diff --git a/gdb/testsuite/gdb.base/define-prefix.exp b/gdb/testsuite/gdb.base/define-prefix.exp
new file mode 100644
index 0000000000..b04c5959c0
--- /dev/null
+++ b/gdb/testsuite/gdb.base/define-prefix.exp
@@ -0,0 +1,164 @@
+# 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/>.
+
+
+# This test verifies the "define-prefix" command.
+
+gdb_start
+
+####################
+# Verify the definition of user defined prefix commands.
+# Test the definition of a command using these prefixes.
+
+# Define an empty prefix command.
+gdb_test_no_output "define-prefix abc-prefix"
+
+# Verify an empty prefix command cannot be used as a command.
+gdb_test "abc-prefix" \
+    "\"abc-prefix\" must be followed by the name of a subcommand.*" \
+    "execute prefix command not followed by subcommand"
+
+# Define a sub-prefix command.
+gdb_test_no_output "define-prefix abc-prefix def-prefix"
+
+# Define ghi-cmd using the prefixes.
+gdb_test_multiple "define abc-prefix def-prefix ghi-cmd" \
+    "define user command: abc-prefix def-prefix ghi-cmd" {
+	-re "Type commands for definition of \"abc-prefix def-prefix ghi-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	    gdb_test "echo command ghi-cmd\\n\nend" "" \
+		"define user command: ghi-cmd"
+	}
+    }
+# Verify ghi-cmd works.
+gdb_test "abc-prefix def-prefix ghi-cmd" \
+    "command ghi-cmd" \
+    "use user command: ghi-cmd"
+
+
+####################
+# Verify an existing (empty) command can be marked as a prefix command.
+# Then verify an empty prefix command can be transformed into an executable command.
+
+# Define ghi-prefix-cmd as an empty command.
+gdb_test_multiple "define abc-prefix def-prefix ghi-prefix-cmd" \
+    "define user command: abc-prefix def-prefix ghi-prefix-cmd" {
+	-re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	    gdb_test "end" "" \
+		"define user command: ghi-prefix-cmd"
+	}
+    }
+gdb_test_no_output "define-prefix abc-prefix def-prefix ghi-prefix-cmd"
+
+# Verify a sequence ending with an empty prefix command cannot be used as
+# a command.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
+    "\"abc-prefix def-prefix ghi-prefix-cmd\" must be followed by the name of a subcommand.*" \
+    "execute sequence of prefix commands not followed by a subcommand"
+
+# Define jkl-cmd command.
+gdb_test_multiple "define abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
+    "define user command: abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" {
+	-re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd jkl-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	    gdb_test "echo command jkl-cmd\\n\nend" "" \
+		"define user command: jkl-cmd"
+	}
+    }
+# Verify jkl-cmd command works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
+    "command jkl-cmd" \
+    "use user command: jkl-cmd"
+
+# Define alternate-jkl-cmd and check it works.
+# Define alternate-jkl-cmd command.
+gdb_test_multiple "define abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
+    "define user command: abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" {
+	-re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	    gdb_test "echo command alternate-jkl-cmd\\n\nend" "" \
+		"define user command: alternate-jkl-cmd"
+	}
+    }
+# Verify alternate-jkl-cmd command works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
+    "command alternate-jkl-cmd" \
+    "use user command: alternate-jkl-cmd"
+
+
+
+# Now define ghi-prefix-cmd as a real command, and check it is working.
+send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
+gdb_expect {
+    -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+	send_gdb "echo defined command ghi-prefix-cmd\\n\nend\n"
+	gdb_expect {
+	    -re "$gdb_prompt $" {pass "define user command: ghi-prefix-cmd"}
+	    timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
+	}
+    }
+    timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
+}
+
+# Verify ghi-prefix-cmd command works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
+    "defined command ghi-prefix-cmd" \
+    "use defined user command: ghi-prefix-cmd"
+
+# Now redefine ghi-prefix-cmd, and check it is working.
+send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
+gdb_expect {
+    -re "Keeping subcommands of prefix command \"ghi-prefix-cmd\"\.\r\nRedefine command \"ghi-prefix-cmd\".*y or n. $" {
+	send_gdb "y\n"
+	gdb_expect {
+	    -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+		send_gdb "echo redefined command ghi-prefix-cmd\\n\nend\n"
+		gdb_expect {
+		    -re "$gdb_prompt $" {pass "redefine user command: ghi-prefix-cmd"}
+		    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
+		}
+	    }
+	    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
+	}
+    }
+    -re "$gdb_prompt $" {fail "redefine user command: ghi-prefix-cmd"}
+    timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
+}
+
+# Verify redefined ghi-prefix-cmd command works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
+    "redefined command ghi-prefix-cmd" \
+    "use redefined user command: ghi-prefix-cmd"
+
+# Check jkl-cmd still works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
+    "command jkl-cmd" \
+    "use user command after redefining ghi-prefix-cmd: jkl-cmd"
+
+# Check alternate-jkl-cmd still works.
+gdb_test "abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
+    "command alternate-jkl-cmd" \
+    "use user command after redefining ghi-prefix-cmd: alternate-jkl-cmd"
+
+####################
+# Check error behaviour.
+
+gdb_test "define-prefix print" ".* is built-in.*"
+
+gdb_test "define-prefix something-not-existing something-else" \
+    "Undefined command: \"something-not-existing\".*"
+
+gdb_test "define-prefix abc-prefix something-not-existing something-else" \
+    "Undefined abc-prefix command: \"something-not-existing\".*"
+
-- 
2.20.1

  parent reply	other threads:[~2019-11-28 20:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28 20:09 [RFAv3 0/4] More flexible user-defined commands prefixing and naming Philippe Waroquiers
2019-11-28 20:09 ` [RFAv3 1/4] Implement user defined prefix Philippe Waroquiers
2019-11-30  4:09   ` Simon Marchi
2019-11-28 20:09 ` [RFAv3 3/4] Allow . character as part of command names Philippe Waroquiers
2019-11-28 20:09 ` [RFAv3 4/4] Document define-prefix command and the use of . in " Philippe Waroquiers
2019-11-28 20:09 ` Philippe Waroquiers [this message]
2019-11-30  3:36 ` [RFAv3 0/4] More flexible user-defined commands prefixing and naming Simon Marchi
2019-11-30  8:55   ` Philippe Waroquiers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191128200901.27511-3-philippe.waroquiers@skynet.be \
    --to=philippe.waroquiers@skynet.be \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).