All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Stefano Lattarini <stefano.lattarini@gmail.com>
Cc: Jon Seymour <jon.seymour@gmail.com>,
	git@vger.kernel.org, gitster@pobox.com, chriscool@tuxfamily.org,
	j6t@kdbg.org, jnareb@gmail.com
Subject: Re: test z$foo = zbar (and Re: [PATCH 1/3] bisect: relax requirement for a working tree.)
Date: Sun, 7 Aug 2011 09:10:35 -0500	[thread overview]
Message-ID: <20110807141035.GC10748@elie.gateway.2wire.net> (raw)
In-Reply-To: <201108071505.00762.stefano.lattarini@gmail.com>

Stefano Lattarini wrote:

>   $ /usr/xpg4/bin/sh -c 'test -z ")"'; echo $?
>   0

Yikes, thanks for pointing it out.  I wonder if we should introduce a
sane_test function, like this.

 empty_string () {
	case $* in
	?*)
		return 1 ;;
	*)
		return 0 ;;
	esac
 }

 # This is like "test", but:
 #  - it only implements a minimal subset of the functionality
 #  - it works around shells that cannot cope with parentheses as
 #    parameters to some operators, like ksh before 2008:
 #
 #	$ /usr/xpg4/bin/sh -c 'test -z ")"'; echo $?
 #	0
 sane_test () {
	# implied -n
	test "$#" = 0 && set -- -n ""
	test "$#" = 1 && set -- -n "$1"
	test "$#" = 2 && test "z$1" = z! && set -- -z "$2"

	test "$#" -le 4 || 

	case $# in
	2)
		case $1 in
		-z)
			empty_string "$2" ;;
		-n)
			! empty_string "$2" ;;
		-*)
			test "$@" ;;
		*)
			die "sane_test: unrecognized unary operator $1" ;;
		esac
		;;
	3)
		case $2 in
		= | !=)
			test "z$1" "$2" "z$3" ;;
		-eq | -lt | -gt | -le | -ge)
			test "$@" ;;
		*)
			die "sane_test: unrecognized binary operator $2" ;;
		esac
		;;
	4)
		test "z$1" = z! ||
		die "sane_test: unrecognized 4-argument test (not a negation)"

		shift
		! sane_test "$@"
		;;
	*)
		die 'sane_test: too many arguments'
		;;
	esac
 }

  reply	other threads:[~2011-08-07 14:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-07 10:50 [PATCH 0/3] bisect: add support for bisecting bare repositories Jon Seymour
2011-08-07 10:50 ` [PATCH 1/3] bisect: relax requirement for a working tree Jon Seymour
2011-08-07 12:41   ` test z$foo = zbar (and Re: [PATCH 1/3] bisect: relax requirement for a working tree.) Jonathan Nieder
2011-08-07 12:51     ` Jon Seymour
2011-08-07 13:04     ` Stefano Lattarini
2011-08-07 14:10       ` Jonathan Nieder [this message]
2011-08-07 14:40   ` [PATCH 1/3] bisect: relax requirement for a working tree Jon Seymour
2011-08-07 10:50 ` [PATCH 2/3] bisect: add tests for bisection on bare repositories Jon Seymour
2011-08-07 13:39   ` Jonathan Nieder
2011-08-07 14:39     ` Jon Seymour
2011-08-07 10:50 ` [PATCH 3/3] bisect: document that --no-checkout is the default for " Jon Seymour
2011-08-07 13:43   ` Jonathan Nieder

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=20110807141035.GC10748@elie.gateway.2wire.net \
    --to=jrnieder@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=jnareb@gmail.com \
    --cc=jon.seymour@gmail.com \
    --cc=stefano.lattarini@gmail.com \
    /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.