From patchwork Mon Oct 28 00:59:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 11214449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 22C6E112C for ; Mon, 28 Oct 2019 00:59:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E00302070B for ; Mon, 28 Oct 2019 00:59:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (3072-bit key) header.d=crustytoothpaste.net header.i=@crustytoothpaste.net header.b="OHYyuAQ0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728651AbfJ1A7e (ORCPT ); Sun, 27 Oct 2019 20:59:34 -0400 Received: from injection.crustytoothpaste.net ([192.241.140.119]:54282 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729001AbfJ1A7d (ORCPT ); Sun, 27 Oct 2019 20:59:33 -0400 Received: from camp.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:b610:a2f0:36c1:12e3]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 611A361CAF; Mon, 28 Oct 2019 00:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1572224371; bh=9cHS+BdocZDusjgmfDKsZP7OczLxO50sQOp48s48Hg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=OHYyuAQ0nDOPxz6oElH2R+teJ1bfUmHVaJp9x5YDp7Od6WfDEPKGhNv5zNrtNsv6z p2+AD1NROVfFjFAFngHvY+di921qpfYmiQsG0czscY9USLacZxXOqdbcKaRsKFMXty 1EVODkwU1DfImXrqS4JSfYG39RCefvvqfS6S+AzUfCp6RU5gbaNEIQBhJDX1RtcbS7 d9zOsHGtVTPytKd+0mutNrhC4feLNKgRDrREd+BNvl+yYPXW6SXzYmPHCWbjXiMtZX G3713gUwP3BjcqqFe5X4hhvMD8IpHT2Z1/HWgKVmcsfpCuL1xJrQPf+qaM+k6aSrkp MDkmlSFAeEeQ+ZCtBa0M7rMtnuvbOWCpuiKjwCE1P7UkN/Ves42xaA4TiSms/L9eCf +fC4fd3k6uPVXLsCAezsmf1cpobtS31NoYT8scvC/WhhMN3kjQzJ3CSbJHbvqClsdL MEiHb6d+tXj6tiVt6K3ifdwbhjbIZXIBp0kHvn8EiHlq9+l97JW From: "brian m. carlson" To: Cc: Derrick Stolee , Stefan Beller , Johannes Schindelin Subject: [PATCH v2 08/15] t4015: abstract away SHA-1-specific constants Date: Mon, 28 Oct 2019 00:59:00 +0000 Message-Id: <20191028005907.24985-9-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665 In-Reply-To: <20191028005907.24985-1-sandals@crustytoothpaste.net> References: <20191028005907.24985-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Signed-off-by: brian m. carlson --- t/t4015-diff-whitespace.sh | 89 +++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 6b087df3dc..eadaf57262 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -16,6 +16,7 @@ test_expect_success "Ray Lehtiniemi's example" ' } while (0); EOF git update-index --add x && + before=$(git rev-parse --short $(git hash-object x)) && cat <<-\EOF >x && do @@ -24,10 +25,11 @@ test_expect_success "Ray Lehtiniemi's example" ' } while (0); EOF + after=$(git rev-parse --short $(git hash-object x)) && - cat <<-\EOF >expect && + cat <<-EOF >expect && diff --git a/x b/x - index adf3937..6edc172 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,3 +1,5 @@ @@ -61,6 +63,7 @@ test_expect_success 'another test, without options' ' EOF git update-index x && + before=$(git rev-parse --short $(git hash-object x)) && tr "_" " " <<-\EOF >x && _ whitespace at beginning @@ -70,10 +73,11 @@ test_expect_success 'another test, without options' ' unchanged line CR at end EOF + after=$(git rev-parse --short $(git hash-object x)) && - tr "Q_" "\015 " <<-\EOF >expect && + tr "Q_" "\015 " <<-EOF >expect && diff --git a/x b/x - index d99af23..22d9f73 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,6 +1,6 @@ @@ -108,9 +112,9 @@ test_expect_success 'another test, without options' ' git diff -w --ignore-cr-at-eol >out && test_must_be_empty out && - tr "Q_" "\015 " <<-\EOF >expect && + tr "Q_" "\015 " <<-EOF >expect && diff --git a/x b/x - index d99af23..22d9f73 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,6 +1,6 @@ @@ -132,9 +136,9 @@ test_expect_success 'another test, without options' ' git diff -b --ignore-cr-at-eol >out && test_cmp expect out && - tr "Q_" "\015 " <<-\EOF >expect && + tr "Q_" "\015 " <<-EOF >expect && diff --git a/x b/x - index d99af23..22d9f73 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,6 +1,6 @@ @@ -154,9 +158,9 @@ test_expect_success 'another test, without options' ' git diff --ignore-space-at-eol --ignore-cr-at-eol >out && test_cmp expect out && - tr "Q_" "\015 " <<-\EOF >expect && + tr "Q_" "\015 " <<-EOF >expect && diff --git a/x b/x - index_d99af23..22d9f73 100644 + index_$before..$after 100644 --- a/x +++ b/x @@ -1,6 +1,6 @@ @@ -786,23 +790,25 @@ test_expect_success 'whitespace-only changes not reported' ' test_must_be_empty actual ' -cat <expect -diff --git a/x b/z -similarity index NUM% -rename from x -rename to z -index 380c32a..a97b785 100644 -EOF test_expect_success 'whitespace-only changes reported across renames' ' git reset --hard && for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x && git add x && + before=$(git rev-parse --short $(git hash-object x)) && git commit -m "base" && sed -e "5s/^/ /" x >z && git rm x && git add z && + after=$(git rev-parse --short $(git hash-object z)) && git diff -w -M --cached | sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual && + cat <<-EOF >expect && + diff --git a/x b/z + similarity index NUM% + rename from x + rename to z + index $before..$after 100644 + EOF test_cmp expect actual ' @@ -858,13 +864,15 @@ test_expect_success 'diff that introduces a line with only tabs' ' git config core.whitespace blank-at-eol && git reset --hard && echo "test" >x && + before=$(git rev-parse --short $(git hash-object x)) && git commit -m "initial" x && echo "{NTN}" | tr "NT" "\n\t" >>x && + after=$(git rev-parse --short $(git hash-object x)) && git diff --color | test_decode_color >current && - cat >expected <<-\EOF && + cat >expected <<-EOF && diff --git a/x b/x - index 9daeafb..2874b91 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1 +1,4 @@ @@ -883,19 +891,21 @@ test_expect_success 'diff that introduces and removes ws breakages' ' echo "0. blank-at-eol " && echo "1. blank-at-eol " } >x && + before=$(git rev-parse --short $(git hash-object x)) && git commit -a --allow-empty -m preimage && { echo "0. blank-at-eol " && echo "1. still-blank-at-eol " && echo "2. and a new line " } >x && + after=$(git rev-parse --short $(git hash-object x)) && git diff --color | test_decode_color >current && - cat >expected <<-\EOF && + cat >expected <<-EOF && diff --git a/x b/x - index d0233a2..700886e 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,2 +1,3 @@ @@ -915,16 +925,18 @@ test_expect_success 'ws-error-highlight test setup' ' echo "0. blank-at-eol " && echo "1. blank-at-eol " } >x && + before=$(git rev-parse --short $(git hash-object x)) && git commit -a --allow-empty -m preimage && { echo "0. blank-at-eol " && echo "1. still-blank-at-eol " && echo "2. and a new line " } >x && + after=$(git rev-parse --short $(git hash-object x)) && - cat >expect.default-old <<-\EOF && + cat >expect.default-old <<-EOF && diff --git a/x b/x - index d0233a2..700886e 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,2 +1,3 @@ @@ -934,9 +946,9 @@ test_expect_success 'ws-error-highlight test setup' ' +2. and a new line EOF - cat >expect.all <<-\EOF && + cat >expect.all <<-EOF && diff --git a/x b/x - index d0233a2..700886e 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,2 +1,3 @@ @@ -946,9 +958,9 @@ test_expect_success 'ws-error-highlight test setup' ' +2. and a new line EOF - cat >expect.none <<-\EOF + cat >expect.none <<-EOF diff --git a/x b/x - index d0233a2..700886e 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,2 +1,3 @@ @@ -1022,14 +1034,15 @@ test_expect_success 'detect moved code, complete file' ' EOF git add test.c && git commit -m "add main function" && + file=$(git rev-parse --short HEAD:test.c) && git mv test.c main.c && test_config color.diff.oldMoved "normal red" && test_config color.diff.newMoved "normal green" && git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual && - cat >expected <<-\EOF && + cat >expected <<-EOF && diff --git a/main.c b/main.c new file mode 100644 - index 0000000..a986c57 + index 0000000..$file --- /dev/null +++ b/main.c @@ -0,0 +1,5 @@ @@ -1040,7 +1053,7 @@ test_expect_success 'detect moved code, complete file' ' +} diff --git a/test.c b/test.c deleted file mode 100644 - index a986c57..0000000 + index $file..0000000 --- a/test.c +++ /dev/null @@ -1,5 +0,0 @@ @@ -1094,6 +1107,8 @@ test_expect_success 'detect malicious moved code, inside file' ' EOF git add main.c test.c && git commit -m "add main and test file" && + before_main=$(git rev-parse --short HEAD:main.c) && + before_test=$(git rev-parse --short HEAD:test.c) && cat <<-\EOF >main.c && #include int stuff() @@ -1126,10 +1141,12 @@ test_expect_success 'detect malicious moved code, inside file' ' bar(); } EOF + after_main=$(git rev-parse --short $(git hash-object main.c)) && + after_test=$(git rev-parse --short $(git hash-object test.c)) && git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual && - cat <<-\EOF >expected && + cat <<-EOF >expected && diff --git a/main.c b/main.c - index 27a619c..7cf9336 100644 + index $before_main..$after_main 100644 --- a/main.c +++ b/main.c @@ -5,13 +5,6 @@ printf("Hello "); @@ -1147,7 +1164,7 @@ test_expect_success 'detect malicious moved code, inside file' ' { foo(); diff --git a/test.c b/test.c - index 1dc1d85..2bedec9 100644 + index $before_test..$after_test 100644 --- a/test.c +++ b/test.c @@ -4,6 +4,13 @@ int bar() @@ -1176,9 +1193,9 @@ test_expect_success 'plain moved code, inside file' ' test_config color.diff.newMovedAlternative "yellow" && # needs previous test as setup git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual && - cat <<-\EOF >expected && + cat <<-EOF >expected && diff --git a/main.c b/main.c - index 27a619c..7cf9336 100644 + index $before_main..$after_main 100644 --- a/main.c +++ b/main.c @@ -5,13 +5,6 @@ printf("Hello "); @@ -1196,7 +1213,7 @@ test_expect_success 'plain moved code, inside file' ' { foo(); diff --git a/test.c b/test.c - index 1dc1d85..2bedec9 100644 + index $before_test..$after_test 100644 --- a/test.c +++ b/test.c @@ -4,6 +4,13 @@ int bar()