t1506: factor out test for "Did you mean..."
With the current code, it's a "'"'"'" jungle, and we test only 1 line of the 2 line response. Factor out and test both. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael J Gruber committed
Mar 31, 2011 at 11:17 UTC
34df9abb41289e475befd05754e518f44f921ef0
1 file changed
+12
-5
t/t1506-rev-parse-diagnosis.sh
+12
-5
@@ -6,6 +6,13 @@ exec </dev/null
6
7
. ./test-lib.sh
8
9
+test_did_you_mean ()
10
+{
11
+ printf "fatal: Path '$2$3' $4, but not ${5:-'$3'}.\n" >expected &&
12
+ printf "Did you mean '$1:$2$3'?\n" >>expected &&
13
+ test_cmp expected error
14
+}
15
+
16
HASH_file=
17
18
test_expect_success 'set up basic repo' '
@@ -106,7 +113,7 @@ test_expect_success 'incorrect file in sha1:path' '
113
grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
114
(cd subdir &&
115
test_must_fail git rev-parse HEAD:file2.txt 2> error &&
109
- grep "Did you mean '"'"'HEAD:subdir/file2.txt'"'"'?" error )
116
+ test_did_you_mean HEAD subdir/ file2.txt exists )
117
'
118
119
test_expect_success 'incorrect file in :path and :N:path' '
@@ -115,14 +122,14 @@ test_expect_success 'incorrect file in :path and :N:path' '
122
test_must_fail git rev-parse :1:nothing.txt 2> error &&
123
grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
124
test_must_fail git rev-parse :1:file.txt 2> error &&
118
- grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
125
+ test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
126
(cd subdir &&
127
test_must_fail git rev-parse :1:file.txt 2> error &&
121
- grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
128
+ test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
129
test_must_fail git rev-parse :file2.txt 2> error &&
123
- grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error &&
130
+ test_did_you_mean ":0" subdir/ file2.txt "is in the index" &&
131
test_must_fail git rev-parse :2:file2.txt 2> error &&
125
- grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error) &&
132
+ test_did_you_mean :0 subdir/ file2.txt "is in the index") &&
133
test_must_fail git rev-parse :disk-only.txt 2> error &&
134
grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
135
'