diff mbox series

[v4,18/39] t8002: make hash size independent

Message ID 20200726195424.626969-19-sandals@crustytoothpaste.net (mailing list archive)
State New, archived
Headers show
Series [v4,01/39] t: make test-bloom initialize repository | expand

Commit Message

brian m. carlson July 26, 2020, 7:54 p.m. UTC
Compute the length of an object ID instead of of hard-coding 40-based
values.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t8002-blame.sh | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

Eric Sunshine July 26, 2020, 10:49 p.m. UTC | #1
On Sun, Jul 26, 2020 at 3:55 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> Compute the length of an object ID instead of of hard-coding 40-based

s/of of /of/

> values.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
> @@ -6,6 +6,10 @@ test_description='git blame'
> +test_expect_success 'setup' '
> +       test_oid_init
> +'
> +
> @@ -105,17 +109,18 @@ test_expect_success 'blame --abbrev=<n> works' '
>  test_expect_success 'blame -l aligns regular and boundary commits' '
> +       hexsz=$(test_oid hexsz) &&
> +       check_abbrev $hexsz         -l HEAD &&
> +       check_abbrev $((hexsz - 1)) -l ^HEAD
>  '
> +test_expect_success 'blame --abbrev with full length behaves like -l' '
> +       check_abbrev $hexsz         --abbrev=$hexsz HEAD &&
> +       check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD
>  '

Rather than assigning 'hexsz' in the first test which needs the value
and then re-using the value in subsequent tests, how about assigning
'hexsz' in the new "setup" test? This will make it easier to run
individual tests while skipping others.
diff mbox series

Patch

diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index eea048e52c..557c886559 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -6,6 +6,10 @@  test_description='git blame'
 PROG='git blame -c'
 . "$TEST_DIRECTORY"/annotate-tests.sh
 
+test_expect_success 'setup' '
+	test_oid_init
+'
+
 test_expect_success 'blame untracked file in empty repo' '
 	>untracked &&
 	test_must_fail git blame untracked
@@ -105,17 +109,18 @@  test_expect_success 'blame --abbrev=<n> works' '
 '
 
 test_expect_success 'blame -l aligns regular and boundary commits' '
-	check_abbrev 40 -l HEAD &&
-	check_abbrev 39 -l ^HEAD
+	hexsz=$(test_oid hexsz) &&
+	check_abbrev $hexsz         -l HEAD &&
+	check_abbrev $((hexsz - 1)) -l ^HEAD
 '
 
-test_expect_success 'blame --abbrev=40 behaves like -l' '
-	check_abbrev 40 --abbrev=40 HEAD &&
-	check_abbrev 39 --abbrev=40 ^HEAD
+test_expect_success 'blame --abbrev with full length behaves like -l' '
+	check_abbrev $hexsz         --abbrev=$hexsz HEAD &&
+	check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD
 '
 
-test_expect_success '--no-abbrev works like --abbrev=40' '
-	check_abbrev 40 --no-abbrev
+test_expect_success '--no-abbrev works like --abbrev with full length' '
+	check_abbrev $hexsz --no-abbrev
 '
 
 test_expect_success '--exclude-promisor-objects does not BUG-crash' '