mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-03-23 19:00:46 +01:00
test: honor NO_COLOR and FORCE_COLOR for output colorization
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1124>
This commit is contained in:
parent
74617de48d
commit
6759a2f754
3 changed files with 26 additions and 10 deletions
|
|
@ -87,6 +87,7 @@ struct litest_runner {
|
|||
size_t max_forks;
|
||||
unsigned int timeout;
|
||||
bool verbose;
|
||||
bool use_colors;
|
||||
bool exit_on_fail;
|
||||
FILE *fp;
|
||||
|
||||
|
|
@ -743,11 +744,10 @@ litest_runner_log_test_result(struct litest_runner *runner, struct litest_runner
|
|||
(ms2s(t->times.end_millis - runner->times.start_millis)) % 60);
|
||||
|
||||
status = litest_runner_result_as_str(t->result);
|
||||
bool is_tty = isatty(fileno(runner->fp));
|
||||
fprintf(runner->fp, " status: %s%s%s\n",
|
||||
is_tty ? color : "",
|
||||
runner->use_colors ? color : "",
|
||||
&status[7], /* skip LITEST_ prefix */
|
||||
is_tty ? ANSI_NORMAL : "");
|
||||
runner->use_colors ? ANSI_NORMAL : "");
|
||||
|
||||
switch (t->result) {
|
||||
case LITEST_PASS:
|
||||
|
|
@ -830,6 +830,13 @@ litest_runner_set_verbose(struct litest_runner *runner,
|
|||
runner->verbose = verbose;
|
||||
}
|
||||
|
||||
void
|
||||
litest_runner_set_use_colors(struct litest_runner *runner,
|
||||
bool use_colors)
|
||||
{
|
||||
runner->use_colors = use_colors;
|
||||
}
|
||||
|
||||
void
|
||||
litest_runner_set_exit_on_fail(struct litest_runner *runner, bool do_exit)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ struct litest_runner *litest_runner_new(void);
|
|||
void litest_runner_set_num_parallel(struct litest_runner *runner, size_t num_jobs);
|
||||
void litest_runner_set_timeout(struct litest_runner *runner, unsigned int timeout);
|
||||
void litest_runner_set_verbose(struct litest_runner *runner, bool verbose);
|
||||
void litest_runner_set_use_colors(struct litest_runner *runner, bool use_colors);
|
||||
void litest_runner_set_exit_on_fail(struct litest_runner *runner, bool do_exit);
|
||||
void litest_runner_set_output_file(struct litest_runner *runner, FILE *fp);
|
||||
void litest_runner_add_test(struct litest_runner *runner,
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ static const char *filter_test = NULL;
|
|||
static const char *filter_device = NULL;
|
||||
static const char *filter_group = NULL;
|
||||
static int filter_rangeval = INT_MIN;
|
||||
static bool use_colors = false;
|
||||
|
||||
struct param_filter {
|
||||
char name[64];
|
||||
|
|
@ -153,7 +154,13 @@ _litest_checkpoint(const char *func,
|
|||
va_start(args, format);
|
||||
if (verbose) {
|
||||
vsnprintf(buf, sizeof(buf), format, args);
|
||||
fprintf(stderr, ANSI_BRIGHT_BLUE "%s():%d - " ANSI_BRIGHT_RED "%s" ANSI_NORMAL "\n", func, line, buf); \
|
||||
fprintf(stderr,
|
||||
"%s%s():%d - %s%s%s\n",
|
||||
use_colors ? ANSI_BRIGHT_BLUE : "",
|
||||
func, line,
|
||||
use_colors ? ANSI_BRIGHT_RED : "",
|
||||
buf,
|
||||
use_colors ? ANSI_NORMAL : "");
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
|
@ -1267,13 +1274,9 @@ litest_log_handler(struct libinput *libinput,
|
|||
const char *format,
|
||||
va_list args)
|
||||
{
|
||||
static int is_tty = -1;
|
||||
const char *priority = NULL;
|
||||
const char *color;
|
||||
|
||||
if (is_tty == -1)
|
||||
is_tty = isatty(STDERR_FILENO);
|
||||
|
||||
switch(pri) {
|
||||
case LIBINPUT_LOG_PRIORITY_INFO:
|
||||
priority = "info ";
|
||||
|
|
@ -1291,7 +1294,7 @@ litest_log_handler(struct libinput *libinput,
|
|||
abort();
|
||||
}
|
||||
|
||||
if (!is_tty)
|
||||
if (!use_colors)
|
||||
color = "";
|
||||
else if (strstr(format, "tap:"))
|
||||
color = ANSI_BLUE;
|
||||
|
|
@ -1312,7 +1315,7 @@ litest_log_handler(struct libinput *libinput,
|
|||
|
||||
fprintf(stderr, "%slitest %s ", color, priority);
|
||||
vfprintf(stderr, format, args);
|
||||
if (is_tty)
|
||||
if (use_colors)
|
||||
fprintf(stderr, ANSI_NORMAL);
|
||||
|
||||
if (strstr(format, "client bug: ") ||
|
||||
|
|
@ -1508,6 +1511,7 @@ litest_run_suite(struct list *suites, int njobs)
|
|||
if (outfile)
|
||||
litest_runner_set_output_file(runner, outfile);
|
||||
litest_runner_set_verbose(runner, verbose);
|
||||
litest_runner_set_use_colors(runner, use_colors);
|
||||
litest_runner_set_timeout(runner, 30);
|
||||
litest_runner_set_exit_on_fail(runner, exit_first);
|
||||
litest_runner_set_setup_funcs(runner, init_quirks, teardown_quirks, NULL);
|
||||
|
|
@ -5406,6 +5410,10 @@ main(int argc, char **argv)
|
|||
int rc;
|
||||
const char *meson_testthreads;
|
||||
|
||||
use_colors = getenv("FORCE_COLOR") || isatty(STDERR_FILENO);
|
||||
if (getenv("NO_COLOR"))
|
||||
use_colors = false;
|
||||
|
||||
in_debugger = is_debugger_attached();
|
||||
if (in_debugger) {
|
||||
jobs = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue