181 lines
5.9 KiB
Diff
181 lines
5.9 KiB
Diff
|
|
From 1854abde0e4031fd35a95cd6df0d982ba8c9bd16 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Mark Nudelman <markn@greenwoodsoftware.com>
|
||
|
|
Date: Tue, 11 Oct 2022 20:21:10 -0700
|
||
|
|
Subject: [PATCH 14/48] lesstest: split display_screen into
|
||
|
|
display_screen_debug and display_screen.
|
||
|
|
|
||
|
|
---
|
||
|
|
lesstest/display.c | 56 +++++++++++++++++++++++++++++++++------------
|
||
|
|
lesstest/lesstest.h | 3 ++-
|
||
|
|
lesstest/pipeline.c | 2 --
|
||
|
|
lesstest/run.c | 15 ++++++------
|
||
|
|
4 files changed, 52 insertions(+), 24 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/lesstest/display.c b/lesstest/display.c
|
||
|
|
index a7e1954..5243337 100644
|
||
|
|
--- a/lesstest/display.c
|
||
|
|
+++ b/lesstest/display.c
|
||
|
|
@@ -31,7 +31,7 @@ static void display_color(Color color) {
|
||
|
|
printf("\33[%dm", color);
|
||
|
|
}
|
||
|
|
|
||
|
|
-void display_screen(const byte* img, int imglen, int screen_width, int screen_height, int move_cursor) {
|
||
|
|
+void display_screen(const byte* img, int imglen, int screen_width, int screen_height) {
|
||
|
|
int x = 0;
|
||
|
|
int y = 0;
|
||
|
|
int cursor_x = 0;
|
||
|
|
@@ -65,19 +65,49 @@ void display_screen(const byte* img, int imglen, int screen_width, int screen_he
|
||
|
|
}
|
||
|
|
}
|
||
|
|
literal = 0;
|
||
|
|
- if (move_cursor) {
|
||
|
|
- if (ch != 0) {
|
||
|
|
- byte cbuf[UNICODE_MAX_BYTES];
|
||
|
|
- byte* cp = cbuf;
|
||
|
|
- store_wchar(&cp, ch);
|
||
|
|
- fwrite(cbuf, 1, cp-cbuf, stdout);
|
||
|
|
+ if (ch != 0) {
|
||
|
|
+ byte cbuf[UNICODE_MAX_BYTES];
|
||
|
|
+ byte* cp = cbuf;
|
||
|
|
+ store_wchar(&cp, ch);
|
||
|
|
+ fwrite(cbuf, 1, cp-cbuf, stdout);
|
||
|
|
+ }
|
||
|
|
+ if (++x >= screen_width) {
|
||
|
|
+ printf("\n");
|
||
|
|
+ x = 0;
|
||
|
|
+ if (++y >= screen_height)
|
||
|
|
+ break;
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+ printf("%s", tgoto(terminfo.cursor_move, cursor_x, cursor_y));
|
||
|
|
+ fflush(stdout);
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+void display_screen_debug(const byte* img, int imglen, int screen_width, int screen_height) {
|
||
|
|
+ int x = 0;
|
||
|
|
+ int y = 0;
|
||
|
|
+ int literal = 0;
|
||
|
|
+ while (imglen-- > 0) {
|
||
|
|
+ wchar ch = load_wchar(&img);
|
||
|
|
+ if (!literal) {
|
||
|
|
+ switch (ch) {
|
||
|
|
+ case '\\':
|
||
|
|
+ literal = 1;
|
||
|
|
+ continue;
|
||
|
|
+ case LTS_CHAR_ATTR:
|
||
|
|
+ case LTS_CHAR_COLOR:
|
||
|
|
+ x -= 2; // don't count LTS_CHAR or following byte
|
||
|
|
+ literal = 1;
|
||
|
|
+ break;
|
||
|
|
+ case LTS_CHAR_CURSOR:
|
||
|
|
+ x -= 1; // don't count LTS_CHAR
|
||
|
|
+ break;
|
||
|
|
}
|
||
|
|
- } else {
|
||
|
|
- if (is_ascii(ch))
|
||
|
|
- fwrite(&ch, 1, 1, stdout);
|
||
|
|
- else
|
||
|
|
- printf("<%lx>", (unsigned long) ch);
|
||
|
|
}
|
||
|
|
+ literal = 0;
|
||
|
|
+ if (is_ascii(ch))
|
||
|
|
+ fwrite(&ch, 1, 1, stdout);
|
||
|
|
+ else
|
||
|
|
+ printf("<%lx>", (unsigned long) ch);
|
||
|
|
if (++x >= screen_width) {
|
||
|
|
printf("\n");
|
||
|
|
x = 0;
|
||
|
|
@@ -85,8 +115,6 @@ void display_screen(const byte* img, int imglen, int screen_width, int screen_he
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
- if (move_cursor)
|
||
|
|
- printf("%s", tgoto(terminfo.cursor_move, cursor_x, cursor_y));
|
||
|
|
fflush(stdout);
|
||
|
|
}
|
||
|
|
|
||
|
|
diff --git a/lesstest/lesstest.h b/lesstest/lesstest.h
|
||
|
|
index 8585f34..93bbed3 100644
|
||
|
|
--- a/lesstest/lesstest.h
|
||
|
|
+++ b/lesstest/lesstest.h
|
||
|
|
@@ -74,7 +74,8 @@ TestSetup* read_test_setup(FILE* fd, char const* less);
|
||
|
|
int read_zline(FILE* fd, char* line, int line_len);
|
||
|
|
void raw_mode(int tty, int on);
|
||
|
|
int setup_term(void);
|
||
|
|
-void display_screen(const byte* img, int imglen, int screen_width, int screen_height, int move_cursor);
|
||
|
|
+void display_screen(const byte* img, int imglen, int screen_width, int screen_height);
|
||
|
|
+void display_screen_debug(const byte* img, int imglen, int screen_width, int screen_height);
|
||
|
|
const char* get_envp(char* const* envp, const char* name);
|
||
|
|
int run_interactive(char* const* argv, int argc, char* const* envp);
|
||
|
|
int run_testfile(const char* testfile, const char* less);
|
||
|
|
diff --git a/lesstest/pipeline.c b/lesstest/pipeline.c
|
||
|
|
index e988e4d..3dcace3 100644
|
||
|
|
--- a/lesstest/pipeline.c
|
||
|
|
+++ b/lesstest/pipeline.c
|
||
|
|
@@ -68,8 +68,6 @@ static void become_child_screen(char* lt_screen, int screen_width, int screen_he
|
||
|
|
}
|
||
|
|
if (1)
|
||
|
|
screen_argv[screen_argc++] = "-q";
|
||
|
|
- if (verbose)
|
||
|
|
- screen_argv[screen_argc++] = "-v";
|
||
|
|
screen_argv[screen_argc] = NULL;
|
||
|
|
if (verbose) print_strings("screen argv", screen_argv);
|
||
|
|
char* const screen_envp[] = { NULL };
|
||
|
|
diff --git a/lesstest/run.c b/lesstest/run.c
|
||
|
|
index fa7ace0..45b3865 100644
|
||
|
|
--- a/lesstest/run.c
|
||
|
|
+++ b/lesstest/run.c
|
||
|
|
@@ -42,7 +42,7 @@ static void set_intr_handler(int set) {
|
||
|
|
}
|
||
|
|
|
||
|
|
static void send_char(LessPipeline* pipeline, wchar ch) {
|
||
|
|
- if (verbose) fprintf(stderr, "send %lx\n", ch);
|
||
|
|
+ if (verbose) fprintf(stderr, "lt.send %lx\n", ch);
|
||
|
|
byte cbuf[UNICODE_MAX_BYTES];
|
||
|
|
byte* cp = cbuf;
|
||
|
|
store_wchar(&cp, ch);
|
||
|
|
@@ -50,7 +50,7 @@ static void send_char(LessPipeline* pipeline, wchar ch) {
|
||
|
|
}
|
||
|
|
|
||
|
|
static int read_screen(LessPipeline* pipeline, byte* buf, int buflen) {
|
||
|
|
- if (verbose) fprintf(stderr, "gen: read screen\n");
|
||
|
|
+ if (verbose) fprintf(stderr, "lt.gen: read screen\n");
|
||
|
|
send_char(pipeline, LESS_DUMP_CHAR);
|
||
|
|
int rn = 0;
|
||
|
|
for (; rn <= buflen; ++rn) {
|
||
|
|
@@ -67,7 +67,7 @@ static void read_and_display_screen(LessPipeline* pipeline) {
|
||
|
|
int rn = read_screen(pipeline, rbuf, sizeof(rbuf));
|
||
|
|
if (rn == 0) return;
|
||
|
|
printf("%s", terminfo.clear_screen);
|
||
|
|
- display_screen(rbuf, rn, pipeline->screen_width, pipeline->screen_height, 1);
|
||
|
|
+ display_screen(rbuf, rn, pipeline->screen_width, pipeline->screen_height);
|
||
|
|
log_screen(rbuf, rn);
|
||
|
|
}
|
||
|
|
|
||
|
|
@@ -77,10 +77,10 @@ static int curr_screen_match(LessPipeline* pipeline, const byte* img, int imglen
|
||
|
|
if (currlen == imglen && memcmp(img, curr, imglen) == 0)
|
||
|
|
return 1;
|
||
|
|
if (details) {
|
||
|
|
- fprintf(stderr, "MISMATCH: expect:\n");
|
||
|
|
- display_screen(img, imglen, pipeline->screen_width, pipeline->screen_height, 0);
|
||
|
|
- fprintf(stderr, "got:\n");
|
||
|
|
- display_screen(curr, currlen, pipeline->screen_width, pipeline->screen_height, 0);
|
||
|
|
+ fprintf(stderr, "lt: mismatch: expect:\n");
|
||
|
|
+ display_screen_debug(img, imglen, pipeline->screen_width, pipeline->screen_height);
|
||
|
|
+ fprintf(stderr, "lt: got:\n");
|
||
|
|
+ display_screen_debug(curr, currlen, pipeline->screen_width, pipeline->screen_height);
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
@@ -152,6 +152,7 @@ int run_test(TestSetup* setup, FILE* testfd) {
|
||
|
|
case '=':
|
||
|
|
if (!curr_screen_match(pipeline, (byte*)line+1, line_len-1)) {
|
||
|
|
ok = 0;
|
||
|
|
+ less_quit = 1;
|
||
|
|
fprintf(stderr, "FAIL %s on cmd #%d (%c %lx)\n",
|
||
|
|
setup_name, cmds, pr_ascii(last_char), last_char);
|
||
|
|
}
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|