From: "Torsten Bögershausen" <tboegi@web.de>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: git@vger.kernel.org, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Jeff King" <peff@peff.net>, "René Scharfe" <l.s.r@web.de>
Subject: Re: [PATCH 01/10] t: add tool to translate hash-related values
Date: Wed, 6 Jun 2018 08:19:27 +0200 [thread overview]
Message-ID: <20180606061927.GA7098@tor.lan> (raw)
In-Reply-To: <20180604235229.279814-2-sandals@crustytoothpaste.net>
Some style nite inline
On Mon, Jun 04, 2018 at 11:52:20PM +0000, brian m. carlson wrote:
> Add a test function helper, test_translate, that will produce its first
> argument if the hash in use is SHA-1 and the second if its argument is
> NewHash. Implement a mode that can read entries from a file as well for
> reusability across tests.
>
> For the moment, use the length of the empty blob to determine the hash
> in use. In the future, we can change this code so that it can use the
> configuration and learn about the difference in input, output, and
> on-disk formats.
>
> Implement two basic lookup charts, one for common invalid or synthesized
> object IDs, and one for various facts about the hash function in use.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> t/test-lib-functions.sh | 40 ++++++++++++++++++++++++++++++++++++++++
> t/translate/hash-info | 9 +++++++++
> t/translate/oid | 15 +++++++++++++++
> 3 files changed, 64 insertions(+)
> create mode 100644 t/translate/hash-info
> create mode 100644 t/translate/oid
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 2b2181dca0..0e7067460b 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -1147,3 +1147,43 @@ depacketize () {
> }
> '
> }
> +
> +test_translate_f_ () {
> + local file="$TEST_DIRECTORY/translate/$2" &&
Unless I'm wrong, we don't use the "local" keyword ?
> + perl -e '
The bare "perl" is better spelled as "$PERL_PATH"
> + $delim = "\t";
> + ($hoidlen, $file, $arg) = @ARGV;
> + open($fh, "<", $file) or die "open: $!";
> + while (<$fh>) {
> + # Allow specifying other delimiters.
> + $delim = $1 if /^#!\sdelimiter\s(.)/;
> + next if /^#/;
> + @fields = split /$delim/, $_, 3;
> + if ($fields[0] eq $arg) {
> + print($hoidlen == 40 ? $fields[1] : $fields[2]);
> + last;
> + }
> + }
> + ' "$1" "$file" "$3"
> +}
> +
> +# Without -f, print the first argument if we are using SHA-1 and the second if
> +# we're using NewHash.
> +# With -f FILE ARG, read the (by default) tab-delimited file from
> +# t/translate/FILE, finding the first field matching ARG and printing either the
> +# second or third field depending on the hash in use.
> +test_translate () {
> + local hoidlen=$(printf "%s" "$EMPTY_BLOB" | wc -c) &&
> + if [ "$1" = "-f" ]
Style nit, please avoid [] and use test:
if test "$1" = "-f"
And more [] below
> + then
> + shift &&
> + test_translate_f_ "$hoidlen" "$@"
> + else
> + if [ "$hoidlen" -eq 40 ]
> + then
> + printf "%s" "$1"
> + else
> + printf "%s" "$2"
> + fi
> + fi
> +}
> diff --git a/t/translate/hash-info b/t/translate/hash-info
> new file mode 100644
> index 0000000000..36cbd9a8eb
> --- /dev/null
> +++ b/t/translate/hash-info
> @@ -0,0 +1,9 @@
> +# Various facts about the hash algorithm in use for easy access in tests.
> +#
> +# Several aliases are provided for easy recall.
> +rawsz 20 32
> +oidlen 20 32
> +hexsz 40 64
> +hexoidlen 40 64
> +zero 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
> +zero-oid 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
> diff --git a/t/translate/oid b/t/translate/oid
> new file mode 100644
> index 0000000000..8de0fd64af
> --- /dev/null
> +++ b/t/translate/oid
> @@ -0,0 +1,15 @@
> +# These are some common invalid and partial object IDs used in tests.
> +001 0000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000001
> +002 0000000000000000000000000000000000000002 0000000000000000000000000000000000000000000000000000000000000002
> +003 0000000000000000000000000000000000000003 0000000000000000000000000000000000000000000000000000000000000003
> +004 0000000000000000000000000000000000000004 0000000000000000000000000000000000000000000000000000000000000004
> +005 0000000000000000000000000000000000000005 0000000000000000000000000000000000000000000000000000000000000005
> +006 0000000000000000000000000000000000000006 0000000000000000000000000000000000000000000000000000000000000006
> +007 0000000000000000000000000000000000000007 0000000000000000000000000000000000000000000000000000000000000007
> +# All zeros or Fs missing one or two hex segments.
> +zero-1 000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000
> +zero-2 00000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000
> +ff-1 fffffffffffffffffffffffffffffffffffffff fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
> +ff-2 ffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
> +numeric 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789012345678901234567890123
> +deadbeef deadbeefdeadbeefdeadbeefdeadbeefdeadbeef deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef
next prev parent reply other threads:[~2018-06-06 6:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-04 23:52 [PATCH 00/10] Hash-independent tests (part 3) brian m. carlson
2018-06-04 23:52 ` [PATCH 01/10] t: add tool to translate hash-related values brian m. carlson
2018-06-06 6:19 ` Torsten Bögershausen [this message]
2018-06-06 20:58 ` Jeff King
2018-06-07 0:57 ` brian m. carlson
2018-06-07 2:40 ` Jeff King
2018-06-11 7:47 ` Eric Sunshine
2018-06-12 1:05 ` brian m. carlson
2018-06-12 7:29 ` Eric Sunshine
2018-06-14 0:22 ` brian m. carlson
2018-07-24 22:17 ` brian m. carlson
2018-07-25 8:33 ` Eric Sunshine
2018-06-04 23:52 ` [PATCH 02/10] t0000: use hash translation table brian m. carlson
2018-06-04 23:52 ` [PATCH 03/10] t0002: abstract away SHA-1-specific constants brian m. carlson
2018-06-11 7:59 ` Eric Sunshine
2018-06-04 23:52 ` [PATCH 04/10] t0027: use $ZERO_OID brian m. carlson
2018-06-06 7:02 ` Torsten Bögershausen
2018-06-07 1:25 ` brian m. carlson
2018-06-04 23:52 ` [PATCH 05/10] t0064: make hash size independent brian m. carlson
2018-06-11 8:09 ` Eric Sunshine
2018-06-12 1:08 ` brian m. carlson
2018-06-04 23:52 ` [PATCH 06/10] t1006: " brian m. carlson
2018-06-04 23:52 ` [PATCH 07/10] t1400: switch hard-coded object ID to variable brian m. carlson
2018-06-04 23:52 ` [PATCH 08/10] t1405: make hash size independent brian m. carlson
2018-06-04 23:52 ` [PATCH 09/10] t1406: make hash-size independent brian m. carlson
2018-06-04 23:52 ` [PATCH 10/10] t1407: make hash size independent brian m. carlson
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=20180606061927.GA7098@tor.lan \
--to=tboegi@web.de \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=sandals@crustytoothpaste.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.