Skip to content

Commit a9cd684

Browse files
committed
Fix test: use precise regex matching for command names
The test was doing naive substring matching which incorrectly found 'comment' in command descriptions like 'Clone a PR or Issue description and comments...' Now uses regex to extract exact command names from the Commands: section, preventing false positives from substring matches in help text. Also added docstring to clone_cmd wrapper for better documentation.
1 parent e6dffc9 commit a9cd684

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/ghpr/commands/clone.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,5 @@ def register(cli):
274274
@flag('-G', '--no-gist', help='Skip creating a gist')
275275
@opt('-d', '--directory', help='Directory to clone into (default: gh/{number})')
276276
def clone_cmd(spec, no_comments, no_gist, directory):
277+
"""Clone a PR or Issue description and comments to a local directory."""
277278
clone(spec, directory, no_gist, no_comments)

tests/test_import.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def test_cli_loads():
2929

3030
def test_all_commands_present():
3131
"""Test that all expected commands are present."""
32+
import re
33+
3234
result = subprocess.run(
3335
["ghpr", "--help"],
3436
capture_output=True,
@@ -37,7 +39,6 @@ def test_all_commands_present():
3739

3840
expected_commands = [
3941
"clone",
40-
"comment",
4142
"create",
4243
"diff",
4344
"init",
@@ -50,8 +51,13 @@ def test_all_commands_present():
5051
"upload",
5152
]
5253

54+
# Extract command names from the Commands: section
55+
# Commands appear as lines starting with " command-name"
56+
command_pattern = re.compile(r'^ (\S+)', re.MULTILINE)
57+
actual_commands = command_pattern.findall(result.stdout)
58+
5359
for cmd in expected_commands:
54-
assert cmd in result.stdout, f"Command '{cmd}' not found in CLI help"
60+
assert cmd in actual_commands, f"Command '{cmd}' not found in CLI commands. Found: {actual_commands}"
5561

5662

5763
def test_shell_integration_outputs():

0 commit comments

Comments
 (0)