Skip to content

Commit 12f7526

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d66f68f commit 12f7526

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

t/t1500-rev-parse.sh

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,28 @@
33
test_description='test git rev-parse'
44
. ./test-lib.sh
55

6-
test_rev_parse() {
6+
# usage: label is-bare is-inside-git is-inside-work prefix git-dir
7+
test_rev_parse () {
78
name=$1
89
shift
910

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
3426
}
3527

36-
# label is-bare is-inside-git is-inside-work prefix git-dir
37-
3828
ROOT=$(pwd)
3929

4030
test_expect_success 'setup' '

0 commit comments

Comments
 (0)