git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jon Seymour <jon.seymour@gmail.com>
To: git@vger.kernel.org
Cc: Jon Seymour <jon.seymour@gmail.com>
Subject: [PATCH 01/40] test-cleaner: automate whitespace cleaning of test scripts
Date: Sat,  6 Aug 2011 18:44:15 +1000	[thread overview]
Message-ID: <1312620294-18616-1-git-send-email-jon.seymour@gmail.com> (raw)
In-Reply-To: <1312620119-18369-1-git-send-email-jon.seymour@gmail.com>

This script allows the automated cleaning of test scripts.

Any whitespace fixups of a test script that do not effect the
exit status or output of the test are assumed to be safe
and are automatically committed.

To check the tests for whitespace issues, change into git's
test directory and run:

	test-cleaner.sh check-whitespace t*.sh

This will:

* write one line of the form:

	AUTO<tab><filename>

for each file that can be fixed automatically.

* write one line of the form:

	MANUAL<tab><filename>

for each file that will require manual intervention to fix.

To fix all the automatically correctable errors, run:

	./test-cleaner.sh fix-whitespace-auto t[0-9]*.sh

To generate commits for all the errors that require manual correction, run:

	./test-cleaner.sh fix-whitespace-manual t[0-9]*.sh

To clean a file without running tests or generating commits, run:

	./test-cleaner.sh clean-whitespace foobar.sh

clean-whitespace can be used with files that are not tests.

If no arguments are supplied, file arguments are read from stdin.

The filter itself can be run with:

	./test-cleaner.sh whitespace-filter < file > some-other-file

The resulting series of commits should rebased on both the git master
and pu branches. Commits that cause merge conflicts should be purged
from the series.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 t/test-cleaner.sh |  185 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 185 insertions(+), 0 deletions(-)
 create mode 100755 t/test-cleaner.sh

