88import pytest
99
1010import borg
11- from ...archiver .completion_cmd import TCSH_SORTBY_FN
11+ from ...archiver .completion_cmd import TCSH_REPO_URL_RULE , TCSH_SORTBY_FN
1212from ...archiver .repo_create_cmd import ENCRYPTION_DESCRIPTIONS
1313from . import cmd , generate_archiver_tests , RK_ENCRYPTION
1414
@@ -632,12 +632,13 @@ def test_zsh_repo_url_no_directories(archivers, request):
632632 archiver = request .getfixturevalue (archivers )
633633 script = cmd (archiver , "completion" , "zsh" )
634634 # stub the zsh directory completion, it needs the whole completion system
635- setup = " _files() { print -r -- COMPLETING-DIRS }\n "
635+ setup = ' _files() { print -r -- COMPLETING-DIRS "$@" }\n '
636636 for url in REPO_URLS :
637637 result = _run_zsh_completion_fn (script , setup + f"PREFIX='{ url } '\n _borg_complete_repo_dirs\n " )
638638 assert "COMPLETING-DIRS" not in result .stdout , f"directories offered for { url } "
639- result = _run_zsh_completion_fn (script , setup + "PREFIX=/some/dir\n _borg_complete_repo_dirs\n " )
640- assert "COMPLETING-DIRS" in result .stdout
639+ # the arguments (_arguments gives the description of the option value) are passed on
640+ result = _run_zsh_completion_fn (script , setup + "PREFIX=/some/dir\n _borg_complete_repo_dirs -X REPO\n " )
641+ assert result .stdout .split () == ["COMPLETING-DIRS" , "-/" , "-X" , "REPO" ]
641642
642643
643644@needs_fish
@@ -655,7 +656,7 @@ def test_fish_repo_url_no_directories(archivers, request):
655656def test_tcsh_repo_url_no_directories (archivers , request ):
656657 """tcsh uses the first matching rule, the one completing nothing for URLs must precede the directory ones."""
657658 lines = [line .strip ().rstrip (" \\ " ) for line in completion_lines (archivers , request , "tcsh" )]
658- url_rule = lines .index ("'c/{--repo=,-r=,--other-repo=,}{ssh,sftp,http,https,s3,b2,rclone}:/n/'" )
659+ url_rule = lines .index (TCSH_REPO_URL_RULE )
659660 for repo_rule in ("'c/--repo=/d/'" , "'n/--repo/d/'" , "'n/-r/d/'" , "'c/--other-repo=/d/'" , "'n/--other-repo/d/'" ):
660661 assert url_rule < lines .index (repo_rule )
661662
@@ -673,6 +674,9 @@ def test_fish_repo_directory_completion(archivers, request, tmp_path):
673674 candidates = _fish_complete_candidates (script , f"borg list { option } { prefix } " )
674675 assert any (c .rstrip ("/" ).endswith ("somerepo" ) for c in candidates ), f"repo dir missing: { candidates } "
675676 assert not any (c .endswith ("somefile.txt" ) for c in candidates ), f"file offered: { candidates } "
677+ # the value attached to the short option
678+ candidates = _fish_complete_candidates (script , f"borg list -r{ prefix } " )
679+ assert [c .rstrip ("/" ) for c in candidates ] == [f"-r{ prefix } repo" ]
676680
677681
678682@needs_fish
0 commit comments