Skip to content

Commit 1ffe2f5

Browse files
committed
test(test[run-args]): add scalar command regressions
why: Lock down the normalization bug at both the helper layer and the public wrapper layer. what: - add direct tests for _normalize_command_args - add git wrapper regression coverage for scalar string args - add minimal hg and svn command wrapper regression tests
1 parent 58603a3 commit 1ffe2f5

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

tests/_internal/test_run.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Tests for libvcs._internal.run."""
2+
3+
from __future__ import annotations
4+
5+
import pathlib
6+
7+
from libvcs._internal.run import _normalize_command_args
8+
9+
10+
def test_normalize_command_args_keeps_scalar_string() -> None:
11+
"""Scalar strings should remain a single subprocess argument."""
12+
assert _normalize_command_args("status") == ["status"]
13+
14+
15+
def test_normalize_command_args_keeps_scalar_bytes() -> None:
16+
"""Scalar bytes should remain a single subprocess argument."""
17+
assert _normalize_command_args(b"status") == [b"status"]
18+
19+
20+
def test_normalize_command_args_expands_sequence() -> None:
21+
"""Sequences should be expanded element by element."""
22+
assert _normalize_command_args(["status", "--short"]) == ["status", "--short"]
23+
24+
25+
def test_normalize_command_args_coerces_pathlike() -> None:
26+
"""Path-like values should be converted with os.fspath semantics."""
27+
path = pathlib.Path("example")
28+
29+
assert _normalize_command_args(path) == ["example"]
30+
assert _normalize_command_args([path, "status"]) == ["example", "status"]

tests/cmd/test_git.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ def test_git_init_basic(tmp_path: pathlib.Path) -> None:
3535
assert (tmp_path / ".git").is_dir()
3636

3737

38+
def test_git_run_accepts_scalar_string(tmp_path: pathlib.Path) -> None:
39+
"""Git run() should not split scalar command strings."""
40+
repo = git.Git(path=tmp_path)
41+
42+
result = repo.run("--version")
43+
44+
assert result.startswith("git version ")
45+
46+
3847
def test_git_init_bare(tmp_path: pathlib.Path) -> None:
3948
"""Test git init with bare repository."""
4049
repo = git.Git(path=tmp_path)

tests/cmd/test_hg.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Tests for libvcs.cmd.hg."""
2+
3+
from __future__ import annotations
4+
5+
import pathlib
6+
import shutil
7+
8+
import pytest
9+
10+
from libvcs.cmd.hg import Hg
11+
12+
if not shutil.which("hg"):
13+
pytestmark = pytest.mark.skip(reason="hg is not available")
14+
15+
16+
def test_hg_run_accepts_scalar_string(tmp_path: pathlib.Path) -> None:
17+
"""Mercurial run() should not split scalar command strings."""
18+
repo = Hg(path=tmp_path)
19+
20+
result = repo.run("help")
21+
22+
assert "Mercurial Distributed SCM" in result

tests/cmd/test_svn.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Tests for libvcs.cmd.svn."""
2+
3+
from __future__ import annotations
4+
5+
import pathlib
6+
import shutil
7+
8+
import pytest
9+
10+
from libvcs.cmd.svn import Svn
11+
12+
if not shutil.which("svn"):
13+
pytestmark = pytest.mark.skip(reason="svn is not available")
14+
15+
16+
def test_svn_run_accepts_scalar_string(tmp_path: pathlib.Path) -> None:
17+
"""Subversion run() should not split scalar command strings."""
18+
repo = Svn(path=tmp_path)
19+
20+
result = repo.run("help")
21+
22+
assert "usage: svn <subcommand> [options] [args]" in result

0 commit comments

Comments
 (0)