Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ jobs:
GH_TOKEN: ${{github.token}}
RELEASE_PLEASE_TAG_NAME: ${{steps.release.outputs.tag_name}}
if: steps.release.outputs.release_created

distcheck-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- run: env PYTESTFLAGS="--verbose -p no:cacheprovider --color=yes" test/macos-script.sh
6 changes: 5 additions & 1 deletion completions/patch
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ _comp_cmd_patch()
[[ $was_split ]] && return

if [[ $cur == -* ]]; then
_comp_compgen_help
if [[ $OSTYPE == *@(darwin)* ]]; then
_comp_compgen_usage
else
_comp_compgen_help
fi
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
Expand Down
6 changes: 5 additions & 1 deletion completions/truncate
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ _comp_cmd_truncate()
[[ $was_split ]] && return

if [[ $cur == -* ]]; then
_comp_compgen_help
if [[ $OSTYPE == *@(darwin)* ]]; then
_comp_compgen_usage
else
_comp_compgen_help
fi
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
Expand Down
29 changes: 29 additions & 0 deletions test/macos-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh -eux

# Note that this script is intended to be run only in throwaway environments;
# it may install undesirable things to system locations (if it succeeds in
# that).

brew install \
automake \
bash

python3 -m venv venv
#shellcheck disable=SC1091
source venv/bin/activate
python3 -m pip install -r test/requirements.txt

rsync --version
rsync --help
echo 'tar version:'
tar --version

export bashcomp_bash=bash
env

autoreconf -i
./configure
make -j

make distcheck \
PYTESTFLAGS="${PYTESTFLAGS---verbose -p no:cacheprovider --numprocesses=auto --dist=loadfile}"
10 changes: 7 additions & 3 deletions test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,9 @@ def startswith(self, prefix: str) -> bool:
return self.output.startswith(prefix)

def _items(self) -> List[str]:
return [x.strip() for x in self.output.strip().splitlines()]
return sorted(
[x.strip() for x in self.output.strip().splitlines() if x]
)

def __eq__(self, expected: object) -> bool:
"""
Expand All @@ -788,7 +790,7 @@ def __eq__(self, expected: object) -> bool:
return False
else:
expiter = expected
return self._items() == expiter
return self._items() == sorted(expiter)

def __contains__(self, item: str) -> bool:
return item in self._items()
Expand Down Expand Up @@ -953,7 +955,9 @@ def prepare_fixture_dir(
the tarball. This is to work better with case insensitive file systems.
"""
tempdir = Path(tempfile.mkdtemp(prefix="bash-completion-fixture-dir"))
request.addfinalizer(lambda: shutil.rmtree(str(tempdir)))
request.addfinalizer(
lambda: shutil.rmtree(str(tempdir), ignore_errors=True)
)

old_cwd = os.getcwd()
try:
Expand Down
26 changes: 14 additions & 12 deletions test/t/test_make.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import os
import sys

import pytest

from conftest import assert_complete


class TestMake:
@pytest.fixture
def remove_extra_makefile(self, bash):
yield
# For some reason macos make doesn't actually create extra_makefile
if sys.platform != "darwin":
os.remove(f"{bash.cwd}/make/extra_makefile")

@pytest.mark.complete("make -f Ma", cwd="make")
def test_1(self, completion):
assert completion == "kefile"

@pytest.mark.complete("make .", cwd="make", require_cmd=True)
def test_2(self, bash, completion):
def test_2(self, bash, completion, remove_extra_makefile):
"""Hidden targets."""
assert completion == ".cache/ .test_passes".split()
os.remove(f"{bash.cwd}/make/extra_makefile")

@pytest.mark.complete("make .cache/", cwd="make", require_cmd=True)
def test_3(self, bash, completion):
def test_3(self, bash, completion, remove_extra_makefile):
assert completion == ".cache/1 .cache/2".split()
os.remove(f"{bash.cwd}/make/extra_makefile")

@pytest.mark.complete("make ", cwd="shared/empty_dir")
def test_4(self, completion):
Expand All @@ -30,24 +36,20 @@ def test_5(self, completion):
assert completion

@pytest.mark.complete("make ", cwd="make", require_cmd=True)
def test_6(self, bash, completion):
def test_6(self, bash, completion, remove_extra_makefile):
assert completion == "all clean extra_makefile install sample".split()
os.remove(f"{bash.cwd}/make/extra_makefile")