diff --git a/t/test-cleaner.sh b/t/test-cleaner.sh
new file mode 100755
index 0000000..9eb260b
--- /dev/null
+++ b/t/test-cleaner.sh
@@ -0,0 +1,185 @@
+#!/bin/sh
+
+USAGE="test-cleaner.sh
+	check-whitespace [<test-file> ...] - report on test files that need cleaning
+	fix_whitespace [<test-file> ...] - generate commits for files that need white space cleaning
+	fix-whitespace-auto [<test-file> ...] - generate commits for files that can be automatically cleaned
+	fix-whitespace-manual [<test-file> ...] - generate commits for files that need manual cleaning
+	clean-whitespace [<file> ...] - applying the cleaner to the specified file without running tests or generating commits
+"
+SUBDIRECTORY_OK=t
+. "$(git --exec-path)/git-sh-setup"
+require_clean_work_tree
+
+cleaner()
+{
+	expand -i | unexpand --first-only | sed "s/ *\$//"
+}
+
+clean_whitespace()
+{
+	rc=0
+	list_files "$@" | while read file
+	do
+		cleaner <"$file" >$$.tmp &&
+		cat $$.tmp >"$file" || rc=1
+		rm -f $$.tmp
+		test $rc = 0
+	done || exit $?
+}
+
+list_files()
+{
+	if test $# -gt 0
+	then
+		for arg in "$@"; do
+		    echo $arg
+		done
+	else
+		cat
+	fi
+}
+
+fix_whitespace_auto()
+{
+	check_whitespace "$@" 2>/dev/null | grep "^AUTO" | fix_whitespace
+}
+
+fix_whitespace_auto()
+{
+	check_whitespace "$@" 2>/dev/null | grep "^MANUAL" | fix_whitespace
+}
+
+fix_whitespace()
+{
+	rc=0
+	check_whitespace "$@" 2>/dev/null | while read status file
+	do
+		case "$status" in
+		AUTO)
+			if  clean_whitespace "$file" &&
+				git diff --exit-code -w -- "$file" >/dev/null
+				git add "$file" &&
+				git diff --exit-code -w HEAD -- "$file" >/dev/null
+			then
+				git commit -F - 1>&2 <<EOF
+whitespace: remediate $file
+
+This file was edited by applying:
+
+	 expand -i | unexpand --first-only | sed "s/ *\$//"
+
+to the file.
+
+No change to test outputs or status code was observed.
+
+Signed-off-by: $(git config user.name) <$(git config user.email)>
+EOF
+				echo "$status	$file"
+			else
+				rc=1
+			fi
+			rm -f $$.tmp
+			;;
+		MANUAL)
+			CLEANER_PREFIX=fixer.
+			check_whitespace "$file" >/dev/null 2>$$.err
+			if  clean_whitespace "$file" &&
+				git diff --exit-code -w -- "$file" >/dev/null
+				git add "$file" &&
+				git diff --exit-code -w HEAD -- "$file" >/dev/null
+			then
+				git commit -F - 1>&2 <<EOF
+FAILED: whitespace: remediate $file
+
+This file was edited by applying:
+
+	 expand -i | unexpand --first-only | sed "s/ *\$//"
+
+to the file.
+
+The following errors were observed:
+
+$(cat $$.err | sed "s/^/   /")
+
+These errors should be fixed before submitting this patch upstream.
+
+Signed-off-by: $(git config user.name) <$(git config user.email)>
+EOF
+				echo "$status	$file"
+			else
+				rc=1
+			fi
+			rm -f $$.tmp $$.err
+			;;
+		*)
+			die "fix-whitespace failed on $file with unexpected output"
+			;;
+		esac
+		test "$rc" = 0
+	done || rc=$?
+	test "$rc" = 0
+}
+
+check_whitespace()
+{
+	list_files "$@" | while read file
+	do
+		cleaner <"$file" >$$.${CLEANER_PREFIX}edited &&
+		cmp "$file" $$.${CLEANER_PREFIX}edited 1>/dev/null
+		rc=$?
+		if test $rc != 0
+		then
+			sh $file >$$.${CLEANER_PREFIX}before.output 2>$$.${CLEANER_PREFIX}before.error </dev/null
+			echo $? > $$.${CLEANER_PREFIX}before.exit
+			sh ./$$.${CLEANER_PREFIX}edited >$$.${CLEANER_PREFIX}after.output 2>$$.${CLEANER_PREFIX}after.error </dev/null
+			echo $? > $$.${CLEANER_PREFIX}after.exit
+
+			if cmp $$.${CLEANER_PREFIX}before.output $$.${CLEANER_PREFIX}after.output 1>/dev/null &&
+				cmp $$.${CLEANER_PREFIX}before.error $$.${CLEANER_PREFIX}after.error 1>/dev/null &&
+				cmp $$.${CLEANER_PREFIX}before.exit $$.${CLEANER_PREFIX}after.exit 1>/dev/null
+			then
+				echo "AUTO	$file"
+			else
+				echo "MANUAL	$file"
+				diff -u $$.${CLEANER_PREFIX}before.output $$.${CLEANER_PREFIX}after.output 1>&2
+				diff -u $$.${CLEANER_PREFIX}before.error $$.${CLEANER_PREFIX}after.error 1>&2
+				diff -u $$.${CLEANER_PREFIX}before.exit $$.${CLEANER_PREFIX}after.exit 1>&2
+			fi
+			looprc=1
+		fi
+		rm -f $$.${CLEANER_PREFIX}edited $$.${CLEANER_PREFIX}after.* $$.${CLEANER_PREFIX}before.*
+		test "$looprc" = 0
+	done
+}
+
+case $# in
+0)
+	usage ;;
+*)
+	cmd=$1
+	shift
+	case "$cmd" in
+	check-whitespace)
+		check_whitespace "$@"
+		;;
+	fix-whitespace)
+		fix_whitespace "$@"
+		;;
+	fix-whitespace-auto)
+		fix_whitespace_auto "$@"
+		;;
+	fix-whitespace-manual)
+		fix_whitespace_manual "$@"
+		;;
+	clean-whitespace)
+		clean_whitespace "$@"
+		;;
+	whitespace-filter)
+		cleaner
+		;;
+	*)
+		usage
+		;;
+	esac
+esac
-- 
1.7.6.362.gf0e6

  reply	other threads:[~2011-08-06  8:45 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-06  8:41 [PATCH 00/40] test whitespace - perform trivial whitespace clean ups of test scripts Jon Seymour
2011-08-06  8:44 ` Jon Seymour [this message]
2011-08-06  8:44   ` [PATCH 02/40] whitespace: remediate t1001-read-tree-m-2way.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 03/40] whitespace: remediate t1006-cat-file.sh Jon Seymour
2011-08-06  9:28     ` Jeff King
2011-08-06  9:47       ` Jon Seymour
2011-08-06 17:56       ` Junio C Hamano
2011-08-06 22:56         ` Jon Seymour
2011-08-06  8:44   ` [PATCH 04/40] whitespace: remediate t1300-repo-config.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 05/40] whitespace: remediate t1503-rev-parse-verify.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 06/40] whitespace: remediate t3040-subprojects-basic.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 07/40] whitespace: remediate t3200-branch.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 08/40] whitespace: remediate t3406-rebase-message.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 09/40] whitespace: remediate t4002-diff-basic.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 10/40] whitespace: remediate t4010-diff-pathspec.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 11/40] whitespace: remediate t5300-pack-object.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 12/40] whitespace: remediate t5301-sliding-window.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 13/40] whitespace: remediate t5302-pack-index.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 14/40] whitespace: remediate t5303-pack-corruption-resilience.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 15/40] whitespace: remediate t5400-send-pack.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 16/40] whitespace: remediate t5402-post-merge-hook.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 17/40] whitespace: remediate t5403-post-checkout-hook.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 18/40] whitespace: remediate t5510-fetch.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 19/40] whitespace: remediate t6002-rev-list-bisect.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 20/40] whitespace: remediate t6005-rev-list-count.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 21/40] whitespace: remediate t6030-bisect-porcelain.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 22/40] whitespace: remediate t7003-filter-branch.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 23/40] whitespace: remediate t7004-tag.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 24/40] whitespace: remediate t7403-submodule-sync.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 25/40] whitespace: remediate t7500-commit.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 26/40] whitespace: remediate t7810-grep.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 27/40] whitespace: remediate t9100-git-svn-basic.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 28/40] whitespace: remediate t9104-git-svn-follow-parent.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 29/40] whitespace: remediate t9107-git-svn-migrate.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 30/40] whitespace: remediate t9108-git-svn-glob.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 31/40] whitespace: remediate t9109-git-svn-multi-glob.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 32/40] whitespace: remediate t9110-git-svn-use-svm-props.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 33/40] whitespace: remediate t9118-git-svn-funky-branch-names.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 34/40] whitespace: remediate t9125-git-svn-multi-glob-branch-names.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 35/40] whitespace: remediate t9400-git-cvsserver-server.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 36/40] whitespace: remediate t9401-git-cvsserver-crlf.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 37/40] whitespace: remediate t9500-gitweb-standalone-no-errors.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 38/40] whitespace: remediate t9603-cvsimport-patchsets.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 39/40] whitespace: remediate t1000-read-tree-m-3way.sh Jon Seymour
2011-08-06  8:44   ` [PATCH 40/40] whitespace: remediate t6120-describe.sh Jon Seymour
2011-08-06  9:17   ` [PATCH 01/40] test-cleaner: automate whitespace cleaning of test scripts Jon Seymour
2011-08-06 15:48   ` [PATCH] whitespace: additional whitespace clean ups Jon Seymour
2011-08-06  9:03 ` [PATCH 00/40] test whitespace - perform trivial whitespace clean ups of test scripts Jon Seymour
2011-08-06  9:20 ` Jeff King
2011-08-06  9:36   ` Jon Seymour
2011-08-06  9:26 ` [PATCH replacement for 01/40] test-cleaner: automate whitespace cleaning " Jon Seymour

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1312620294-18616-1-git-send-email-jon.seymour@gmail.com \
    --to=jon.seymour@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).