All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Henderson <henderson.bj@gmail.com>
To: git@vger.kernel.org
Cc: peff@peff.net, e@80x24.org, gitster@pobox.com,
	Brian Henderson <henderson.bj@gmail.com>
Subject: [PATCH v3 1/3] diff-highlight: add some tests.
Date: Fri, 19 Aug 2016 10:08:10 -0700	[thread overview]
Message-ID: <20160819170812.1676-2-henderson.bj@gmail.com> (raw)
In-Reply-To: <20160819170812.1676-1-henderson.bj@gmail.com>
In-Reply-To: <20160819145123.73hf7ffysy53l3kz@sigill.intra.peff.net>

Signed-off-by: Brian Henderson <henderson.bj@gmail.com>
---
 contrib/diff-highlight/Makefile                  |   5 +
 contrib/diff-highlight/t/Makefile                |  22 ++++
 contrib/diff-highlight/t/t9400-diff-highlight.sh | 150 +++++++++++++++++++++++
 3 files changed, 177 insertions(+)
 create mode 100644 contrib/diff-highlight/Makefile
 create mode 100644 contrib/diff-highlight/t/Makefile
 create mode 100755 contrib/diff-highlight/t/t9400-diff-highlight.sh

diff --git a/contrib/diff-highlight/Makefile b/contrib/diff-highlight/Makefile
new file mode 100644
index 0000000..9018724
--- /dev/null
+++ b/contrib/diff-highlight/Makefile
@@ -0,0 +1,5 @@
+# nothing to build
+all:
+
+test:
+	$(MAKE) -C t
diff --git a/contrib/diff-highlight/t/Makefile b/contrib/diff-highlight/t/Makefile
new file mode 100644
index 0000000..5ff5275
--- /dev/null
+++ b/contrib/diff-highlight/t/Makefile
@@ -0,0 +1,22 @@
+-include ../../../config.mak.autogen
+-include ../../../config.mak
+
+# copied from ../../t/Makefile
+SHELL_PATH ?= $(SHELL)
+SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+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 "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
+
+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 100755
index 0000000..6b8a461
--- /dev/null
+++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
@@ -0,0 +1,150 @@
+#!/bin/sh
+
+test_description='Test diff-highlight'
+
+CURR_DIR=$(pwd)
+TEST_OUTPUT_DIRECTORY=$(pwd)
+TEST_DIRECTORY="$CURR_DIR"/../../../t
+DIFF_HIGHLIGHT="$CURR_DIR"/../diff-highlight
+
+CW="\033[7m"	# white
+CR="\033[27m" # reset
+
+. "$TEST_DIRECTORY"/test-lib.sh
+
+if ! test_have_prereq PERL
+then
+	skip_all='skipping diff-highlight tests; perl not available'
+	test_done
+fi
+
+# dh_test is a test helper function which takes 1) some file data, 2) some
+# change of the file data, creates a diff and commit of the changes and passes
+# that through diff-highlight. The optional 3rd parameter is the expected
+# output of diff-highlight minus the diff/commit header. Don't include a 3rd
+# parameter if diff-highlight is stupposed to leave the input unmodified.
+dh_test () {
+	dh_diff_test "$@" &&
+	dh_commit_test "$@"
+}
+
+# see dh_test for usage
+dh_diff_test () {
+	a="$1" b="$2"
+
+	printf "$a" >file
+	git add file
+
+	printf "$b" >file
+	git diff file >diff.raw
+
+	if test $# -ge 3
+	then
+		# Add the diff header to the expected file
+		# we remove the trailing newline to make the test a little more readable
+		# this means $3 should start with a newline
+		head -n5 diff.raw | test_chomp_eof >diff.exp
+		printf "$3" >>diff.exp
+	else
+		cat diff.raw >diff.exp
+	fi
+
+	"$DIFF_HIGHLIGHT" <diff.raw >diff.act &&
+	# check that at least one of the files is not empty (any of the above
+	# commands could have failed resulting in an empty file)
+	test -s diff.act &&
+	test_cmp diff.exp diff.act
+}
+
+# see dh_test for usage
+dh_commit_test () {
+	a="$1" b="$2"
+
+	printf "$a" >file
+	git add file
+	git commit -m "Add a file" >/dev/null
+
+	printf "$b" >file
+	git commit -am "Update a file" >/dev/null
+
+	git show >commit.raw
+
+	if test $# -ge 3
+	then
+		# same as dh_diff_test
+		head -n11 commit.raw | test_chomp_eof >commit.exp
+		printf "$3" >>commit.exp
+	else
+		cat commit.raw >commit.exp
+	fi
+
+	"$DIFF_HIGHLIGHT" <commit.raw >commit.act &&
+	# check that at least one of the files is not empty (any of the above
+	# commands could have failed resulting in an empty file)
+	test -s commit.act &&
+	test_cmp commit.exp commit.act
+}
+
+test_chomp_eof () {
+	"$PERL_PATH" -pe 'chomp if eof'
+}
+
+test_expect_success 'diff-highlight highlights the beginning of a line' '
+	dh_test \
+		"aaa\nbbb\nccc\n" \
+		"aaa\n0bb\nccc\n" \
+"
+ aaa
+-${CW}b${CR}bb
++${CW}0${CR}bb
+ ccc
+"
+'
+
+test_expect_success 'diff-highlight highlights the end of a line' '
+	dh_test \
+		"aaa\nbbb\nccc\n" \
+		"aaa\nbb0\nccc\n" \
+"
+ aaa
+-bb${CW}b${CR}
++bb${CW}0${CR}
+ ccc
+"
+'
+
+test_expect_success 'diff-highlight highlights the middle of a line' '
+	dh_test \
+		"aaa\nbbb\nccc\n" \
+		"aaa\nb0b\nccc\n" \
+"
+ aaa
+-b${CW}b${CR}b
++b${CW}0${CR}b
+ ccc
+"
+'
+
+test_expect_success 'diff-highlight does not highlight whole line' '
+	dh_test \
+		"aaa\nbbb\nccc\n" \
+		"aaa\n000\nccc\n"
+'
+
+test_expect_failure 'diff-highlight highlights mismatched hunk size' '
+	dh_test \
+		"aaa\nbbb\n" \
+		"aaa\nb0b\nccc\n" \
+"
+ aaa
+-b${CW}b${CR}b
++b${CW}0${CR}b
++ccc
+"
+'
+
+# TODO add multi-byte test
+
+test_done
+
+# vim: set noet
-- 
2.9.0


  parent reply	other threads:[~2016-08-19 17:08 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-30 15:11 [PATCH 0/3] diff-highlight: add support for git log --graph output Brian Henderson
2016-07-30 15:11 ` [PATCH 1/3] diff-highlight: add some tests Brian Henderson
2016-08-10  8:56   ` Eric Wong
2016-08-15 16:20     ` Brian Henderson
2016-08-15 16:25       ` Junio C Hamano
2016-08-17 15:31     ` [PATCH v2 0/3] diff-highlight: add support for git log --graph output Brian Henderson
2016-08-19 21:19       ` Eric Wong
2016-08-19 21:23         ` Jeff King
2016-08-17 15:31     ` [PATCH v2 1/3] diff-highlight: add some tests Brian Henderson
2016-08-17 19:09       ` Junio C Hamano
2016-08-19 14:42         ` Brian Henderson
2016-08-19 14:51           ` Jeff King
2016-08-19 15:13             ` Brian Henderson
2016-08-19 17:08             ` [PATCH v3 0/3] diff-highlight: add support for git log --graph output Brian Henderson
2016-08-19 17:08             ` Brian Henderson [this message]
2016-08-19 18:10               ` [PATCH v3 1/3] diff-highlight: add some tests Junio C Hamano
2016-08-19 19:30                 ` Brian Henderson
2016-08-19 20:56                   ` Eric Wong
2016-08-19 20:18                 ` [PATCH] " Brian Henderson
2016-08-19 20:44                   ` Junio C Hamano
2016-08-19 21:04                     ` Jeff King
2016-08-19 22:31                       ` Junio C Hamano
2016-08-22 15:55                         ` Brian Henderson
2016-08-23  4:12                           ` Jeff King
2016-08-29 17:33                             ` [PATCH v4 0/3] diff-highlight: add support for --graph option Brian Henderson
2016-08-29 17:33                               ` [PATCH v4 1/3] diff-highlight: add some tests Brian Henderson
2016-08-29 17:33                               ` [PATCH v4 2/3] diff-highlight: add failing test for handling --graph output Brian Henderson
2016-08-29 17:33                               ` [PATCH v4 3/3] diff-highlight: add support for " Brian Henderson
2016-08-29 21:37                               ` [PATCH v4 0/3] diff-highlight: add support for --graph option Junio C Hamano
2016-08-30 14:07                                 ` Brian Henderson
2016-08-30 14:07                                   ` [PATCH v4 1/3] diff-highlight: add some tests Brian Henderson
2016-08-30 14:07                                   ` [PATCH v4 2/3] diff-highlight: add failing test for handling --graph output Brian Henderson
2016-08-30 14:07                                   ` [PATCH v4 3/3] diff-highlight: add support for " Brian Henderson
2016-08-31  5:02                                   ` [PATCH v4 0/3] diff-highlight: add support for --graph option Jeff King
2016-08-31  5:02                                     ` [PATCH 1/3] diff-highlight: ignore test cruft Jeff King
2016-08-31  5:03                                     ` [PATCH 2/3] diff-highlight: add multi-byte tests Jeff King
2016-08-31  5:05                                     ` [PATCH 3/3] diff-highlight: avoid highlighting combined diffs Jeff King
2016-08-30  8:11                               ` [PATCH v4 0/3] diff-highlight: add support for --graph option Jeff King
2016-08-19 21:05                   ` [PATCH] diff-highlight: add some tests Junio C Hamano
2016-08-19 17:08             ` [PATCH v3 2/3] diff-highlight: add failing test for handling --graph output Brian Henderson
2016-08-19 18:25               ` Junio C Hamano
2016-08-19 17:08             ` [PATCH v3 3/3] diff-highlight: add support for " Brian Henderson
2016-08-19 18:27               ` Junio C Hamano
2016-08-17 15:31     ` [PATCH v2 2/3] diff-highlight: add failing test for handling " Brian Henderson
2016-08-17 19:18       ` Junio C Hamano
2016-08-17 15:31     ` [PATCH v2 3/3] diff-highlight: add support for " Brian Henderson
2016-08-19 14:37       ` Jeff King
2016-08-15 16:40   ` [PATCH 1/3] diff-highlight: add some tests Lars Schneider
2016-08-16 20:48     ` Junio C Hamano
2016-08-24  9:38       ` Lars Schneider
2016-07-30 15:11 ` [PATCH 2/3] diff-highlight: add failing test for handling --graph output Brian Henderson
2016-07-30 15:11 ` [PATCH 3/3] diff-highlight: add support for " Brian Henderson
2016-08-01 17:16   ` Junio C Hamano
2016-08-04 15:02     ` [PATCH] diff-highlight: Add comment for our assumption about " Brian Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160819170812.1676-2-henderson.bj@gmail.com \
    --to=henderson.bj@gmail.com \
    --cc=e@80x24.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.