Skip to content

Commit 840624f

Browse files
bk2204gitster
authored andcommitted
t4011: abstract away SHA-1-specific constants
Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32a6707 commit 840624f

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

t/t4011-diff-symlink.sh

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,32 @@ test_description='Test diff of symlinks.
99
. ./test-lib.sh
1010
. "$TEST_DIRECTORY"/diff-lib.sh
1111

12+
# Print the short OID of a symlink with the given name.
13+
symlink_oid () {
14+
local oid=$(printf "%s" "$1" | git hash-object --stdin) &&
15+
git rev-parse --short "$oid"
16+
}
17+
18+
# Print the short OID of the given file.
19+
short_oid () {
20+
local oid=$(git hash-object "$1") &&
21+
git rev-parse --short "$oid"
22+
}
23+
1224
test_expect_success 'diff new symlink and file' '
13-
cat >expected <<-\EOF &&
25+
symlink=$(symlink_oid xyzzy) &&
26+
cat >expected <<-EOF &&
1427
diff --git a/frotz b/frotz
1528
new file mode 120000
16-
index 0000000..7c465af
29+
index 0000000..$symlink
1730
--- /dev/null
1831
+++ b/frotz
1932
@@ -0,0 +1 @@
2033
+xyzzy
2134
\ No newline at end of file
2235
diff --git a/nitfol b/nitfol
2336
new file mode 100644
24-
index 0000000..7c465af
37+
index 0000000..$symlink
2538
--- /dev/null
2639
+++ b/nitfol
2740
@@ -0,0 +1 @@
@@ -46,18 +59,18 @@ test_expect_success 'diff unchanged symlink and file' '
4659
'
4760

4861
test_expect_success 'diff removed symlink and file' '
49-
cat >expected <<-\EOF &&
62+
cat >expected <<-EOF &&
5063
diff --git a/frotz b/frotz
5164
deleted file mode 120000
52-
index 7c465af..0000000
65+
index $symlink..0000000
5366
--- a/frotz
5467
+++ /dev/null
5568
@@ -1 +0,0 @@
5669
-xyzzy
5770
\ No newline at end of file
5871
diff --git a/nitfol b/nitfol
5972
deleted file mode 100644
60-
index 7c465af..0000000
73+
index $symlink..0000000
6174
--- a/nitfol
6275
+++ /dev/null
6376
@@ -1 +0,0 @@
@@ -90,9 +103,10 @@ test_expect_success 'diff identical, but newly created symlink and file' '
90103
'
91104

92105
test_expect_success 'diff different symlink and file' '
93-
cat >expected <<-\EOF &&
106+
new=$(symlink_oid yxyyz) &&
107+
cat >expected <<-EOF &&
94108
diff --git a/frotz b/frotz
95-
index 7c465af..df1db54 120000
109+
index $symlink..$new 120000
96110
--- a/frotz
97111
+++ b/frotz
98112
@@ -1 +1 @@
@@ -101,7 +115,7 @@ test_expect_success 'diff different symlink and file' '
101115
+yxyyz
102116
\ No newline at end of file
103117
diff --git a/nitfol b/nitfol
104-
index 7c465af..df1db54 100644
118+
index $symlink..$new 100644
105119
--- a/nitfol
106120
+++ b/nitfol
107121
@@ -1 +1 @@
@@ -137,14 +151,16 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
137151
'
138152

139153
test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
140-
cat >expect <<-\EOF &&
154+
file=$(short_oid file.bin) &&
155+
link=$(symlink_oid file.bin) &&
156+
cat >expect <<-EOF &&
141157
diff --git a/file.bin b/file.bin
142158
new file mode 100644
143-
index 0000000..d95f3ad
159+
index 0000000..$file
144160
Binary files /dev/null and b/file.bin differ
145161
diff --git a/link.bin b/link.bin
146162
new file mode 120000
147-
index 0000000..dce41ec
163+
index 0000000..$link
148164
--- /dev/null
149165
+++ b/link.bin
150166
@@ -0,0 +1 @@

0 commit comments

Comments
 (0)