[v2,10/18] Implement completion limiting for cmdpy_completer.
Commit Message
This patch converts cmdpy_completer, used by commands written in
python. It also adds tests for some untested python functionality
related to completion.
gdb/ChangeLog
* python/py-cmd.c (cmdpy_completer) Use add_completion.
gdb/testsuite/ChangeLog
* gdb.python/py-completion.exp: Test completion functions,
with and without completion limiting.
---
gdb/python/py-cmd.c | 5 ++-
gdb/testsuite/gdb.python/py-completion.exp | 45 ++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)
@@ -392,7 +392,10 @@ cmdpy_completer (struct completer_data *cdata,
PyErr_Clear ();
continue;
}
- VEC_safe_push (char_ptr, result, item);
+
+ if (add_completion (cdata, &result, item)
+ == ADD_COMPLETION_MAX_REACHED)
+ break;
}
Py_DECREF (iter);
@@ -128,3 +128,48 @@ if {[readline_is_used]} {
"completelimit2 cl29"
}
}
+
+# The terminal at the end of the complete command
+set end "\\\*\\\*\\\* List may be truncated, "
+append end "max-completions reached\\\. \\\*\\\*\\\*"
+
+set max_completions 3
+gdb_test_no_output "set max-completions $max_completions"
+set seen 0
+
+set testname "limit completions of 'complete completel'"
+gdb_test_multiple "complete completel" $testname {
+ "complete completel" { exp_continue }
+
+ -re "completelimit\[1-9\]+\r\n" {
+ incr seen
+ exp_continue
+ }
+
+ -re "completel $end\r\n$gdb_prompt $" {
+ if {$seen == $max_completions} {
+ pass $testname
+ } else {
+ fail "$testname ($seen/$max_completions)"
+ }
+ }
+}
+
+set testname "limit completions of 'complete completelimit1 c'"
+set seen 0
+gdb_test_multiple "complete completelimit1 c" $testname {
+ "complete completelimit1 c" { exp_continue }
+
+ -re "completelimit1 cl1\[1-9\]+\r\n" {
+ incr seen
+ exp_continue
+ }
+
+ -re "completelimit1 c $end\r\n$gdb_prompt $" {
+ if {$seen == $max_completions} {
+ pass $testname
+ } else {
+ fail "$testname ($seen/$max_completions)"
+ }
+ }
+}