Skip to content

Commit e3d49aa

Browse files
committed
Merge branch 'll/ls-files-tests-update' into maint
Test update. source: <[email protected]> * ll/ls-files-tests-update: ls-files: update test style
2 parents 2d39f66 + 18337d4 commit e3d49aa

File tree

5 files changed

+132
-71
lines changed

5 files changed

+132
-71
lines changed

t/README

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,61 @@ This test harness library does the following things:
547547
consistently when command line arguments --verbose (or -v),
548548
--debug (or -d), and --immediate (or -i) is given.
549549

550+
Recommended style
551+
-----------------
552+
Here are some recommented styles when writing test case.
553+
554+
- Keep test title the same line with test helper function itself.
555+
556+
Take test_expect_success helper for example, write it like:
557+
558+
test_expect_success 'test title' '
559+
... test body ...
560+
'
561+
562+
Instead of:
563+
564+
test_expect_success \
565+
'test title' \
566+
'... test body ...'
567+
568+
569+
- End the line with a single quote.
570+
571+
- Indent the body of here-document, and use "<<-" instead of "<<"
572+
to strip leading TABs used for indentation:
573+
574+
test_expect_success 'test something' '
575+
cat >expect <<-\EOF &&
576+
one
577+
two
578+
three
579+
EOF
580+
test_something > actual &&
581+
test_cmp expect actual
582+
'
583+
584+
Instead of:
585+
586+
test_expect_success 'test something' '
587+
cat >expect <<\EOF &&
588+
one
589+
two
590+
three
591+
EOF
592+
test_something > actual &&
593+
test_cmp expect actual
594+
'
595+
596+
- Quote or escape the EOF delimiter that begins a here-document if
597+
there is no parameter and other expansion in it, to signal readers
598+
that they can skim it more casually:
599+
600+
cmd <<-\EOF
601+
literal here-document text without any expansion
602+
EOF
603+
604+
550605
Do's & don'ts
551606
-------------
552607

t/t3001-ls-files-others-exclude.sh

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,41 @@ echo '!*.2
6767

6868
allignores='.gitignore one/.gitignore one/two/.gitignore'
6969

70-
test_expect_success \
71-
'git ls-files --others with various exclude options.' \
72-
'git ls-files --others \
70+
test_expect_success 'git ls-files --others with various exclude options.' '
71+
git ls-files --others \
7372
--exclude=\*.6 \
7473
--exclude-per-directory=.gitignore \
7574
--exclude-from=.git/ignore \
76-
>output &&
77-
test_cmp expect output'
75+
>output &&
76+
test_cmp expect output
77+
'
7878

7979
# Test \r\n (MSDOS-like systems)
8080
printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
8181

82-
test_expect_success \
83-
'git ls-files --others with \r\n line endings.' \
84-
'git ls-files --others \
82+
test_expect_success 'git ls-files --others with \r\n line endings.' '
83+
git ls-files --others \
8584
--exclude=\*.6 \
8685
--exclude-per-directory=.gitignore \
8786
--exclude-from=.git/ignore \
88-
>output &&
89-
test_cmp expect output'
87+
>output &&
88+
test_cmp expect output
89+
'
9090

9191
test_expect_success 'setup skip-worktree gitignore' '
9292
git add $allignores &&
9393
git update-index --skip-worktree $allignores &&
9494
rm $allignores
9595
'
9696

97-
test_expect_success \
98-
'git ls-files --others with various exclude options.' \
99-
'git ls-files --others \
97+
test_expect_success 'git ls-files --others with various exclude options.' '
98+
git ls-files --others \
10099
--exclude=\*.6 \
101100
--exclude-per-directory=.gitignore \
102101
--exclude-from=.git/ignore \
103-
>output &&
104-
test_cmp expect output'
102+
>output &&
103+
test_cmp expect output
104+
'
105105

106106
test_expect_success !SANITIZE_LEAK 'restore gitignore' '
107107
git checkout --ignore-skip-worktree-bits $allignores &&
@@ -283,12 +283,12 @@ test_expect_success 'pattern matches prefix completely' '
283283
'
284284

285285
test_expect_success 'ls-files with "**" patterns' '
286-
cat <<\EOF >expect &&
287-
a.1
288-
one/a.1
289-
one/two/a.1
290-
three/a.1
291-
EOF
286+
cat <<-\EOF >expect &&
287+
a.1
288+
one/a.1
289+
one/two/a.1
290+
three/a.1
291+
EOF
292292
git ls-files -o -i --exclude "**/a.1" >actual &&
293293
test_cmp expect actual
294294
'

t/t3002-ls-files-dashpath.sh

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,62 @@ filesystem.
1616
TEST_PASSES_SANITIZE_LEAK=true
1717
. ./test-lib.sh
1818

