Skip to content

Commit 5e11362

Browse files
artagnongitster
authored andcommitted
t3040 (subprojects-basic): fix '&&' chaining, modernize style
Breaks in a test assertion's && chain can potentially hide failures from earlier commands in the chain. Fix instances of this. While at it, clean up the style to fit the prevailing style. This means: - Put the opening quote starting each test on the same line as the test_expect_* invocation. - Indent the file with tabs, not spaces. - Use test_expect_code() in preference to checking the exit status of various statements by hand. - Guard commands that prepare test input for individual tests in the same test_expect_success, so that their scope is clearer and errors at that stage can be caught. - Use <<-\EOF in preference to <<EOF to save readers the trouble of looking for variable interpolations. - Include "setup" in the titles of test assertions that prepare for later ones to make it more obvious which tests can be skipped. Helped-by: Jonathan Nieder <[email protected]> Signed-off-by: Ramkumar Ramachandra <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f9a5fc commit 5e11362

File tree

1 file changed

+72
-72
lines changed

1 file changed

+72
-72
lines changed

t/t3040-subprojects-basic.sh

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,81 @@
33
test_description='Basic subproject functionality'
44
. ./test-lib.sh
55

6-
test_expect_success 'Super project creation' \
7-
': >Makefile &&
8-
git add Makefile &&
9-
git commit -m "Superproject created"'
10-
11-
12-
cat >expected <<EOF
13-
:000000 160000 00000... A sub1
14-
:000000 160000 00000... A sub2
15-
EOF
16-
test_expect_success 'create subprojects' \
17-
'mkdir sub1 &&
18-
( cd sub1 && git init && : >Makefile && git add * &&
19-
git commit -q -m "subproject 1" ) &&
20-
mkdir sub2 &&
21-
( cd sub2 && git init && : >Makefile && git add * &&
22-
git commit -q -m "subproject 2" ) &&
23-
git update-index --add sub1 &&
24-
git add sub2 &&
25-
git commit -q -m "subprojects added" &&
26-
git diff-tree --abbrev=5 HEAD^ HEAD |cut -d" " -f-3,5- >current &&
27-
test_cmp expected current'
28-
29-
git branch save HEAD
30-
31-
test_expect_success 'check if fsck ignores the subprojects' \
32-
'git fsck --full'
33-
34-
test_expect_success 'check if commit in a subproject detected' \
35-
'( cd sub1 &&
36-
echo "all:" >>Makefile &&
37-
echo " true" >>Makefile &&
38-
git commit -q -a -m "make all" ) && {
39-
git diff-files --exit-code
40-
test $? = 1
41-
}'
42-
43-
test_expect_success 'check if a changed subproject HEAD can be committed' \
44-
'git commit -q -a -m "sub1 changed" && {
45-
git diff-tree --exit-code HEAD^ HEAD
46-
test $? = 1
47-
}'
48-
49-
test_expect_success 'check if diff-index works for subproject elements' \
50-
'git diff-index --exit-code --cached save -- sub1
51-
test $? = 1'
52-
53-
test_expect_success 'check if diff-tree works for subproject elements' \
54-
'git diff-tree --exit-code HEAD^ HEAD -- sub1
55-
test $? = 1'
56-
57-
test_expect_success 'check if git diff works for subproject elements' \
58-
'git diff --exit-code HEAD^ HEAD
59-
test $? = 1'
60-
61-
test_expect_success 'check if clone works' \
62-
'git ls-files -s >expected &&
63-
git clone -l -s . cloned &&
64-
( cd cloned && git ls-files -s ) >current &&
65-
test_cmp expected current'
66-
67-
test_expect_success 'removing and adding subproject' \
68-
'git update-index --force-remove -- sub2 &&
69-
mv sub2 sub3 &&
70-
git add sub3 &&
71-
git commit -q -m "renaming a subproject" && {
72-
git diff -M --name-status --exit-code HEAD^ HEAD
73-
test $? = 1
74-
}'
6+
test_expect_success 'setup: create superproject' '
7+
: >Makefile &&
8+
git add Makefile &&
9+
git commit -m "Superproject created"
10+
'
11+
12+
test_expect_success 'setup: create subprojects' '
13+
mkdir sub1 &&
14+
( cd sub1 && git init && : >Makefile && git add * &&
15+
git commit -q -m "subproject 1" ) &&
16+
mkdir sub2 &&
17+
( cd sub2 && git init && : >Makefile && git add * &&
18+
git commit -q -m "subproject 2" ) &&
19+
git update-index --add sub1 &&
20+
git add sub2 &&
21+
git commit -q -m "subprojects added" &&
22+
git diff-tree --abbrev=5 HEAD^ HEAD |cut -d" " -f-3,5- >current &&
23+
git branch save HEAD &&
24+
cat >expected <<-\EOF &&
25+
:000000 160000 00000... A sub1
26+
:000000 160000 00000... A sub2
27+
EOF
28+
test_cmp expected current
29+
'
30+
31+
test_expect_success 'check if fsck ignores the subprojects' '
32+
git fsck --full
33+
'
34+
35+
test_expect_success 'check if commit in a subproject detected' '
36+
( cd sub1 &&
37+
echo "all:" >>Makefile &&
38+
echo " true" >>Makefile &&
39+
git commit -q -a -m "make all" ) &&
40+
test_expect_code 1 git diff-files --exit-code
41+
'
42+
43+
test_expect_success 'check if a changed subproject HEAD can be committed' '
44+
git commit -q -a -m "sub1 changed" &&
45+
test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD
46+
'
47+
48+
test_expect_success 'check if diff-index works for subproject elements' '
49+
test_expect_code 1 git diff-index --exit-code --cached save -- sub1
50+
'
51+
52+
test_expect_success 'check if diff-tree works for subproject elements' '
53+
test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- sub1
54+
'
55+
56+
test_expect_success 'check if git diff works for subproject elements' '
57+
test_expect_code 1 git diff --exit-code HEAD^ HEAD
58+
'
59+
60+
test_expect_success 'check if clone works' '
61+
git ls-files -s >expected &&
62+
git clone -l -s . cloned &&
63+
( cd cloned && git ls-files -s ) >current &&
64+
test_cmp expected current
65+
'
66+
67+
test_expect_success 'removing and adding subproject' '
68+
git update-index --force-remove -- sub2 &&
69+
mv sub2 sub3 &&
70+
git add sub3 &&
71+
git commit -q -m "renaming a subproject" &&
72+
test_expect_code 1 git diff -M --name-status --exit-code HEAD^ HEAD
73+
'
7574

7675
# the index must contain the object name the HEAD of the
7776
# subproject sub1 was at the point "save"
78-
test_expect_success 'checkout in superproject' \
79-
'git checkout save &&
80-
git diff-index --exit-code --raw --cached save -- sub1'
77+
test_expect_success 'checkout in superproject' '
78+
git checkout save &&
79+
git diff-index --exit-code --raw --cached save -- sub1
80+
'
8181

8282
# just interesting what happened...
8383
# git diff --name-status -M save master

0 commit comments

Comments
 (0)