# test-options xxx", with no flag/option set. OPERAND is the expected
# operand.
proc expect_none {operand} {
- return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -- $operand"
+ return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -- $operand"
}
# Return a string for the expected result of running "maint
# test-options xxx", with -flag set. OPERAND is the expected operand.
proc expect_flag {operand} {
- return "-flag 1 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -- $operand"
+ return "-flag 1 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -- $operand"
}
# Return a string for the expected result of running "maint
# test-options xxx", with -bool set. OPERAND is the expected operand.
proc expect_bool {operand} {
- return "-flag 0 -xx1 0 -xx2 0 -bool 1 -enum xxx -uint 0 -zuint-unl 0 -- $operand"
+ return "-flag 0 -xx1 0 -xx2 0 -bool 1 -enum xxx -uint 0 -zuint-unl 0 -string '' -- $operand"
}
# Return a string for the expected result of running "maint
# expected operand.
proc expect_integer {option val operand} {
if {$option == "uinteger"} {
- return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint $val -zuint-unl 0 -- $operand"
+ return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint $val -zuint-unl 0 -string '' -- $operand"
} elseif {$option == "zuinteger-unlimited"} {
- return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl $val -- $operand"
+ return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl $val -string '' -- $operand"
} else {
error "unsupported option: $option"
}
}
+# Return a string for the expected result of running "maint
+# test-options xxx", with -string set to $STR. OPERAND is the
+# expected operand.
+proc expect_string {str operand} {
+ return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '$str' -- $operand"
+}
+
set all_options {
"-bool"
"-enum"
"-flag"
+ "-string"
"-uinteger"
"-xx1"
"-xx2"
# Extract twice the same flag, separated by one space.
gdb_test "$cmd -xx1 -xx2 -xx1 -xx2 -xx1 -- non flags args" \
- "-flag 0 -xx1 1 -xx2 1 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -- non flags args"
+ "-flag 0 -xx1 1 -xx2 1 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -- non flags args"
# Extract 2 known flags in front of unknown flags.
gdb_test "$cmd -xx1 -xx2 -a -b -c -xx1 --" \
# E.g., "frame apply all -past-main COMMAND".
if {$variant == "require-delimiter"} {
+ set match_list $all_options
+ lappend match_list "off" "on"
res_test_gdb_complete_multiple \
"1 [expect_none ""]" \
- "$cmd -bool " "" "" {
- "-bool"
- "-enum"
- "-flag"
- "-uinteger"
- "-xx1"
- "-xx2"
- "-zuinteger-unlimited"
- "off"
- "on"
- }
+ "$cmd -bool " "" "" $match_list
} else {
res_test_gdb_complete_none "0 " "$cmd -bool "
}
gdb_test "$cmd -enum www --" "Undefined item: \"www\"."
}
+# String option tests.
+proc_with_prefix test-string {variant} {
+ global all_options
+
+ set cmd [make_cmd $variant]
+
+ res_test_gdb_complete_none \
+ "1 [expect_none ""]" \
+ "$cmd -string "
+
+ # Check that "-" where a value is expected does not show the
+ # command's options. I.e., a string's value is not optional.
+ # Check both completion and running the command.
+ res_test_gdb_complete_none \
+ "1 [expect_none ""]" \
+ "$cmd -string -"
+ gdb_test "$cmd -string --"\
+ "-string requires an argument"
+ if {$variant == "require-delimiter"} {
+ gdb_test "$cmd -string" [expect_none "-string"]
+ } else {
+ gdb_test "$cmd -string"\
+ "-string requires an argument"
+ }
+
+ res_test_gdb_complete_none \
+ "1 [expect_none ""]" \
+ "$cmd -string STR"
+ gdb_test "$cmd -string STR --" [expect_string "STR" ""]
+
+ # Completing at "-" after parsing STR should list all options.
+ res_test_gdb_complete_multiple \
+ "1 [expect_string "STR" "-"]" \
+ "$cmd -string STR " "-" "" $all_options
+
+ # Check that only FOO is considered part of the string's value.
+ # I.e., that we stop parsing the string at the first whitespace.
+ if {$variant == "require-delimiter"} {
+ res_test_gdb_complete_none \
+ "1 [expect_string "FOO" "BAR"]" \
+ "$cmd -string FOO BAR"
+ } else {
+ res_test_gdb_complete_none "0 BAR" "$cmd -string FOO BAR"
+ }
+ gdb_test "$cmd -string FOO BAR --" "Unrecognized option at: BAR --"
+}
+
# Run the options framework tests first.
foreach_with_prefix cmd {
"require-delimiter"
test-uinteger $cmd $subcmd
}
test-enum $cmd
+ test-string $cmd
}
# Run the print integration tests, both as "standalone", and under