]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parseopt: add tests for subcommand autocorrection
authorJiamu Sun <39@barroit.sh>
Thu, 23 Apr 2026 01:37:59 +0000 (10:37 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 23 Apr 2026 02:02:29 +0000 (11:02 +0900)
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>
t/meson.build
t/t9004-autocorrect-subcommand.sh [new file with mode: 0755]

index f66a73f8a07d937777deda9a63cee4798c91917b..bf0503d705a9a3932ec2f102e943efd75984e139 100644 (file)
@@ -973,6 +973,7 @@ integration_tests = [
   't9001-send-email.sh',
   't9002-column.sh',
   't9003-help-autocorrect.sh',
+  't9004-autocorrect-subcommand.sh',
   't9100-git-svn-basic.sh',
   't9101-git-svn-props.sh',
   't9102-git-svn-deep-rmdir.sh',
diff --git a/t/t9004-autocorrect-subcommand.sh b/t/t9004-autocorrect-subcommand.sh
new file mode 100755 (executable)
index 0000000..09d281b
--- /dev/null
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+test_description='subcommand auto-correction test
+
+Test autocorrection for subcommands with different
+help.autocorrect mode.'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' "
+       echo '^error: unknown subcommand: ' >grep_unknown
+"
+
+test_expect_success 'default is show hint only' '
+       test_must_fail git worktree lsit 2>actual &&
+       test_grep "most similar subcommand" actual
+'
+
+test_expect_success "'never' disables autocorrection" '
+       test_config help.autocorrect never &&
+
+       test_must_fail git worktree lsit 2>actual &&
+       head -n1 actual >first && test_grep -f grep_unknown first
+'
+
+for mode in false no off 0 show
+do
+       test_expect_success "'$mode' disables autocorrection and shows hints" "
+               test_config help.autocorrect $mode &&
+
+               test_must_fail git worktree lsit 2>actual &&
+               test_grep 'most similar subcommand' actual
+       "
+done
+
+for mode in -39 immediate 1
+do
+       test_expect_success "autocorrect immediately with '$mode'" - <<-EOT
+               test_config help.autocorrect $mode &&
+
+               git worktree lsit 2>actual &&
+               test_grep "you meant 'list'\.$" actual
+       EOT
+done
+
+test_expect_success 'delay path is executed' - <<-\EOT
+       test_config help.autocorrect 2 &&
+
+       git worktree lsit 2>actual &&
+       test_grep '^Continuing in 0.2 seconds, ' actual
+EOT
+
+test_expect_success 'deny if too dissimilar' - <<-\EOT
+       test_must_fail git remote rensnr 2>actual &&
+       head -n1 actual >first && test_grep -f grep_unknown first
+EOT
+
+test_done