19-
test_expect_success \
20-
setup \
21-
'echo frotz >path0 &&
19+
test_expect_success 'setup' '
20+
echo frotz >path0 &&
2221
echo frotz >./-foo &&
23-
echo frotz >./--'
22+
echo frotz >./--
23+
'
2424

25-
test_expect_success \
26-
'git ls-files without path restriction.' \
27-
'git ls-files --others >output &&
28-
test_cmp output - <<EOF
29-
--
30-
-foo
31-
output
32-
path0
33-
EOF
25+
test_expect_success 'git ls-files without path restriction.' '
26+
test_when_finished "rm -f expect" &&
27+
git ls-files --others >output &&
28+
cat >expect <<-\EOF &&
29+
--
30+
-foo
31+
output
32+
path0
33+
EOF
34+
test_cmp output expect
3435
'
3536

36-
test_expect_success \
37-
'git ls-files with path restriction.' \
38-
'git ls-files --others path0 >output &&
39-
test_cmp output - <<EOF
40-
path0
41-
EOF
37+
test_expect_success 'git ls-files with path restriction.' '
38+
test_when_finished "rm -f expect" &&
39+
git ls-files --others path0 >output &&
40+
cat >expect <<-\EOF &&
41+
path0
42+
EOF
43+
test_cmp output expect
4244
'
4345

44-
test_expect_success \
45-
'git ls-files with path restriction with --.' \
46-
'git ls-files --others -- path0 >output &&
47-
test_cmp output - <<EOF
48-
path0
49-
EOF
46+
test_expect_success 'git ls-files with path restriction with --.' '
47+
test_when_finished "rm -f expect" &&
48+
git ls-files --others -- path0 >output &&
49+
cat >expect <<-\EOF &&
50+
path0
51+
EOF
52+
test_cmp output expect
5053
'
5154

52-
test_expect_success \
53-
'git ls-files with path restriction with -- --.' \
54-
'git ls-files --others -- -- >output &&
55-
test_cmp output - <<EOF
56-
--
57-
EOF
55+
test_expect_success 'git ls-files with path restriction with -- --.' '
56+
test_when_finished "rm -f expect" &&
57+
git ls-files --others -- -- >output &&
58+
cat >expect <<-\EOF &&
59+
--
60+
EOF
61+
test_cmp output expect
5862
'
5963

60-
test_expect_success \
61-
'git ls-files with no path restriction.' \
62-
'git ls-files --others -- >output &&
63-
test_cmp output - <<EOF
64-
--
65-
-foo
66-
output
67-
path0
68-
EOF
64+
test_expect_success 'git ls-files with no path restriction.' '
65+
test_when_finished "rm -f expect" &&
66+
git ls-files --others -- >output &&
67+
cat >expect <<-\EOF &&
68+
--
69+
-foo
70+
output
71+
path0
72+
EOF
73+
test_cmp output expect
74+
6975
'
7076

7177
test_done

t/t3020-ls-files-error-unmatch.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ test_expect_success 'setup' '
1919
git commit -m "add foo bar"
2020
'
2121

22-
test_expect_success \
23-
'git ls-files --error-unmatch should fail with unmatched path.' \
24-
'test_must_fail git ls-files --error-unmatch foo bar-does-not-match'
22+
test_expect_success 'git ls-files --error-unmatch should fail with unmatched path.' '
23+
test_must_fail git ls-files --error-unmatch foo bar-does-not-match
24+
'
2525

26-
test_expect_success \
27-
'git ls-files --error-unmatch should succeed with matched paths.' \
28-
'git ls-files --error-unmatch foo bar'
26+
test_expect_success 'git ls-files --error-unmatch should succeed with matched paths.' '
27+
git ls-files --error-unmatch foo bar
28+
'
2929

3030
test_done

t/t3060-ls-files-with-tree.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ a scenario known to trigger a crash with some versions of git.
1010
'
1111
. ./test-lib.sh
1212

13-
test_expect_success setup '
13+
test_expect_success 'setup' '
1414
1515
# The bug we are exercising requires a fair number of entries
1616
# in a sub-directory so that add_index_entry will trigger a
@@ -62,9 +62,9 @@ test_expect_success 'git ls-files --with-tree should succeed from subdir' '
6262
)
6363
'
6464

65-
test_expect_success \
66-
'git ls-files --with-tree should add entries from named tree.' \
67-
'test_cmp expected output'
65+
test_expect_success 'git ls-files --with-tree should add entries from named tree.' '
66+
test_cmp expected output
67+
'
6868

6969
test_expect_success 'no duplicates in --with-tree output' '
7070
git ls-files --with-tree=HEAD >actual &&

0 commit comments

Comments
 (0)