From: "Li Linchao via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Li Linchao" <lilinchao@oschina.cn>,
"Li Linchao" <lilinchao@oschina.cn>
Subject: [PATCH v2] ls-files: update test style
Date: Tue, 28 Jun 2022 09:14:24 +0000 [thread overview]
Message-ID: <pull.1269.v2.git.1656407664694.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1269.git.1655974015414.gitgitgadget@gmail.com>
From: Li Linchao <lilinchao@oschina.cn>
Update test style in t/t30[*].sh for uniformity, that's to
keep test title the same line with helper function itself.
And update t/README to describe this test style.
Signed-off-by: Li Linchao <lilinchao@oschina.cn>
---
ls-files: update test style
Update test style in t/t30[*].sh for uniformity, that's to keep test
title the same line with helper function itself.
And update t/README to describe this test style.
Signed-off-by: Li Linchao lilinchao@oschina.cn
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1269%2FCactusinhand%2Fllc%2Ffix-test-title-style-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1269/Cactusinhand/llc/fix-test-title-style-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1269
Range-diff vs v1:
1: e18a6172cff ! 1: 775c17499d5 ls-files: update test style
@@ Commit message
Signed-off-by: Li Linchao <lilinchao@oschina.cn>
## t/README ##
-@@ t/README: Here are the "do's:"
- Even code that isn't a test per se, but merely some setup code
- should be inside a test assertion.
+@@ t/README: This test harness library does the following things:
+ consistently when command line arguments --verbose (or -v),
+ --debug (or -d), and --immediate (or -i) is given.
-+ - Keep test title the same line with test helper function itself,
-+ and end the line with a single quote.
++Recommended style
++-----------------
++Here are some recommented style that you should follow when you write some test cases.
++
++ - Keep test title the same line with test helper function itself.
+
+ Take test_expect_success helper for example, write it like:
+
-+ test_expect_success 'test title to describe this test case' '
-+ # test body
++ test_expect_success 'test title' '
++ ... test body ...
+ '
+
+ Instead of:
+
+ test_expect_success \
-+ 'test title to describe this test case' \
-+ '# test body'
++ 'test title' \
++ '... test body ...'
++
++
++ - End the line with a single quote.
++
++ - Indent the body of here-document, and cut off prefix TAB by using
++ "<<-":
+
- - Chain your test assertions
++ test_expect_success 'test something' '
++ cat >expect <<-\EOF &&
++ one
++ two
++ three
++ EOF
++ test_something > actual &&
++ test_cmp expect actual
++ '
++
++ Instead of:
++
++ test_expect_success 'test something' '
++ cat >expect <<\EOF &&
++ one
++ two
++ three
++ EOF
++ test_something > actual &&
++ test_cmp expect actual
++ '
++
++
+ Do's & don'ts
+ -------------
- Write test code like this:
## t/t3001-ls-files-others-exclude.sh ##
@@ t/t3001-ls-files-others-exclude.sh: echo '!*.2
@@ t/t3001-ls-files-others-exclude.sh: echo '!*.2
--exclude=\*.6 \
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
- >output &&
+- >output &&
- test_cmp expect output'
-+ test_cmp expect output
++ >output &&
++ test_cmp expect output
+'
# Test \r\n (MSDOS-like systems)
@@ t/t3001-ls-files-others-exclude.sh: echo '!*.2
--exclude=\*.6 \
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
- >output &&
+- >output &&
- test_cmp expect output'
-+ test_cmp expect output
++ >output &&
++ test_cmp expect output
+'
test_expect_success 'setup skip-worktree gitignore' '
@@ t/t3001-ls-files-others-exclude.sh: test_expect_success 'setup skip-worktree git
--exclude=\*.6 \
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
- >output &&
+- >output &&
- test_cmp expect output'
-+ test_cmp expect output
++ >output &&
++ test_cmp expect output
+'
test_expect_success !SANITIZE_LEAK 'restore gitignore' '
git checkout --ignore-skip-worktree-bits $allignores &&
+@@ t/t3001-ls-files-others-exclude.sh: test_expect_success 'pattern matches prefix completely' '
+ '
+
+ test_expect_success 'ls-files with "**" patterns' '
+- cat <<\EOF >expect &&
+-a.1
+-one/a.1
+-one/two/a.1
+-three/a.1
+-EOF
++ cat <<-\EOF >expect &&
++ a.1
++ one/a.1
++ one/two/a.1
++ three/a.1
++ EOF
+ git ls-files -o -i --exclude "**/a.1" >actual &&
+ test_cmp expect actual
+ '
## t/t3002-ls-files-dashpath.sh ##
@@ t/t3002-ls-files-dashpath.sh: filesystem.
@@ t/t3002-ls-files-dashpath.sh: filesystem.
- setup \
- 'echo frotz >path0 &&
+test_expect_success 'setup' '
-+ echo frotz >path0 &&
++ echo frotz >path0 &&
echo frotz >./-foo &&
- echo frotz >./--'
+ echo frotz >./--
@@ t/t3002-ls-files-dashpath.sh: filesystem.
-test_expect_success \
- 'git ls-files without path restriction.' \
- 'git ls-files --others >output &&
+- test_cmp output - <<EOF
+---
+--foo
+-output
+-path0
+-EOF
+test_expect_success 'git ls-files without path restriction.' '
-+ git ls-files --others >output &&
- test_cmp output - <<EOF
- --
- -foo
-@@ t/t3002-ls-files-dashpath.sh: path0
- EOF
++ test_when_finished "rm -f expect" &&
++ git ls-files --others >output &&
++ cat >expect <<-\EOF &&
++ --
++ -foo
++ output
++ path0
++ EOF
++ test_cmp output expect
'
-test_expect_success \
- 'git ls-files with path restriction.' \
- 'git ls-files --others path0 >output &&
+- test_cmp output - <<EOF
+-path0
+-EOF
+test_expect_success 'git ls-files with path restriction.' '
-+ git ls-files --others path0 >output &&
- test_cmp output - <<EOF
- path0
- EOF
++ test_when_finished "rm -f expect" &&
++ git ls-files --others path0 >output &&
++ cat >expect <<-\EOF &&
++ path0
++ EOF
++ test_cmp output expect
'
-test_expect_success \
- 'git ls-files with path restriction with --.' \
- 'git ls-files --others -- path0 >output &&
+- test_cmp output - <<EOF
+-path0
+-EOF
+test_expect_success 'git ls-files with path restriction with --.' '
-+ git ls-files --others -- path0 >output &&
- test_cmp output - <<EOF
- path0
- EOF
++ test_when_finished "rm -f expect" &&
++ git ls-files --others -- path0 >output &&
++ cat >expect <<-\EOF &&
++ path0
++ EOF
++ test_cmp output expect
'
-test_expect_success \
- 'git ls-files with path restriction with -- --.' \
- 'git ls-files --others -- -- >output &&
+- test_cmp output - <<EOF
+---
+-EOF
+test_expect_success 'git ls-files with path restriction with -- --.' '
-+ git ls-files --others -- -- >output &&
- test_cmp output - <<EOF
- --
- EOF
++ test_when_finished "rm -f expect" &&
++ git ls-files --others -- -- >output &&
++ cat >expect <<-\EOF &&
++ --
++ EOF
++ test_cmp output expect
'
-test_expect_success \
- 'git ls-files with no path restriction.' \
- 'git ls-files --others -- >output &&
+- test_cmp output - <<EOF
+---
+--foo
+-output
+-path0
+-EOF
+test_expect_success 'git ls-files with no path restriction.' '
-+ git ls-files --others -- >output &&
- test_cmp output - <<EOF
- --
- -foo
++ test_when_finished "rm -f expect" &&
++ git ls-files --others -- >output &&
++ cat >expect <<-\EOF &&
++ --
++ -foo
++ output
++ path0
++ EOF
++ test_cmp output expect
++
+ '
+
+ test_done
+
+ ## t/t3007-ls-files-recurse-submodules.sh ##
+@@ t/t3007-ls-files-recurse-submodules.sh: test_expect_success '--recurse-submodules does not support --error-unmatch' '
+
+ test_incompatible_with_recurse_submodules () {
+ test_expect_success "--recurse-submodules and $1 are incompatible" "
+- test_must_fail git ls-files --recurse-submodules $1 2>actual &&
+- test_i18ngrep 'unsupported mode' actual
++ test_must_fail git ls-files --recurse-submodules $1 2>actual &&
++ test_i18ngrep 'unsupported mode' actual
+ "
+ }
+
## t/t3020-ls-files-error-unmatch.sh ##
@@ t/t3020-ls-files-error-unmatch.sh: test_expect_success 'setup' '
@@ t/t3020-ls-files-error-unmatch.sh: test_expect_success 'setup' '
- 'git ls-files --error-unmatch should fail with unmatched path.' \
- 'test_must_fail git ls-files --error-unmatch foo bar-does-not-match'
+test_expect_success 'git ls-files --error-unmatch should fail with unmatched path.' '
-+ test_must_fail git ls-files --error-unmatch foo bar-does-not-match
++ test_must_fail git ls-files --error-unmatch foo bar-does-not-match
+'
-test_expect_success \
- 'git ls-files --error-unmatch should succeed with matched paths.' \
- 'git ls-files --error-unmatch foo bar'
+test_expect_success 'git ls-files --error-unmatch should succeed with matched paths.' '
-+ git ls-files --error-unmatch foo bar
++ git ls-files --error-unmatch foo bar
+'
test_done
## t/t3060-ls-files-with-tree.sh ##
+@@ t/t3060-ls-files-with-tree.sh: a scenario known to trigger a crash with some versions of git.
+ '
+ . ./test-lib.sh
+
+-test_expect_success setup '
++test_expect_success 'setup' '
+
+ # The bug we are exercising requires a fair number of entries
+ # in a sub-directory so that add_index_entry will trigger a
@@ t/t3060-ls-files-with-tree.sh: test_expect_success 'git ls-files --with-tree should succeed from subdir' '
)
'
t/README | 47 ++++++++++++++
t/t3001-ls-files-others-exclude.sh | 42 ++++++-------
t/t3002-ls-files-dashpath.sh | 86 ++++++++++++++------------
t/t3007-ls-files-recurse-submodules.sh | 4 +-
t/t3020-ls-files-error-unmatch.sh | 12 ++--
t/t3060-ls-files-with-tree.sh | 8 +--
6 files changed, 126 insertions(+), 73 deletions(-)
diff --git a/t/README b/t/README
index 309a31133c6..845af1883c3 100644
--- a/t/README
+++ b/t/README
@@ -547,6 +547,53 @@ This test harness library does the following things:
consistently when command line arguments --verbose (or -v),
--debug (or -d), and --immediate (or -i) is given.
+Recommended style
+-----------------
+Here are some recommented style that you should follow when you write some test cases.
+
+ - Keep test title the same line with test helper function itself.
+
+ Take test_expect_success helper for example, write it like:
+
+ test_expect_success 'test title' '
+ ... test body ...
+ '
+
+ Instead of:
+
+ test_expect_success \
+ 'test title' \
+ '... test body ...'
+
+
+ - End the line with a single quote.
+
+ - Indent the body of here-document, and cut off prefix TAB by using
+ "<<-":
+
+ test_expect_success 'test something' '
+ cat >expect <<-\EOF &&
+ one
+ two
+ three
+ EOF
+ test_something > actual &&
+ test_cmp expect actual
+ '
+
+ Instead of:
+
+ test_expect_success 'test something' '
+ cat >expect <<\EOF &&
+ one
+ two
+ three
+ EOF
+ test_something > actual &&
+ test_cmp expect actual
+ '
+
+
Do's & don'ts
-------------
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index 48cec4e5f88..e07ac6c6dce 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -67,26 +67,26 @@ echo '!*.2
allignores='.gitignore one/.gitignore one/two/.gitignore'
-test_expect_success \
- 'git ls-files --others with various exclude options.' \
- 'git ls-files --others \
+test_expect_success 'git ls-files --others with various exclude options.' '
+ git ls-files --others \
--exclude=\*.6 \
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
- >output &&
- test_cmp expect output'
+ >output &&
+ test_cmp expect output
+'
# Test \r\n (MSDOS-like systems)
printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
-test_expect_success \
- 'git ls-files --others with \r\n line endings.' \
- 'git ls-files --others \
+test_expect_success 'git ls-files --others with \r\n line endings.' '
+ git ls-files --others \
--exclude=\*.6 \
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
- >output &&
- test_cmp expect output'
+ >output &&
+ test_cmp expect output
+'
test_expect_success 'setup skip-worktree gitignore' '
git add $allignores &&
@@ -94,14 +94,14 @@ test_expect_success 'setup skip-worktree gitignore' '
rm $allignores
'
-test_expect_success \
- 'git ls-files --others with various exclude options.' \
- 'git ls-files --others \
+test_expect_success 'git ls-files --others with various exclude options.' '
+ git ls-files --others \
--exclude=\*.6 \
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
- >output &&
- test_cmp expect output'
+ >output &&
+ test_cmp expect output
+'
test_expect_success !SANITIZE_LEAK 'restore gitignore' '
git checkout --ignore-skip-worktree-bits $allignores &&
@@ -283,12 +283,12 @@ test_expect_success 'pattern matches prefix completely' '
'
test_expect_success 'ls-files with "**" patterns' '
- cat <<\EOF >expect &&
-a.1
-one/a.1
-one/two/a.1
-three/a.1
-EOF
+ cat <<-\EOF >expect &&
+ a.1
+ one/a.1
+ one/two/a.1
+ three/a.1
+ EOF
git ls-files -o -i --exclude "**/a.1" >actual &&
test_cmp expect actual
'
diff --git a/t/t3002-ls-files-dashpath.sh b/t/t3002-ls-files-dashpath.sh
index 54d22a45dfb..4dd24550eba 100755
--- a/t/t3002-ls-files-dashpath.sh
+++ b/t/t3002-ls-files-dashpath.sh
@@ -16,56 +16,62 @@ filesystem.
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
-test_expect_success \
- setup \
- 'echo frotz >path0 &&
+test_expect_success 'setup' '
+ echo frotz >path0 &&
echo frotz >./-foo &&
- echo frotz >./--'
+ echo frotz >./--
+'
-test_expect_success \
- 'git ls-files without path restriction.' \
- 'git ls-files --others >output &&
- test_cmp output - <<EOF
---
--foo
-output
-path0
-EOF
+test_expect_success 'git ls-files without path restriction.' '
+ test_when_finished "rm -f expect" &&
+ git ls-files --others >output &&
+ cat >expect <<-\EOF &&
+ --
+ -foo
+ output
+ path0
+ EOF
+ test_cmp output expect
'
-test_expect_success \
- 'git ls-files with path restriction.' \
- 'git ls-files --others path0 >output &&
- test_cmp output - <<EOF
-path0
-EOF
+test_expect_success 'git ls-files with path restriction.' '
+ test_when_finished "rm -f expect" &&
+ git ls-files --others path0 >output &&
+ cat >expect <<-\EOF &&
+ path0
+ EOF
+ test_cmp output expect
'
-test_expect_success \
- 'git ls-files with path restriction with --.' \
- 'git ls-files --others -- path0 >output &&
- test_cmp output - <<EOF
-path0
-EOF
+test_expect_success 'git ls-files with path restriction with --.' '
+ test_when_finished "rm -f expect" &&
+ git ls-files --others -- path0 >output &&
+ cat >expect <<-\EOF &&
+ path0
+ EOF
+ test_cmp output expect
'
-test_expect_success \
- 'git ls-files with path restriction with -- --.' \
- 'git ls-files --others -- -- >output &&
- test_cmp output - <<EOF
---
-EOF
+test_expect_success 'git ls-files with path restriction with -- --.' '
+ test_when_finished "rm -f expect" &&
+ git ls-files --others -- -- >output &&
+ cat >expect <<-\EOF &&
+ --
+ EOF
+ test_cmp output expect
'
-test_expect_success \
- 'git ls-files with no path restriction.' \
- 'git ls-files --others -- >output &&
- test_cmp output - <<EOF
---
--foo
-output
-path0
-EOF
+test_expect_success 'git ls-files with no path restriction.' '
+ test_when_finished "rm -f expect" &&
+ git ls-files --others -- >output &&
+ cat >expect <<-\EOF &&
+ --
+ -foo
+ output
+ path0
+ EOF
+ test_cmp output expect
+
'
test_done
diff --git a/t/t3007-ls-files-recurse-submodules.sh b/t/t3007-ls-files-recurse-submodules.sh
index dd7770e85de..2a057e987fe 100755
--- a/t/t3007-ls-files-recurse-submodules.sh
+++ b/t/t3007-ls-files-recurse-submodules.sh
@@ -301,8 +301,8 @@ test_expect_success '--recurse-submodules does not support --error-unmatch' '
test_incompatible_with_recurse_submodules () {
test_expect_success "--recurse-submodules and $1 are incompatible" "
- test_must_fail git ls-files --recurse-submodules $1 2>actual &&
- test_i18ngrep 'unsupported mode' actual
+ test_must_fail git ls-files --recurse-submodules $1 2>actual &&
+ test_i18ngrep 'unsupported mode' actual
"
}
diff --git a/t/t3020-ls-files-error-unmatch.sh b/t/t3020-ls-files-error-unmatch.sh
index 2cbcbc0721b..133593d23c0 100755
--- a/t/t3020-ls-files-error-unmatch.sh
+++ b/t/t3020-ls-files-error-unmatch.sh
@@ -19,12 +19,12 @@ test_expect_success 'setup' '
git commit -m "add foo bar"
'
-test_expect_success \
- 'git ls-files --error-unmatch should fail with unmatched path.' \
- 'test_must_fail git ls-files --error-unmatch foo bar-does-not-match'
+test_expect_success 'git ls-files --error-unmatch should fail with unmatched path.' '
+ test_must_fail git ls-files --error-unmatch foo bar-does-not-match
+'
-test_expect_success \
- 'git ls-files --error-unmatch should succeed with matched paths.' \
- 'git ls-files --error-unmatch foo bar'
+test_expect_success 'git ls-files --error-unmatch should succeed with matched paths.' '
+ git ls-files --error-unmatch foo bar
+'
test_done
diff --git a/t/t3060-ls-files-with-tree.sh b/t/t3060-ls-files-with-tree.sh
index b257c792a46..52f76f7b57f 100755
--- a/t/t3060-ls-files-with-tree.sh
+++ b/t/t3060-ls-files-with-tree.sh
@@ -10,7 +10,7 @@ a scenario known to trigger a crash with some versions of git.
'
. ./test-lib.sh
-test_expect_success setup '
+test_expect_success 'setup' '
# The bug we are exercising requires a fair number of entries
# 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' '
)
'
-test_expect_success \
- 'git ls-files --with-tree should add entries from named tree.' \
- 'test_cmp expected output'
+test_expect_success 'git ls-files --with-tree should add entries from named tree.' '
+ test_cmp expected output
+'
test_expect_success 'no duplicates in --with-tree output' '
git ls-files --with-tree=HEAD >actual &&
base-commit: e4a4b31577c7419497ac30cebe30d755b97752c5
--
gitgitgadget
next prev parent reply other threads:[~2022-06-28 9:15 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-23 8:46 [PATCH] ls-files: update test style Li Linchao via GitGitGadget
2022-06-23 10:50 ` Ævar Arnfjörð Bjarmason
2022-06-24 4:57 ` lilinchao
2022-06-23 17:09 ` Junio C Hamano
2022-06-24 5:05 ` lilinchao
2022-06-28 9:14 ` Li Linchao via GitGitGadget [this message]
2022-06-28 9:51 ` [PATCH v3] " Li Linchao via GitGitGadget
2022-06-28 20:12 ` Junio C Hamano
2022-06-29 7:12 ` lilinchao
2022-06-30 15:54 ` Junio C Hamano
2022-06-30 5:59 ` [PATCH v4] " Li Linchao via GitGitGadget
2022-07-01 11:03 ` [PATCH v5] " Li Linchao via GitGitGadget
2022-07-01 21:46 ` Junio C Hamano
2022-07-03 15:49 ` [PATCH v6] " Li Linchao via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1269.v2.git.1656407664694.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=lilinchao@oschina.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).