Skip to content

Commit 39fc408

Browse files
Unique-Usmangitster
authored andcommitted
t/t1517: automate git subcmd -h tests outside a repository
Replace manual `-h` tests with a loop over all subcommands using `git --list-cmds=main`. This ensures consistent coverage of `-h` behavior outside a repo and future-proofs the test by covering new commands automatically. Known exceptions are skipped or marked as expected failures. Suggested-by: Patrick Steinhardt <[email protected]> Helped-by: Junio C Hamano <[email protected]> Helped-by: D. Ben Knoble <[email protected]> Signed-off-by: Usman Akinyemi <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 866e6a3 commit 39fc408

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

t/t1517-outside-repo.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ test_expect_success LIBCURL 'remote-http outside repository' '
109109

110110
test_expect_success 'update-server-info does not crash with -h' '
111111
test_expect_code 129 git update-server-info -h >usage &&
112-
test_grep "[Uu]sage: git update-server-info " usage &&
113-
test_expect_code 129 nongit git update-server-info -h >usage &&
114112
test_grep "[Uu]sage: git update-server-info " usage
115113
'
116114

@@ -121,4 +119,32 @@ test_expect_success 'prune does not crash with -h' '
121119
test_grep "[Uu]sage: git prune " usage
122120
'
123121

122+
for cmd in $(git --list-cmds=main)
123+
do
124+
cmd=${cmd%.*} # strip .sh, .perl, etc.
125+
case "$cmd" in
126+
archimport | cvsexportcommit | cvsimport | cvsserver | daemon | \
127+
difftool--helper | filter-branch | fsck-objects | get-tar-commit-id | \
128+
http-backend | http-fetch | http-push | init-db | \
129+
merge-octopus | merge-one-file | merge-resolve | mergetool | \
130+
mktag | p4 | p4.py | pickaxe | remote-ftp | remote-ftps | \
131+
remote-http | remote-https | replay | send-email | \
132+
sh-i18n--envsubst | shell | show | stage | submodule | svn | \
133+
upload-archive--writer | upload-pack | web--browse | whatchanged)
134+
expect_outcome=expect_failure ;;
135+
*)
136+
expect_outcome=expect_success ;;
137+
esac
138+
case "$cmd" in
139+
instaweb)
140+
prereq=PERL ;;
141+
*)
142+
prereq= ;;
143+
esac
144+
test_$expect_outcome $prereq "'git $cmd -h' outside a repository" '
145+
test_expect_code 129 nongit git $cmd -h >usage &&
146+
test_grep "[Uu]sage: git $cmd " usage
147+
'
148+
done
149+
124150
test_done

0 commit comments

Comments
 (0)