git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] diff-highlight: add some tests.

From
EWEric Wong <e@80x24.org>
Date
Aug 10, 2016, 08:56 UTC
Message-ID
<20160810085635.GA1672@starla>
In-Reply-To
<20160730151149.15980-2-henderson.bj@gmail.com>
Brian Henderson <henderson.bj@gmail.com> wrote:
Hi Brian,

A few minor portability/style nits below, but contrib/ probably (still?) has laxer rules than the rest of git...

I think we still require Signed-off-by lines in contrib, though...

Show 18 quoted lines
> +++ b/contrib/diff-highlight/t/Makefile
> @@ -0,0 +1,19 @@
> +-include ../../../config.mak.autogen
> +-include ../../../config.mak
> +
> +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
> +
> +all: test
> +test: $(T)
> +
> +.PHONY: help clean all test $(T)
> +
> +help:
> +	@echo 'Run "$(MAKE) test" to launch test scripts'
> +	@echo 'Run "$(MAKE) clean" to remove trash folders'
> +
> +$(T):
> +	@echo "*** $@ ***"; sh $@ $(GIT_TEST_OPTS)
Probably:
	@echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
like we do in t/Makefile in case we need to override 'sh'.
Show 12 quoted lines
> +
> +clean:
> +	$(RM) -r 'trash directory'.*
> diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> new file mode 100644
> index 0000000..ca7605f
> --- /dev/null
> +++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> @@ -0,0 +1,63 @@
> +#!/bin/sh
> +#
> +# Copyright (C) 2016

IANAL, but I think your name (or who you represent) needs to be in the copyright.

Show 5 quoted lines
> +
> +test_description='Test diff-highlight'
> +
> +. ./test-diff-highlight.sh
> +. $TEST_DIRECTORY/test-lib.sh

TEST_DIRECTORY ought to be quoted since it could contain shell-unfriendly chars (we intentionally name 'trash directory' this way to trigger errors).

Show 5 quoted lines
> +
> +# PERL is required, but assumed to be present, although not necessarily modern
> +# some tests require 5.8
> +
> +test_expect_success 'diff-highlight highlightes the beginning of a line' '
You can declare a prereq for PERL::
	test_expect_success PERL 'name' 'true'
And spelling: "highlights" (there's other instances of this, too)
> +  dh_test \
> +    "aaa\nbbb\nccc\n" \
> +    "aaa\n0bb\nccc\n" \
> +"
We use tabs for shell indentation.
<snip>
Show 15 quoted lines
> diff --git a/contrib/diff-highlight/t/test-diff-highlight.sh b/contrib/diff-highlight/t/test-diff-highlight.sh
> new file mode 100644
> index 0000000..9b26271
> --- /dev/null
> +++ b/contrib/diff-highlight/t/test-diff-highlight.sh
> @@ -0,0 +1,69 @@
> +#!/bin/sh
> +#
> +# Copyright (C) 2016
> +
> +CURR_DIR=$(pwd)
> +TEST_OUTPUT_DIRECTORY=$(pwd)
> +TEST_DIRECTORY="$CURR_DIR"/../../../t
> +cmd=diff-highlight
> +CMD="$CURR_DIR"/../$cmd
Same comments as above on quoting pathnames and empty copyright.
Show 13 quoted lines
> +
> +CW="\033[7m"
> +CR="\033[27m"
> +
> +export TEST_OUTPUT_DIRECTORY TEST_DIRECTORY CW CR
> +
> +dh_test() {
> +  dh_diff_test "$@"
> +  dh_commit_test "$@"
> +}
> +
> +dh_diff_test() {
> +  local a="$1" b="$2"

"local" is not a portable construct. It's common for Debian/Ubuntu systems to use dash as /bin/sh instead of bash; (dash is faster, and mostly sticks to POSIX)

The "devscripts" package in Debian/Ubuntu-based systems has a handy "checkbashisms" tool for checking portability of shell scripts.

Show 7 quoted lines
> +
> +  printf "$a" > file
> +  git add file
> +
> +  printf "$b" > file
> +
> +  git diff file > diff.raw

Commands should be '&&'-chained here since any of them could fail ("git add"/printf/etc could run out of space or fail on disk errors)

Also, our redirect style is: command >file without a space between '>' and destination.

See Documentation/CodingGuidelines for more details. Unfortunately, the reasoning is not explained for '>NOSPACE' and I'm not sure exactly why, either...

> +  if test "$#" = 3

Better to use -eq for numeric comparisons: test $# -eq 3 Quoting $# doesn't seem necessary unless your shell is hopelessly buggy :)

> +  then
> +    # remove last newline
> +    head -n5 diff.raw | head -c -1 > diff.act

"head -c" isn't portable, fortunately Jeff hoisted it out for use as test_copy_bytes in commit 48860819e8026 https://public-inbox.org/git/20160630090753.GA17463@sigill.intra.peff.net/

Show 6 quoted lines
> +    printf "$3" >> diff.act
> +  else
> +    cat diff.raw > diff.act
> +  fi
> +
> +  < diff.raw $CMD > diff.exp
$CMD probably needs to be quoted.  However, by the time I got
here I had to ask myself:  What is $CMD again?
A: Oh, look up at the top!
*shrug*  My attention span is tiny and my fonts are gigantic.
Perhaps using:
	DIFF_HIGHLIGHT="$CURR_DIR"/../diff-highlight
Would be more-readable?
> +
> +  diff diff.exp diff.act

Maybe use test_cmp to avoid depending external diff. (or "git diff -b --no-index" in your later test)

Same comments for the rest of the series, I think.

Typically, we expect a reroll in a few days, and I guess there's no rush (so you can squash your comment patch in addressing Junio's concern into 3/3).

Thanks.
Previous: Brian HendersonNext: Brian Henderson
Message 7 of 24 in “diff-highlight: add support for git log --graph output.”
  1. 0/3 diff-highlight: add support for git log --graph output.Brian Henderson, Jul 30, 2016
  2. 3/3 diff-highlight: add support for --graph output.Brian Henderson, Jul 30, 2016
  3. Junio C HamanoAug 1, 2016
  4. diff-highlight: Add comment for our assumption about --graph output.Brian Henderson, Aug 4, 2016
  5. 2/3 diff-highlight: add failing test for handling --graph output.Brian Henderson, Jul 30, 2016
  6. 1/3 diff-highlight: add some tests.Brian Henderson, Jul 30, 2016
  7. Eric WongAug 10, 2016
  8. Brian HendersonAug 15, 2016
  9. Junio C HamanoAug 15, 2016
  10. 0/3 diff-highlight: add support for git log --graph output.Brian Henderson, Aug 17, 2016
  11. 2/3 diff-highlight: add failing test for handling --graph output.Brian Henderson, Aug 17, 2016
  12. Junio C HamanoAug 17, 2016
  13. 1/3 diff-highlight: add some tests.Brian Henderson, Aug 17, 2016
  14. Junio C HamanoAug 17, 2016
  15. Brian HendersonAug 19, 2016
  16. Jeff KingAug 19, 2016
  17. Brian HendersonAug 19, 2016
  18. 3/3 diff-highlight: add support for --graph output.Brian Henderson, Aug 17, 2016
  19. Jeff KingAug 19, 2016
  20. Eric WongAug 19, 2016
  21. Jeff KingAug 19, 2016
  22. Lars SchneiderAug 15, 2016
  23. Junio C HamanoAug 16, 2016
  24. Lars SchneiderAug 24, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.