Skip to content

Commit 92e2a91

Browse files
barroitgitster
authored andcommitted
help: 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 94d7bdf commit 92e2a91

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

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)