+# Basic option-machinery + "thread apply" command integration tests.
+proc_with_prefix test-thread-apply {} {
+
+ test_gdb_complete_unique "thread apply all" "thread apply all"
+ test_gdb_complete_unique "taas" "taas"
+
+ gdb_test "thread apply 1-" \
+ "inverted range"
+ test_gdb_complete_none "frame apply level 1-"
+
+ foreach cmd {
+ "thread apply all"
+ "thread apply 1"
+ "taas"
+ } {
+ test_gdb_completion_offers_commands "$cmd "
+
+ # taas is silent on command error by design. This procedure
+ # hides the difference. EXPECTED_RE is only considered when
+ # not testing with "taas".
+ proc test_invalid_cmd {cmd arg expected_re} {
+ if {$cmd != "taas"} {
+ gdb_test "$cmd$arg" $expected_re
+ } else {
+ gdb_test_no_output "$cmd$arg"
+ }
+ }
+
+ gdb_test "$cmd -" "Ambiguous option at: -"
+
+ if {$cmd != "thread apply 1"} {
+ test_gdb_complete_multiple "$cmd " "-" "" {
+ "-ascending"
+ "-c"
+ "-q"
+ "-s"
+ }
+ } else {
+ # "-ascending" only works with "all".
+ test_gdb_complete_multiple "$cmd " "-" "" {
+ "-c"
+ "-q"
+ "-s"
+ }
+ }
+
+ if {$cmd == "thread apply all" || $cmd == "taas"} {
+ set errmsg \
+ "Please specify a command at the end of 'thread apply all'"
+ } elseif {$cmd == "thread apply 1"} {
+ set errmsg \
+ "Please specify a command following the thread ID list"
+ } else {
+ error "unexpected cmd: $cmd"
+ }
+
+ with_test_prefix "no-trailing-space" {
+ gdb_test "$cmd --" $errmsg
+ test_gdb_complete_unique "$cmd --" "$cmd --"
+ }
+
+ with_test_prefix "trailing-space" {
+ gdb_test "$cmd -- " $errmsg
+ test_gdb_completion_offers_commands "$cmd -- "
+ }
+
+ # '-' is a valid TUI command.
+ test_invalid_cmd "$cmd" " -- -" \
+ "Cannot enable the TUI when output is not a terminal"
+ test_gdb_complete_unique \
+ "$cmd -- -" \
+ "$cmd -- -"
+
+ test_invalid_cmd $cmd " -foo" \
+ "Undefined command: \"-foo\". Try \"help\"\\."
+ test_gdb_complete_none "$cmd -foo"
+
+ test_gdb_completion_offers_commands "$cmd -c "
+ }
+}
+