t1500: test_rev_parse: facilitate future test enhancements
Tests run by test_rev_parse() are nearly identical; each invokes git-rev-parse with a single option and compares the result against an expected value. Such duplication makes it onerous to extend the tests since any change needs to be repeated in each test. Avoid the duplication by parameterizing the test and driving it via a for-loop. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
May 18, 2016 at 16:15 UTC
12f7526c66547ced1b670f5c0faeec5120fc9c7a
1 file changed
+17
-27
t/t1500-rev-parse.sh
+17
-27
@@ -3,38 +3,28 @@
3
test_description='test git rev-parse'
4
. ./test-lib.sh
5
6
-test_rev_parse() {
6
+# usage: label is-bare is-inside-git is-inside-work prefix git-dir
7
+test_rev_parse () {
8
name=$1
9
shift
10
10
- test_expect_success "$name: is-bare-repository" \
11
- "test '$1' = \"\$(git rev-parse --is-bare-repository)\""
12
- shift
13
- [ $# -eq 0 ] && return
14
-
15
- test_expect_success "$name: is-inside-git-dir" \
16
- "test '$1' = \"\$(git rev-parse --is-inside-git-dir)\""
17
- shift
18
- [ $# -eq 0 ] && return
19
-
20
- test_expect_success "$name: is-inside-work-tree" \
21
- "test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
22
- shift
23
- [ $# -eq 0 ] && return
24
-
25
- test_expect_success "$name: prefix" \
26
- "test '$1' = \"\$(git rev-parse --show-prefix)\""
27
- shift
28
- [ $# -eq 0 ] && return
29
-
30
- test_expect_success "$name: git-dir" \
31
- "test '$1' = \"\$(git rev-parse --git-dir)\""
32
- shift
33
- [ $# -eq 0 ] && return
11
+ for o in --is-bare-repository \
12
+ --is-inside-git-dir \
13
+ --is-inside-work-tree \
14
+ --show-prefix \
15
+ --git-dir
16
+ do
17
+ test $# -eq 0 && break
18
+ expect="$1"
19
+ test_expect_success "$name: $o" '
20
+ echo "$expect" >expect &&
21
+ git rev-parse $o >actual &&
22
+ test_cmp expect actual
23
+ '
24
+ shift
25
+ done
26
}
27
36
-# label is-bare is-inside-git is-inside-work prefix git-dir
37
-
28
ROOT=$(pwd)
29
30
test_expect_success 'setup' '