+# Test printf of convenience variables.
+# These tests can be done with or without a running inferior.
+# PREFIX ensures uniqueness of test names.
+# DO_WSTRING 1 tells to test printf of wide strings. Wide strings tests
+# must be skipped (DO_WSTRING 0) if the wchar_t type is not yet known by
+# GDB, as this type is needed to create wide strings.
+
+proc test_printf_convenience_var {prefix do_wstring} {
+
+ with_test_prefix "conv var: $prefix" {
+ gdb_test_no_output "set var \$cstr = \"abcde\"" "set \$cstr"
+ gdb_test "printf \"cstr val = %s\\n\", \$cstr" "cstr val = abcde" \
+ "printf \$cstr"
+ gdb_test_no_output "set var \$abcde = \"ABCDE\"" "set \$abcde"
+ gdb_test "eval \"print \$%s\\n\", \$cstr" "= \"ABCDE\"" \
+ "indirect print abcde"
+ # Without a target, the below produces no output
+ # but with a target, it gives a warning.
+ # So, use gdb_test expecting ".*" instead of gdb_test_no_output.
+ gdb_test "set language ada" ".*" "set language ada"
+ gdb_test_no_output "set var \$astr := \"fghij\"" "set \$astr"
+ gdb_test "printf \"astr val = %s\\n\", \$astr" "astr val = fghij" \
+ "printf \$astr"
+ gdb_test_no_output "set language auto" "set language auto"
+ gdb_test "printf \"astr val = %s\\n\", \$astr" "astr val = fghij" \
+ "printf \$astr, auto language"
+ if {$do_wstring} {
+ gdb_test_no_output "set var \$wstr = L\"facile\"" \
+ "set \$wstr"
+ gdb_test "printf \"wstr val = %ls\\n\", \$wstr" \
+ "wstr val = facile" "printf \$wstr"
+ }
+ }
+}
+
+