{"thread":{"id":"10424","subject":"[PATCH] Add some fancy colors in the test library when terminal supports it.","startedAt":"2007-10-22T08:13:41Z","lastAt":"2007-10-23T08:13:27Z","messageCount":10,"participants":["Pierre Habouzit","Johannes Sixt","Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"56839","messageId":"20071022081341.GC32763@artemis.corp","threadId":"10424","inReplyTo":null,"subject":"[PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-10-22T08:13:41Z","receivedAt":"2007-10-22T08:13:41Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n\nMaybe this is just me, but I don't find the output of the test-suite\neasy to watch while scrolling. This puts some colors in proper places.\n\n  * end-test summaries are in green or red depending on the sucess of\n    the tests.\n  * errors are in red.\n  * skipped tests and other things that tests `say` are in brown (now\n    you can _see_ that your testsuite skips some tests on purpose, I\n    only noticed recently that I missed part of the environment for\n    proper testing).\n\nI'm not 100% sure the test to see if terminal supports color is correct, and\npeople using emacs shell buffer or alike tools may have better ideas on how to\nmake it.\n\nand yes, I know that it \"depends\" upon tput, but if tput isn't available, the\n    [ \"x$TERM\" != \"xdumb\" ] && tput hpa 60 >/dev/null 2>&1 && tput setaf 1 >/dev/null 2>&1\nexpression will fail, and color will be disabled.\n\n t/test-lib.sh |   32 ++++++++++++++++++++++----------\n 1 files changed, 22 insertions(+), 10 deletions(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex cc1253c..c6521c0 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -59,14 +59,24 @@ esac\n # '\n # . ./test-lib.sh\n \n+[ \"x$TERM\" != \"xdumb\" ] && tput hpa 60 >/dev/null 2>&1 && tput setaf 1 >/dev/null 2>&1\n+nocolor=$?\n+\n+say_color () {\n+\t[ \"$nocolor\" = 0 ] &&  [ \"$1\" != '-1' ] && tput setaf \"$1\"\n+\tshift\n+\techo \"* $*\"\n+\ttput op\n+}\n+\n error () {\n-\techo \"* error: $*\"\n+\tsay_color 9 \"* error: $*\"\n \ttrap - exit\n \texit 1\n }\n \n say () {\n-\techo \"* $*\"\n+\tsay_color 3 \"$*\"\n }\n \n test \"${test_description}\" != \"\" ||\n@@ -84,6 +94,8 @@ do\n \t\texit 0 ;;\n \t-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)\n \t\tverbose=t; shift ;;\n+\t--no-color)\n+\t    nocolor=1; shift ;;\n \t--no-python)\n \t\t# noop now...\n \t\tshift ;;\n@@ -122,13 +134,13 @@ test_tick () {\n \n test_ok_ () {\n \ttest_count=$(expr \"$test_count\" + 1)\n-\tsay \"  ok $test_count: $@\"\n+\tsay_color -1 \"  ok $test_count: $@\"\n }\n \n test_failure_ () {\n \ttest_count=$(expr \"$test_count\" + 1)\n \ttest_failure=$(expr \"$test_failure\" + 1);\n-\tsay \"FAIL $test_count: $1\"\n+\tsay_color 9 \"FAIL $test_count: $1\"\n \tshift\n \techo \"$@\" | sed -e 's/^/\t/'\n \ttest \"$immediate\" = \"\" || { trap - exit; exit 1; }\n@@ -158,9 +170,9 @@ test_skip () {\n \tdone\n \tcase \"$to_skip\" in\n \tt)\n-\t\tsay >&3 \"skipping test: $@\"\n+\t\tsay_color 10 >&3 \"skipping test: $@\"\n \t\ttest_count=$(expr \"$test_count\" + 1)\n-\t\tsay \"skip $test_count: $1\"\n+\t\tsay_color 10 \"skip $test_count: $1\"\n \t\t: true\n \t\t;;\n \t*)\n@@ -247,11 +259,11 @@ test_done () {\n \t\t# The Makefile provided will clean this test area so\n \t\t# we will leave things as they are.\n \n-\t\tsay \"passed all $test_count test(s)\"\n+\t\tsay_color 2 \"passed all $test_count test(s)\"\n \t\texit 0 ;;\n \n \t*)\n-\t\tsay \"failed $test_failure among $test_count test(s)\"\n+\t\tsay_color 9 \"failed $test_failure among $test_count test(s)\"\n \t\texit 1 ;;\n \n \tesac\n@@ -296,8 +308,8 @@ do\n \tdone\n \tcase \"$to_skip\" in\n \tt)\n-\t\tsay >&3 \"skipping test $this_test altogether\"\n-\t\tsay \"skip all tests in $this_test\"\n+\t\tsay_color 10 >&3 \"skipping test $this_test altogether\"\n+\t\tsay_color 10 \"skip all tests in $this_test\"\n \t\ttest_done\n \tesac\n done\n-- \n1.5.3.4.1342.ge0cd-dirty\n"},{"id":"56843","messageId":"471C6510.8010300@viscovery.net","threadId":"10424","inReplyTo":"20071022081341.GC32763@artemis.corp","subject":"Re: [PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-10-22T08:53:36Z","receivedAt":"2007-10-22T08:53:36Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Pierre Habouzit schrieb:\n> Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n> ---\n> \n> Maybe this is just me, but I don't find the output of the test-suite\n> easy to watch while scrolling. This puts some colors in proper places.\n> \n>   * end-test summaries are in green or red depending on the sucess of\n>     the tests.\n>   * errors are in red.\n>   * skipped tests and other things that tests `say` are in brown (now\n>     you can _see_ that your testsuite skips some tests on purpose, I\n>     only noticed recently that I missed part of the environment for\n>     proper testing).\n> \n> I'm not 100% sure the test to see if terminal supports color is correct, and\n> people using emacs shell buffer or alike tools may have better ideas on how to\n> make it.\n> \n> and yes, I know that it \"depends\" upon tput, but if tput isn't available, the\n>     [ \"x$TERM\" != \"xdumb\" ] && tput hpa 60 >/dev/null 2>&1 && tput setaf 1 >/dev/null 2>&1\n> expression will fail, and color will be disabled.\n> \n>  t/test-lib.sh |   32 ++++++++++++++++++++++----------\n>  1 files changed, 22 insertions(+), 10 deletions(-)\n> \n> diff --git a/t/test-lib.sh b/t/test-lib.sh\n> index cc1253c..c6521c0 100644\n> --- a/t/test-lib.sh\n> +++ b/t/test-lib.sh\n> @@ -59,14 +59,24 @@ esac\n>  # '\n>  # . ./test-lib.sh\n>  \n> +[ \"x$TERM\" != \"xdumb\" ] && tput hpa 60 >/dev/null 2>&1 && tput setaf 1 >/dev/null 2>&1\n> +nocolor=$?\n\ntest \"x$TERM\" != \"xdumb\" &&\n\ttput hpa 60 >/dev/null 2>&1 &&\n\ttput setaf 1 >/dev/null 2>&1 &&\n\tcolor=t\n\nBTW, doesn't tput fail if stdout/stderr is not a terminal, like above?\n\n> +\n> +say_color () {\n> +\t[ \"$nocolor\" = 0 ] &&  [ \"$1\" != '-1' ] && tput setaf \"$1\"\n> +\tshift\n> +\techo \"* $*\"\n> +\ttput op\n> +}\n\nWhat if tput is not available, like on Windows? How about this (at the end \nof the file, so it can obey --no-color):\n\nif test \"$color\"; then\n\tsay_color () {\n\t\ttest \"$1\" != '-1' && tput setaf \"$1\"\n\t\tshift\n\t\techo \"* $*\"\n\t\ttput op\n\t}\nelse\n\tsay_color() {\n\t\tshift\n\t\techo \"* $*\"\n\t}\nfi\n\n> +\t--no-color)\n> +\t    nocolor=1; shift ;;\n\n\t    color=; shift ;;\n\n-- Hannes \"We don't need no double negation\"\n"},{"id":"56859","messageId":"20071022112401.GE32763@artemis.corp","threadId":"10424","inReplyTo":"471C6510.8010300@viscovery.net","subject":"Re: [PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-10-22T11:24:01Z","receivedAt":"2007-10-22T11:24:01Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Mon, Oct 22, 2007 at 08:53:36AM +0000, Johannes Sixt wrote:\n> Pierre Habouzit schrieb:\n> >Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n> >---\n> >Maybe this is just me, but I don't find the output of the test-suite\n> >easy to watch while scrolling. This puts some colors in proper places.\n> >  * end-test summaries are in green or red depending on the sucess of\n> >    the tests.\n> >  * errors are in red.\n> >  * skipped tests and other things that tests `say` are in brown (now\n> >    you can _see_ that your testsuite skips some tests on purpose, I\n> >    only noticed recently that I missed part of the environment for\n> >    proper testing).\n> >I'm not 100% sure the test to see if terminal supports color is correct, \n> >and\n> >people using emacs shell buffer or alike tools may have better ideas on \n> >how to\n> >make it.\n> >and yes, I know that it \"depends\" upon tput, but if tput isn't \n> >available, the\n> >    [ \"x$TERM\" != \"xdumb\" ] && tput hpa 60 >/dev/null 2>&1 && tput setaf \n> >1 >/dev/null 2>&1\n> >expression will fail, and color will be disabled.\n> > t/test-lib.sh |   32 ++++++++++++++++++++++----------\n> > 1 files changed, 22 insertions(+), 10 deletions(-)\n> >diff --git a/t/test-lib.sh b/t/test-lib.sh\n> >index cc1253c..c6521c0 100644\n> >--- a/t/test-lib.sh\n> >+++ b/t/test-lib.sh\n> >@@ -59,14 +59,24 @@ esac\n> > # '\n> > # . ./test-lib.sh\n> > +[ \"x$TERM\" != \"xdumb\" ] && tput hpa 60 >/dev/null 2>&1 && tput setaf 1 \n> >>/dev/null 2>&1\n> >+nocolor=$?\n> \n> test \"x$TERM\" != \"xdumb\" &&\n> \ttput hpa 60 >/dev/null 2>&1 &&\n> \ttput setaf 1 >/dev/null 2>&1 &&\n> \tcolor=t\n> \n> BTW, doesn't tput fail if stdout/stderr is not a terminal, like above?\n> \n> >+\n> >+say_color () {\n> >+\t[ \"$nocolor\" = 0 ] &&  [ \"$1\" != '-1' ] && tput setaf \"$1\"\n> >+\tshift\n> >+\techo \"* $*\"\n> >+\ttput op\n> >+}\n> \n> What if tput is not available, like on Windows? How about this (at the \n> end of the file, so it can obey --no-color):\n\n  I answered to it already in my first mail: if tput isn't available,\nthe command fails, and $? is non 0. and nocolor is set. Or color isn't\nset to 't' for your proposal.\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"56861","messageId":"471C8B02.6080202@viscovery.net","threadId":"10424","inReplyTo":"20071022112401.GE32763@artemis.corp","subject":"Re: [PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-10-22T11:35:30Z","receivedAt":"2007-10-22T11:35:30Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Pierre Habouzit schrieb:\n> On Mon, Oct 22, 2007 at 08:53:36AM +0000, Johannes Sixt wrote:\n>> Pierre Habouzit schrieb:\n>>> +say_color () {\n>>> +\t[ \"$nocolor\" = 0 ] &&  [ \"$1\" != '-1' ] && tput setaf \"$1\"\n>>> +\tshift\n>>> +\techo \"* $*\"\n>>> +\ttput op\n>>> +}\n>> What if tput is not available, like on Windows? How about this (at the \n>> end of the file, so it can obey --no-color):\n> \n>   I answered to it already in my first mail: if tput isn't available,\n> the command fails, and $? is non 0. and nocolor is set. Or color isn't\n> set to 't' for your proposal.\n\nI was too terse, sorry. I wanted to point out that if tput is not available, \nthe second invocation will leave \"tput: command not found\" behind on stderr. \nTherefore, I proposed to make the definition of say_color() different \ndepending on whether $color is set or not. Then you don't need to test for \n$color twice inside the function.\n\n-- Hannes\n"},{"id":"56864","messageId":"20071022121106.GA7151@artemis.corp","threadId":"10424","inReplyTo":"471C8B02.6080202@viscovery.net","subject":"Re: [PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-10-22T12:11:06Z","receivedAt":"2007-10-22T12:11:06Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Mon, Oct 22, 2007 at 11:35:30AM +0000, Johannes Sixt wrote:\n> Pierre Habouzit schrieb:\n> >On Mon, Oct 22, 2007 at 08:53:36AM +0000, Johannes Sixt wrote:\n> >>Pierre Habouzit schrieb:\n> >>>+say_color () {\n> >>>+\t[ \"$nocolor\" = 0 ] &&  [ \"$1\" != '-1' ] && tput setaf \"$1\"\n> >>>+\tshift\n> >>>+\techo \"* $*\"\n> >>>+\ttput op\n> >>>+}\n> >>What if tput is not available, like on Windows? How about this (at the \n> >>end of the file, so it can obey --no-color):\n> >  I answered to it already in my first mail: if tput isn't available,\n> >the command fails, and $? is non 0. and nocolor is set. Or color isn't\n> >set to 't' for your proposal.\n> \n> I was too terse, sorry. I wanted to point out that if tput is not \n> available, the second invocation will leave \"tput: command not found\" \n> behind on stderr. Therefore, I proposed to make the definition of \n> say_color() different depending on whether $color is set or not. Then you \n> don't need to test for $color twice inside the function.\n\n  Right we can do that. I'll try to rework the patch. and no it\nshouldn't leave tput: command not found as I 2>/dev/null and I think the\nshell doesn't print that in that case. At least my zsh doesn't.\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"56865","messageId":"471C950E.40702@viscovery.net","threadId":"10424","inReplyTo":"20071022121106.GA7151@artemis.corp","subject":"Re: [PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-10-22T12:18:22Z","receivedAt":"2007-10-22T12:18:22Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Pierre Habouzit schrieb:\n> On Mon, Oct 22, 2007 at 11:35:30AM +0000, Johannes Sixt wrote:\n>> Pierre Habouzit schrieb:\n>>> On Mon, Oct 22, 2007 at 08:53:36AM +0000, Johannes Sixt wrote:\n>>>> Pierre Habouzit schrieb:\n>>>>> +say_color () {\n>>>>> +\t[ \"$nocolor\" = 0 ] &&  [ \"$1\" != '-1' ] && tput setaf \"$1\"\n>>>>> +\tshift\n>>>>> +\techo \"* $*\"\n>>>>> +\ttput op\n        ^^^^^^^^\nI am talking about this line.\n\n>>>>> +}\n>> I wanted to point out that if tput is not \n>> available, the second invocation will leave \"tput: command not found\" \n>> behind on stderr. Therefore, I proposed to make the definition of \n>> say_color() different depending on whether $color is set or not. Then you \n>> don't need to test for $color twice inside the function.\n> \n>   Right we can do that. I'll try to rework the patch. and no it\n> shouldn't leave tput: command not found as I 2>/dev/null and I think the\n> shell doesn't print that in that case. At least my zsh doesn't.\n\nThere is no 2>/dev/null. Am I missing something?\n\n-- Hannes\n"},{"id":"56875","messageId":"20071022134541.GA9776@artemis.corp","threadId":"10424","inReplyTo":"471C950E.40702@viscovery.net","subject":"Re: [PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-10-22T13:45:41Z","receivedAt":"2007-10-22T13:45:41Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Mon, Oct 22, 2007 at 12:18:22PM +0000, Johannes Sixt wrote:\n> Pierre Habouzit schrieb:\n> >On Mon, Oct 22, 2007 at 11:35:30AM +0000, Johannes Sixt wrote:\n> >>Pierre Habouzit schrieb:\n> >>>On Mon, Oct 22, 2007 at 08:53:36AM +0000, Johannes Sixt wrote:\n> >>>>Pierre Habouzit schrieb:\n> >>>>>+say_color () {\n> >>>>>+\t[ \"$nocolor\" = 0 ] &&  [ \"$1\" != '-1' ] && tput setaf \"$1\"\n> >>>>>+\tshift\n> >>>>>+\techo \"* $*\"\n> >>>>>+\ttput op\n>        ^^^^^^^^\n> I am talking about this line.\n\n  Oooh, good catch :P it should be guarded by a [ \"$nocolor\" = 0 ]\nindeed :P (or use your solution).\n\n> >>>>>+}\n> >>I wanted to point out that if tput is not available, the second \n> >>invocation will leave \"tput: command not found\" behind on stderr. \n> >>Therefore, I proposed to make the definition of say_color() different \n> >>depending on whether $color is set or not. Then you don't need to test \n> >>for $color twice inside the function.\n> >  Right we can do that. I'll try to rework the patch. and no it\n> >shouldn't leave tput: command not found as I 2>/dev/null and I think the\n> >shell doesn't print that in that case. At least my zsh doesn't.\n> \n> There is no 2>/dev/null. Am I missing something?\n\n  I was.\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"56946","messageId":"200710230608.15124.chriscool@tuxfamily.org","threadId":"10424","inReplyTo":"20071022081341.GC32763@artemis.corp","subject":"Re: [PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-10-23T04:08:14Z","receivedAt":"2007-10-23T04:08:14Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Hi Pierre,\n\nLe lundi 22 octobre 2007, Pierre Habouzit a écrit :\n> +\n> +say_color () {\n> +\t[ \"$nocolor\" = 0 ] &&  [ \"$1\" != '-1' ] && tput setaf \"$1\"\n> +\tshift\n> +\techo \"* $*\"\n> +\ttput op\n> +}\n> +\n>  error () {\n> -\techo \"* error: $*\"\n> +\tsay_color 9 \"* error: $*\"\n\nThis will print something like \"* * error: ...\" instead of \"* error: ...\"\n\nThe following should work:\n\n> +\tsay_color 9 \"error: $*\"\n\nBy the way, where do the 9 here and the 10 and the -1 below come from ?\n\"man 5 terminfo\" says that only values form 0 to 7 are portably defined.\nMaybe 9 is a bold red and 10 a bold green, or something like that, but it \ndoesn't seem to work on my konsole.\n\nAnyway, perhaps having:\n\n_red=1\n_green=2\n\nand then using \"say_color $_red stuff\" might be easier to understand and \nchange if needed.\n\nThanks for this good idea,\nChristian.\n"},{"id":"56982","messageId":"471D96B7.4080200@viscovery.net","threadId":"10424","inReplyTo":"200710230608.15124.chriscool@tuxfamily.org","subject":"Re: [PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-10-23T06:37:43Z","receivedAt":"2007-10-23T06:37:43Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Christian Couder schrieb:\n> Anyway, perhaps having:\n> \n> _red=1\n> _green=2\n> \n> and then using \"say_color $_red stuff\" might be easier to understand and \n> change if needed.\n\nGood idea. But then better name it by its purpose:\n\nfail=1\t# red\npass=2\t# green\n\n-- Hannes\n"},{"id":"56989","messageId":"20071023081327.GA21334@artemis.corp","threadId":"10424","inReplyTo":"200710230608.15124.chriscool@tuxfamily.org","subject":"Re: [PATCH] Add some fancy colors in the test library when terminal supports it.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-10-23T08:13:27Z","receivedAt":"2007-10-23T08:13:27Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Tue, Oct 23, 2007 at 04:08:14AM +0000, Christian Couder wrote:\n> Hi Pierre,\n> \n> Le lundi 22 octobre 2007, Pierre Habouzit a écrit :\n> > +\n> > +say_color () {\n> > +\t[ \"$nocolor\" = 0 ] &&  [ \"$1\" != '-1' ] && tput setaf \"$1\"\n> > +\tshift\n> > +\techo \"* $*\"\n> > +\ttput op\n> > +}\n> > +\n> >  error () {\n> > -\techo \"* error: $*\"\n> > +\tsay_color 9 \"* error: $*\"\n> \n> This will print something like \"* * error: ...\" instead of \"* error: ...\"\n> \n> The following should work:\n> \n> > +\tsay_color 9 \"error: $*\"\n> \n> By the way, where do the 9 here and the 10 and the -1 below come from ?\n> \"man 5 terminfo\" says that only values form 0 to 7 are portably defined.\n> Maybe 9 is a bold red and 10 a bold green, or something like that, but it \n> doesn't seem to work on my konsole.\n\nRight I should use tput setb or sth like that to ask for bold mode\nprobably.\n\n> Anyway, perhaps having:\n> \n> _red=1\n> _green=2\n> \n> and then using \"say_color $_red stuff\" might be easier to understand and \n> change if needed.\n\nAgreed.\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"}]}