mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-31 22:25:25 -04:00
tests: use color when printing on terminal
Colorize output of the tests when prinitng on terminal. Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Tested-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
parent
57050589b6
commit
0e1cc7aba7
1 changed files with 45 additions and 7 deletions
|
|
@ -52,6 +52,9 @@ int leak_check_enabled;
|
||||||
* WAYLAND_TEST_NO_TIMEOUTS evnironment var */
|
* WAYLAND_TEST_NO_TIMEOUTS evnironment var */
|
||||||
static int timeouts_enabled = 1;
|
static int timeouts_enabled = 1;
|
||||||
|
|
||||||
|
/* set to one if the output goes to the terminal */
|
||||||
|
static int is_atty = 0;
|
||||||
|
|
||||||
extern const struct test __start_test_section, __stop_test_section;
|
extern const struct test __start_test_section, __stop_test_section;
|
||||||
|
|
||||||
__attribute__ ((visibility("default"))) void *
|
__attribute__ ((visibility("default"))) void *
|
||||||
|
|
@ -224,6 +227,25 @@ rmdir_xdg_runtime_dir(void)
|
||||||
perror("Cleaning XDG_RUNTIME_DIR");
|
perror("Cleaning XDG_RUNTIME_DIR");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define RED "\033[31m"
|
||||||
|
#define GREEN "\033[32m"
|
||||||
|
|
||||||
|
static void
|
||||||
|
stderr_set_color(const char *color)
|
||||||
|
{
|
||||||
|
/* use colors only when the output is connected to
|
||||||
|
* the terminal */
|
||||||
|
if (is_atty)
|
||||||
|
fprintf(stderr, "%s", color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
stderr_reset_color(void)
|
||||||
|
{
|
||||||
|
if (is_atty)
|
||||||
|
fprintf(stderr, "\033[0m");
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const struct test *t;
|
const struct test *t;
|
||||||
|
|
@ -240,6 +262,9 @@ int main(int argc, char *argv[])
|
||||||
leak_check_enabled = !getenv("WAYLAND_TEST_NO_LEAK_CHECK");
|
leak_check_enabled = !getenv("WAYLAND_TEST_NO_LEAK_CHECK");
|
||||||
timeouts_enabled = !getenv("WAYLAND_TEST_NO_TIMEOUTS");
|
timeouts_enabled = !getenv("WAYLAND_TEST_NO_TIMEOUTS");
|
||||||
|
|
||||||
|
if (isatty(fileno(stderr)))
|
||||||
|
is_atty = 1;
|
||||||
|
|
||||||
if (argc == 2 && strcmp(argv[1], "--help") == 0)
|
if (argc == 2 && strcmp(argv[1], "--help") == 0)
|
||||||
usage(argv[0], EXIT_SUCCESS);
|
usage(argv[0], EXIT_SUCCESS);
|
||||||
|
|
||||||
|
|
@ -271,32 +296,45 @@ int main(int argc, char *argv[])
|
||||||
run_test(t); /* never returns */
|
run_test(t); /* never returns */
|
||||||
|
|
||||||
if (waitid(P_ALL, 0, &info, WEXITED)) {
|
if (waitid(P_ALL, 0, &info, WEXITED)) {
|
||||||
|
stderr_set_color(RED);
|
||||||
fprintf(stderr, "waitid failed: %m\n");
|
fprintf(stderr, "waitid failed: %m\n");
|
||||||
|
stderr_reset_color();
|
||||||
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "test \"%s\":\t", t->name);
|
|
||||||
switch (info.si_code) {
|
switch (info.si_code) {
|
||||||
case CLD_EXITED:
|
case CLD_EXITED:
|
||||||
fprintf(stderr, "exit status %d", info.si_status);
|
|
||||||
if (info.si_status == EXIT_SUCCESS)
|
if (info.si_status == EXIT_SUCCESS)
|
||||||
success = 1;
|
success = !t->must_fail;
|
||||||
|
else
|
||||||
|
success = t->must_fail;
|
||||||
|
|
||||||
|
stderr_set_color(success ? GREEN : RED);
|
||||||
|
fprintf(stderr, "test \"%s\":\texit status %d",
|
||||||
|
t->name, info.si_status);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case CLD_KILLED:
|
case CLD_KILLED:
|
||||||
case CLD_DUMPED:
|
case CLD_DUMPED:
|
||||||
fprintf(stderr, "signal %d", info.si_status);
|
if (t->must_fail)
|
||||||
|
success = 1;
|
||||||
|
|
||||||
|
stderr_set_color(success ? GREEN : RED);
|
||||||
|
fprintf(stderr, "test \"%s\":\tsignal %d",
|
||||||
|
t->name, info.si_status);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t->must_fail)
|
|
||||||
success = !success;
|
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
pass++;
|
pass++;
|
||||||
fprintf(stderr, ", pass.\n");
|
fprintf(stderr, ", pass.\n");
|
||||||
} else
|
} else
|
||||||
fprintf(stderr, ", fail.\n");
|
fprintf(stderr, ", fail.\n");
|
||||||
|
|
||||||
|
stderr_reset_color();
|
||||||
|
|
||||||
/* print separator line */
|
/* print separator line */
|
||||||
fprintf(stderr, "----------------------------------------\n");
|
fprintf(stderr, "----------------------------------------\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue