[gdb/testsuite] Fix and add prompt anchoring in tuiterm
commit3e543c18b174a6d68277d27f27a98eb9515d20c5
authorTom de Vries <tdevries@suse.de>
Tue, 13 Jun 2023 10:24:17 +0000 (13 12:24 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 13 Jun 2023 10:24:17 +0000 (13 12:24 +0200)
treef33bbca0ef7f0e16ec5c3f02f855fdcc45cb9035
parentcc313a1d84d3b76d5a4f6208d1aa6c0e99c0d132
[gdb/testsuite] Fix and add prompt anchoring in tuiterm

There is a test-case that contains a unit test for tuiterm:
gdb.tui/tuiterm.exp.

However, this only excercises the tuiterm itself, and not the functions that
interact with it, like Term::command.

Add a new test-case gdb.tui/tuiterm-2.exp that:
- overrides proc accept_gdb_output (to be able simulate incorrect responses
  while avoiding the timeout),
- overrides proc send_gdb (to be able to call Term::command without a gdb
  instance, such that all tuiterm input is generated by the test-case).
- issues Term::command calls, and
- checks whether they behave correctly.

This exposes a problem in Term::command.  The "prompt before command" regexp
starts with a bit that is supposed to anchor the prompt to the border:
...
set str "(^|\|)$gdb_prompt $str"
...
but that doesn't work due to insufficient escaping.  Fix this by adding the
missing escape:
...
set str "(^|\\|)$gdb_prompt $str"
...

Futhermore, the "prompt after command" regexp in Term::wait_for has no
anchoring at all:
...
set prompt_wait_for "$gdb_prompt \$"
...
so add that as well.

Tested on x86_64-linux.
gdb/testsuite/gdb.tui/tuiterm-2.exp [new file with mode: 0644]
gdb/testsuite/lib/tuiterm.exp