Skip to content

Commit

Permalink
Report cursor position in screen-dump, and add "-expect-cursor"
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdphk committed Apr 11, 2018
1 parent 71c29e8 commit 4c3ef2d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
12 changes: 8 additions & 4 deletions bin/varnishtest/tests/a00000.vtc
Expand Up @@ -55,10 +55,14 @@ process p4 -write "\x1b[H\x1b[2J1\x1b[79C2\x08>\x1b[25;1H3\x1b[25;80H"
process p4 -write "4\x08>\x1b[A\x1b[Cv\x1b[22A^\x1b[79D^\x1b[;2H<\n\n\n\n"
process p4 -write "\n\n\n\n\n\n\n\n\x1b[B\x1b[11B\x08<\x1b[24;Hv\x1b[12;1H"
process p4 -write "111111112222222333333\x0d\x0a111111112"
process p4 -write "222222333333\x0d\x0a111111112222222333"
process p4 -write "333\x0d\x0a111111112222222333333\x0d\x0a\x1b[12"
process p4 -write "222222333333\x0d\x0a111111112222222333333 UTF8: "
process p4 -writehex {c2 a2 20 e2 82 ac 20 f0 9f 90 b0}
process p4 -write "\x0d\x0a111111112222222333333\x0d\x0a\x1b[12"
process p4 -write ";12H\x1b[K\x1b[13;12H\x1b[0K\x1b[14;12H\x1b[1K\x1b"
process p4 -write "[15;12H\x1b[2K\x1b[3;1Hline3 <\x0d\x0a"

process p4 -need-bytes 252 -expect-text 3 1 "line3 <"
process p4 -screen_dump -stop
process p4 -need-bytes 270 -expect-text 3 1 "line3 <"
process p4 -expect-cursor 4 1
process p4 -expect-cursor 4 0
process p4 -expect-cursor 0 1
process p4 -screen-dump -stop
31 changes: 30 additions & 1 deletion bin/varnishtest/vtc_process.c
Expand Up @@ -205,9 +205,13 @@ static void
term_screen_dump(const struct process *pp)
{
int i;
const teken_pos_t *pos;

for (i = 0; i < pp->nlin; i++)
vtc_dump(pp->vl, 3, "screen", pp->vram[i], pp->ncol);
pos = teken_get_cursor(pp->tek);
vtc_log(pp->vl, 3, "Cursor at line %d column %d",
pos->tp_row + 1, pos->tp_col + 1);
}

static void
Expand Down Expand Up @@ -312,6 +316,23 @@ term_expect_text(struct process *pp,
vtc_log(pp->vl, 4, "found expected text at %d,%d: '%s'", y, x, pat);
}

static void
term_expect_cursor(struct process *pp, const char *lin, const char *col)
{
int x, y;
const teken_pos_t *pos;

pos = teken_get_cursor(pp->tek);
y = strtoul(lin, NULL, 0);
x = strtoul(col, NULL, 0);
if (y != 0 && (y-1) != pos->tp_row)
vtc_fatal(pp->vl, "Cursor on line %d (expected %d)",
pos->tp_row + 1, y);
if (x != 0 && (x-1) != pos->tp_col)
vtc_fatal(pp->vl, "Cursor in column %d (expected %d)",
pos->tp_col + 1, y);
}

/**********************************************************************
* Allocate and initialize a process
*/
Expand Down Expand Up @@ -968,7 +989,15 @@ cmd_process(CMD_ARGS)
av += 3;
continue;
}
if (!strcmp(*av, "-screen_dump")) {
if (!strcmp(*av, "-expect-cursor")) {
AN(av[1]);
AN(av[2]);
term_expect_cursor(p, av[1], av[2]);
av += 2;
continue;
}
if (!strcmp(*av, "-screen_dump") ||
!strcmp(*av, "-screen-dump")) {
term_screen_dump(p);
continue;
}
Expand Down

0 comments on commit 4c3ef2d

Please sign in to comment.