<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 28 November 2014 at 13:08, Pekka Paalanen <span dir="ltr"><<a href="mailto:ppaalanen@gmail.com" target="_blank">ppaalanen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, 21 Nov 2014 11:34:08 +0100<br>
Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>> wrote:<br>
<br>
> Colorize output of the tests when prinitng on terminal.<br>
><br>
> Signed-off-by: Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>><br>
> ---<br>
>  tests/test-runner.c | 52 +++++++++++++++++++++++++++++++++++++++++++++-------<br>
>  1 file changed, 45 insertions(+), 7 deletions(-)<br>
><br>
> diff --git a/tests/test-runner.c b/tests/test-runner.c<br>
> index 2ecb15a..3af78fe 100644<br>
> --- a/tests/test-runner.c<br>
> +++ b/tests/test-runner.c<br>
> @@ -53,6 +53,9 @@ int leak_check_enabled;<br>
>   * WAYLAND_TESTS_NO_TIMEOUTS evnironment var */<br>
>  static int timeouts_enabled = 1;<br>
><br>
> +/* set to one if the output goes to the terminal */<br>
> +static int is_atty = 0;<br>
> +<br>
>  extern const struct test __start_test_section, __stop_test_section;<br>
><br>
>  __attribute__ ((visibility("default"))) void *<br>
> @@ -258,6 +261,25 @@ is_debugger_attached(void)<br>
>       return rc;<br>
>  }<br>
><br>
> +#define RED  "\033[31m"<br>
> +#define GREEN        "\033[32m"<br>
> +<br>
> +static void<br>
> +stderr_set_color(const char *color)<br>
> +{<br>
> +     /* use colors only when the output is connected to<br>
> +      * the terminal */<br>
> +     if (is_atty)<br>
> +             fprintf(stderr, "%s", color);<br>
> +}<br>
> +<br>
> +static void<br>
> +stderr_reset_color(void)<br>
> +{<br>
> +     if (is_atty)<br>
> +             fprintf(stderr, "\033[0m");<br>
> +}<br>
> +<br>
>  int main(int argc, char *argv[])<br>
>  {<br>
>       const struct test *t;<br>
> @@ -279,6 +301,9 @@ int main(int argc, char *argv[])<br>
>               timeouts_enabled = !getenv("WAYLAND_TESTS_NO_TIMEOUTS");<br>
>       }<br>
><br>
> +     if (isatty(fileno(stderr)))<br>
> +             is_atty = 1;<br>
> +<br>
>       if (argc == 2 && strcmp(argv[1], "--help") == 0)<br>
>               usage(argv[0], EXIT_SUCCESS);<br>
><br>
> @@ -310,32 +335,45 @@ int main(int argc, char *argv[])<br>
>                       run_test(t); /* never returns */<br>
><br>
>               if (waitid(P_ALL, 0, &info, WEXITED)) {<br>
> +                     stderr_set_color(RED);<br>
>                       fprintf(stderr, "waitid failed: %m\n");<br>
> +                     stderr_reset_color();<br>
> +<br>
>                       abort();<br>
>               }<br>
><br>
> -             fprintf(stderr, "test \"%s\":\t", t->name);<br>
>               switch (info.si_code) {<br>
>               case CLD_EXITED:<br>
> -                     fprintf(stderr, "exit status %d", info.si_status);<br>
>                       if (info.si_status == EXIT_SUCCESS)<br>
> -                             success = 1;<br>
> +                             success = !t->must_fail;<br>
> +                     else<br>
> +                             success = t->must_fail;<br>
> +<br>
> +                     stderr_set_color(success ? GREEN : RED);<br>
> +                     fprintf(stderr, "test \"%s\":\texit status %d",<br>
> +                             t->name, info.si_status);<br>
> +<br>
>                       break;<br>
>               case CLD_KILLED:<br>
>               case CLD_DUMPED:<br>
> -                     fprintf(stderr, "signal %d", info.si_status);<br>
> +                     if (t->must_fail)<br>
> +                             success = 1;<br>
> +<br>
> +                     stderr_set_color(success ? GREEN : RED);<br>
> +                     fprintf(stderr, "test \"%s\":\tsignal %d",<br>
> +                             t->name, info.si_status);<br>
> +<br>
>                       break;<br>
>               }<br>
><br>
> -             if (t->must_fail)<br>
> -                     success = !success;<br>
> -<br>
>               if (success) {<br>
>                       pass++;<br>
>                       fprintf(stderr, ", pass.\n");<br>
>               } else<br>
>                       fprintf(stderr, ", fail.\n");<br>
><br>
> +             stderr_reset_color();<br>
> +<br>
>               /* print separator line */<br>
>               fprintf(stderr, "----------------------------------------\n");<br>
>       }<br>
<br>
</div></div>Hi,<br>
<br>
patch 1 pushed, but for some reason I couldn't get this patch 2 to<br>
apply. I tried with three-way merge, and also on top of some earlier<br>
revisions.<br>
<br></blockquote><div><br></div><div>Oh, yes, sorry.<br>I somehow tangled it with not-upstream changes. I'll resend the rebased patch.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks,<br>
pq<br>
</blockquote></div><br></div></div>