Skip to content

Commit 273faab

Browse files
barroitgitster
authored andcommitted
parseopt: add tests for subcommand autocorrection
These tests cover default behavior (help.autocorrect is unset), no correction, immediate correction, delayed correction, and rejection when the typo is too dissimilar. Signed-off-by: Jiamu Sun <39@barroit.sh> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ae8b7e1 commit 273faab

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ integration_tests = [
973973
't9001-send-email.sh',
974974
't9002-column.sh',
975975
't9003-help-autocorrect.sh',
976+
't9004-autocorrect-subcommand.sh',
976977
't9100-git-svn-basic.sh',
977978
't9101-git-svn-props.sh',
978979
't9102-git-svn-deep-rmdir.sh',

t/t9004-autocorrect-subcommand.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
3+
test_description='subcommand auto-correction test
4+
5+
Test autocorrection for subcommands with different
6+
help.autocorrect mode.'
7+
8+
. ./test-lib.sh
9+
10+
test_expect_success 'setup' "
11+
echo '^error: unknown subcommand: ' >grep_unknown
12+
"
13+
14+
test_expect_success 'default is not to autocorrect' '
15+
test_must_fail git worktree lsit 2>actual &&
16+
head -n1 actual >first && test_grep -f grep_unknown first
17+
'
18+
19+
for mode in false no off 0 show never
20+
do
21+
test_expect_success "'$mode' disables autocorrection" "
22+
test_config help.autocorrect $mode &&
23+
24+
test_must_fail git worktree lsit 2>actual &&
25+
head -n1 actual >first && test_grep -f grep_unknown first
26+
"
27+
done
28+
29+
for mode in -39 immediate 1
30+
do
31+
test_expect_success "autocorrect immediately with '$mode'" - <<-EOT
32+
test_config help.autocorrect $mode &&
33+
34+
git worktree lsit 2>actual &&
35+
test_grep "you meant 'list'\.$" actual
36+
EOT
37+
done
38+
39+
test_expect_success 'delay path is executed' - <<-\EOT
40+
test_config help.autocorrect 2 &&
41+
42+
git worktree lsit 2>actual &&
43+
test_grep '^Continuing in 0.2 seconds, ' actual
44+
EOT
45+
46+
test_expect_success 'deny if too dissimilar' - <<-\EOT
47+
test_must_fail git remote rensnr 2>actual &&
48+
head -n1 actual >first && test_grep -f grep_unknown first
49+
EOT
50+
51+
test_done

0 commit comments

Comments
 (0)