aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base
diff options
context:
space:
mode:
authorPatrick Palka <patrick@parcs.ath.cx>2015-06-02 22:49:15 -0400
committerPatrick Palka <patrick@parcs.ath.cx>2015-06-26 11:05:56 -0400
commitfc637f04c741b08726cc1631428bf094235ecb4e (patch)
tree1bb91721617e984a814138fd3fb0401af3541ba4 /gdb/testsuite/gdb.base
parent2e52ae68e7cedc3a1f9908c98ee60a8602705835 (diff)
downloadbinutils-fc637f04c741b08726cc1631428bf094235ecb4e.zip
binutils-fc637f04c741b08726cc1631428bf094235ecb4e.tar.gz
binutils-fc637f04c741b08726cc1631428bf094235ecb4e.tar.bz2
Add option to remove duplicate command history entries
This patch implements the new option "history remove-duplicates", which controls the removal of duplicate history entries ("off" by default). The motivation for this option is to be able to reduce the prevalence of basic commands such as "up" and "down" in the history file. These common commands crowd out more unique commands in the history file (when the history file has a fixed size), and they make navigation of the history file via ^P, ^N and ^R more inconvenient. The option takes an integer denoting the number of history entries to look back at for a history entry that is a duplicate of the latest one. "history remove-duplicates 1" is equivalent to bash's ignoredups option, and "history remove-duplicates unlimited" is equivalent to bash's erasedups option. [ I decided to go with this integer approach instead of a tri-state enum because it's slightly more flexible and seemingly more intuitive than leave/erase/ignore. ] gdb/ChangeLog: * NEWS: Mention the new option "history remove-duplicates". * top.c (history_remove_duplicates): New static variable. (show_history_remove_duplicates): New static function. (gdb_add_history): Conditionally remove duplicate history entries. (init_main): Add "history remove-duplicates" option. gdb/doc/ChangeLog: * gdb.texinfo (Command History): Document the new option "history remove-duplicates". gdb/testsuite/ChangeLog: * gdb.base/history-duplicates.exp: New test.
Diffstat (limited to 'gdb/testsuite/gdb.base')
-rw-r--r--gdb/testsuite/gdb.base/history-duplicates.exp117
1 files changed, 117 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/history-duplicates.exp b/gdb/testsuite/gdb.base/history-duplicates.exp
new file mode 100644
index 0000000..11bb1ed
--- /dev/null
+++ b/gdb/testsuite/gdb.base/history-duplicates.exp
@@ -0,0 +1,117 @@
+# Copyright 2015 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 file is part of the gdb testsuite.
+
+# Test the operation of the "history remove-duplicates" option.
+
+
+# Check that the previous history entry is ENTRY.
+
+proc check_prev_history_entry { entry { test_suffix "" } } {
+ set test_name "history entry is $entry"
+ if { $test_suffix != "" } {
+ append test_name " $test_suffix"
+ }
+
+ # Send ^P followed by ^L.
+ send_gdb "\x10\x0c"
+
+ gdb_expect {
+ -re $entry {
+ pass $test_name
+ }
+ timeout {
+ fail $test_name
+ }
+ }
+}
+
+# Foreach element ELT in THINGS, run the command "print $ELT", making sure that
+# each invocation of "print" has a unique test name.
+
+proc run_print_on_each_thing { things } {
+ set index 0
+
+ foreach thing $things {
+ gdb_test "print $thing" "" "printing $thing (item #$index)"
+ incr index
+ }
+}
+
+# By default the option is set to 0.
+gdb_exit
+gdb_start
+gdb_test "show history remove-duplicates" "is 0\\."
+
+# Test the "unlimited" setting.
+with_test_prefix "remove-duplicates=unlimited" {
+ gdb_exit
+ gdb_start
+ gdb_test "set history remove-duplicates unlimited"
+
+ run_print_on_each_thing { 0 1 2 1 1 2 3 3 4 1 2 3 4 }
+
+ check_prev_history_entry "print 4"
+ check_prev_history_entry "print 3"
+ check_prev_history_entry "print 2"
+ check_prev_history_entry "print 1"
+ check_prev_history_entry "print 0"
+}
+
+
+# Test the "1" setting.
+with_test_prefix "remove-duplicates=1" {
+ gdb_exit
+ gdb_start
+ gdb_test "set history remove-duplicates 1"
+
+ run_print_on_each_thing { 0 1 0 2 2 1 }
+
+ check_prev_history_entry "print 1"
+ check_prev_history_entry "print 2"
+ check_prev_history_entry "print 0"
+ check_prev_history_entry "print 1" "(again)"
+ check_prev_history_entry "print 0" "(again)"
+}
+
+
+# Test the "0" setting.
+with_test_prefix "remove-duplicates=0" {
+ gdb_exit
+ gdb_start
+ gdb_test "set history remove-duplicates 0"
+
+ run_print_on_each_thing { 0 0 1 1 }
+
+ check_prev_history_entry "print 1"
+ check_prev_history_entry "print 1" "(again)"
+ check_prev_history_entry "print 0"
+ check_prev_history_entry "print 0" "(again)"
+}
+
+
+# Test the "2" setting.
+with_test_prefix "remove-duplicates=2" {
+ gdb_exit
+ gdb_start
+ gdb_test "set history remove-duplicates 2"
+
+ run_print_on_each_thing { 1 2 0 2 0 }
+
+ check_prev_history_entry "print 0"
+ check_prev_history_entry "print 2"
+ check_prev_history_entry "print 1"
+}