@pytest.mark.complete("make .cache/.", cwd="make", require_cmd=True)
def test_7(self, bash, completion):
def test_7(self, bash, completion, remove_extra_makefile):
assert completion == ".cache/.1 .cache/.2".split()
os.remove(f"{bash.cwd}/make/extra_makefile")

@pytest.mark.complete("make -C make ", require_cmd=True)
def test_8(self, bash, completion):
def test_8(self, bash, completion, remove_extra_makefile):
assert completion == "all clean extra_makefile install sample".split()
os.remove(f"{bash.cwd}/make/extra_makefile")

@pytest.mark.complete("make -nC make ", require_cmd=True)
def test_8n(self, bash, completion):
def test_8n(self, bash, completion, remove_extra_makefile):
assert completion == "all clean extra_makefile install sample".split()
os.remove(f"{bash.cwd}/make/extra_makefile")

@pytest.mark.complete("make -", require_cmd=True)
def test_9(self, completion):
Expand Down
7 changes: 1 addition & 6 deletions test/t/test_vipw.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import sys

import pytest


class TestVipw:
@pytest.mark.complete("vipw -", require_cmd=True)
def test_1(self, completion):
if sys.platform == "darwin":
assert not completion # takes no options
else:
assert completion
assert completion
5 changes: 4 additions & 1 deletion test/t/unit/test_unit_dequote.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import pytest

from conftest import assert_bash_exec, bash_env_saved
Expand Down Expand Up @@ -38,7 +40,8 @@ def test_5_brace(self, bash, functions):

def test_6_glob(self, bash, functions):
output = assert_bash_exec(bash, "__tester 'a?b'", want_output=True)
assert output.strip() == "<a b><a$b><a&b><a'b>"
items = sorted(re.findall(r"<[^>]*>", output))
assert "".join(items) == "<a b><a$b><a&b><a'b>"

def test_7_quote_1(self, bash, functions):
output = assert_bash_exec(
Expand Down
27 changes: 21 additions & 6 deletions test/t/unit/test_unit_expand_glob.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import unicodedata

import pytest

from conftest import assert_bash_exec, bash_env_saved


def normalize(string):
# Applies "canonical decomposition", so might make errors look weird?
# The alternative is probably `NFC` which composes together some of
# the characters again.
# See https://docs.python.org/3/library/unicodedata.html#unicodedata.normalize
return unicodedata.normalize("NFD", string)


@pytest.mark.bashcomp(
cmd=None,
cwd="_filedir",
Expand All @@ -22,14 +32,15 @@ def functions(self, bash):

def test_match_all(self, bash, functions):
output = assert_bash_exec(bash, "__tester '*'", want_output=True)
assert (
output.strip()
== "<a b><a$b><a&b><a'b><ab><aé><brackets><dotdot><ext>"
assert normalize(output.strip()) == normalize(
"<a b><a$b><a&b><a'b><ab><aé><brackets><dotdot><ext>"
)

def test_match_pattern(self, bash, functions):
output = assert_bash_exec(bash, "__tester 'a*'", want_output=True)
assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé>"
assert normalize(output.strip()) == normalize(
"<a b><a$b><a&b><a'b><ab><aé>"
)

def test_match_unmatched(self, bash, functions):
output = assert_bash_exec(
Expand All @@ -51,7 +62,9 @@ def test_protect_from_noglob(self, bash, functions):
with bash_env_saved(bash, functions) as bash_env:
bash_env.set("noglob", True)
output = assert_bash_exec(bash, "__tester 'a*'", want_output=True)
assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé>"
assert normalize(output.strip()) == normalize(
"<a b><a$b><a&b><a'b><ab><aé>"
)

def test_protect_from_failglob(self, bash, functions):
with bash_env_saved(bash) as bash_env:
Expand Down Expand Up @@ -83,4 +96,6 @@ def test_protect_from_GLOBIGNORE(self, bash, functions):
bash_env.save_shopt("dotglob")
bash_env.write_variable("GLOBIGNORE", "*")
output = assert_bash_exec(bash, "__tester 'a*'", want_output=True)
assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé>"
assert normalize(output.strip()) == normalize(
"<a b><a$b><a&b><a'b><ab><aé>"
)
Loading