From 8a15b7d52def954135f576a6334ae4a53190ba82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 31 May 2021 23:13:02 +0300 Subject: [PATCH 01/15] test: add macOS test script --- test/macos-script.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 test/macos-script.sh diff --git a/test/macos-script.sh b/test/macos-script.sh new file mode 100755 index 00000000000..d1480312fce --- /dev/null +++ b/test/macos-script.sh @@ -0,0 +1,22 @@ +#!/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 pip install -r test/requirements.txt + +export bashcomp_bash=bash +env + +autoreconf -i +./configure +make -j + +make distcheck \ + PYTESTFLAGS="${PYTESTFLAGS---verbose --numprocesses=auto --dist=loadfile}" +cp -p bash-completion-*.tar.* "$oldpwd/" From 0e006b0c75966551ad64e88b419dbbb873414cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 4 Apr 2024 21:46:12 +0000 Subject: [PATCH 02/15] TO BE REWORKED BEFORE MERGE: temporary macOS CI test config This is an interim hack to remove things from CI config unrelated to beating the test suite into shape on macOS, for a bit faster turnaround. To be cleaned up and properly integrated to check.yaml before merge. --- .github/workflows/ci.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 48860e5f5c1..6ee9247023b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,6 +8,7 @@ on: jobs: pre-commit: + if: false runs-on: ubuntu-latest steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -38,6 +39,7 @@ jobs: pre-commit run --color=always --all-files --show-diff-on-failure distcheck: + if: false runs-on: ubuntu-latest strategy: matrix: @@ -94,3 +96,9 @@ jobs: env: GH_TOKEN: ${{github.token}} if: steps.release.outputs.release_created + + distcheck-macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - run: env PYTESTFLAGS=--verbose test/macos-script.sh From cefc875b2ea0ea7a93073499e99f9ff12e00b580 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Mon, 24 Feb 2025 22:27:11 +0200 Subject: [PATCH 03/15] ci: Remove if:false --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6ee9247023b..4a9b1610e03 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,7 +8,6 @@ on: jobs: pre-commit: - if: false runs-on: ubuntu-latest steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -39,7 +38,6 @@ jobs: pre-commit run --color=always --all-files --show-diff-on-failure distcheck: - if: false runs-on: ubuntu-latest strategy: matrix: From b04ef6f7c9dcfd5330e9b3f83685fc0bc879fde4 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Mon, 24 Feb 2025 22:36:34 +0200 Subject: [PATCH 04/15] ci: Align macos script with current linux --- .github/workflows/ci.yaml | 2 +- test/macos-script.sh | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4a9b1610e03..b5ca7e5fff6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -99,4 +99,4 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v4 - - run: env PYTESTFLAGS=--verbose test/macos-script.sh + - run: env PYTESTFLAGS="--verbose -p no:cacheprovider" test/macos-script.sh diff --git a/test/macos-script.sh b/test/macos-script.sh index d1480312fce..7f7ad13bcd2 100755 --- a/test/macos-script.sh +++ b/test/macos-script.sh @@ -10,6 +10,10 @@ brew install \ python3 -m pip install -r test/requirements.txt +oldpwd=$(pwd) +cp -a . /work +cd /work + export bashcomp_bash=bash env @@ -18,5 +22,5 @@ autoreconf -i make -j make distcheck \ - PYTESTFLAGS="${PYTESTFLAGS---verbose --numprocesses=auto --dist=loadfile}" + PYTESTFLAGS="${PYTESTFLAGS---verbose -p no:cacheprovider --numprocesses=auto --dist=loadfile}" cp -p bash-completion-*.tar.* "$oldpwd/" From 8f4360fdec442712a97e1320893dda8bf5d7368d Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Mon, 24 Feb 2025 22:43:21 +0200 Subject: [PATCH 05/15] ci(macos): Use venv instead of global install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit brew/python doesn't like installing python packages globally: ``` error: externally-managed-environment × This environment is externally managed ``` --- test/macos-script.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/macos-script.sh b/test/macos-script.sh index 7f7ad13bcd2..527759594e1 100755 --- a/test/macos-script.sh +++ b/test/macos-script.sh @@ -8,12 +8,15 @@ brew install \ automake \ bash -python3 -m pip install -r test/requirements.txt - oldpwd=$(pwd) cp -a . /work cd /work +python3 -m venv venv +#shellcheck disable=SC1091 +source venv/bin/activate +python3 -m pip install -r test/requirements.txt + export bashcomp_bash=bash env From 8fb9fc0370c383451c8e8c57e9260b1d8383c6dd Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Mon, 24 Feb 2025 22:46:12 +0200 Subject: [PATCH 06/15] ci: Don't move to /work --- test/macos-script.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/macos-script.sh b/test/macos-script.sh index 527759594e1..6cc067e4149 100755 --- a/test/macos-script.sh +++ b/test/macos-script.sh @@ -9,8 +9,6 @@ brew install \ bash oldpwd=$(pwd) -cp -a . /work -cd /work python3 -m venv venv #shellcheck disable=SC1091 @@ -26,4 +24,3 @@ make -j make distcheck \ PYTESTFLAGS="${PYTESTFLAGS---verbose -p no:cacheprovider --numprocesses=auto --dist=loadfile}" -cp -p bash-completion-*.tar.* "$oldpwd/" From 21c30751b50b09cab7124ce917d2931cdd99a2ed Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Tue, 25 Feb 2025 21:30:50 +0200 Subject: [PATCH 07/15] ci(macos): Force colored output --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b5ca7e5fff6..d9c76f57f68 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -99,4 +99,4 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v4 - - run: env PYTESTFLAGS="--verbose -p no:cacheprovider" test/macos-script.sh + - run: env PYTESTFLAGS="--verbose -p no:cacheprovider --color=yes" test/macos-script.sh From 74678c53f2feb15cb8d7202322f498843c194904 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Tue, 25 Feb 2025 21:37:49 +0200 Subject: [PATCH 08/15] REMOVE BEFORE MERGE: ignore errors for rmtree --- test/t/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/t/conftest.py b/test/t/conftest.py index 8d38d873990..bbd6b1abb36 100644 --- a/test/t/conftest.py +++ b/test/t/conftest.py @@ -951,7 +951,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: From 0eabf4fc7bb03caa9557465eab2c45eb1a9481b8 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Fri, 4 Jul 2025 14:33:47 +0300 Subject: [PATCH 09/15] test(make): Move file deletion to a fixture --- test/t/test_make.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/t/test_make.py b/test/t/test_make.py index 34fc7e5906a..e1014ccf63b 100644 --- a/test/t/test_make.py +++ b/test/t/test_make.py @@ -6,20 +6,23 @@ class TestMake: + @pytest.fixture + def remove_extra_makefile(self, bash): + yield + 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): @@ -30,24 +33,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): From 153fcc26ad8b9ae8b5b13d70fb952293e7c43a3a Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Fri, 4 Jul 2025 15:46:33 +0300 Subject: [PATCH 10/15] test(macos): Don't delete extra_makefile on macos For some reason, even though the test succeeds, the actual file isn't created like on linux. Maybe about versions/implementations of make? --- test/t/test_make.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/t/test_make.py b/test/t/test_make.py index e1014ccf63b..4af4285b665 100644 --- a/test/t/test_make.py +++ b/test/t/test_make.py @@ -1,4 +1,5 @@ import os +import sys import pytest @@ -9,7 +10,9 @@ class TestMake: @pytest.fixture def remove_extra_makefile(self, bash): yield - os.remove(f"{bash.cwd}/make/extra_makefile") + # 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): From 8f5fff171c863e8d5bba08cfe81a99c494b3bc7d Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Fri, 4 Jul 2025 16:46:12 +0300 Subject: [PATCH 11/15] test(glob): Normalize some strings to compare Some of the files have unicode characters that can be represented in multiple ways, so we normalize them. Specifically: 'e\u0301' ('e' + 'Combining Acute Accent') doesn't equal '\xe9' (LATIN SMALL LETTER E WITH ACUTE) unless you normalize them. --- test/t/unit/test_unit_expand_glob.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/test/t/unit/test_unit_expand_glob.py b/test/t/unit/test_unit_expand_glob.py index 7c1bcde3f9c..480fd37d0a8 100644 --- a/test/t/unit/test_unit_expand_glob.py +++ b/test/t/unit/test_unit_expand_glob.py @@ -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", @@ -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() - == "" + assert normalize(output.strip()) == normalize( + "" ) def test_match_pattern(self, bash, functions): output = assert_bash_exec(bash, "__tester 'a*'", want_output=True) - assert output.strip() == "" + assert normalize(output.strip()) == normalize( + "" + ) def test_match_unmatched(self, bash, functions): output = assert_bash_exec( @@ -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() == "" + assert normalize(output.strip()) == normalize( + "" + ) def test_protect_from_failglob(self, bash, functions): with bash_env_saved(bash) as bash_env: @@ -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() == "" + assert normalize(output.strip()) == normalize( + "" + ) From dd4674ef558e356fd8bb1cac9f5bf506e8dcfbb0 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Fri, 4 Jul 2025 17:08:34 +0300 Subject: [PATCH 12/15] test(vipw): Drop exception for macos vipw seems to have -d as an option on macos now. Partially reverts ccf7bf69d "test(dmesg,vipw): expect no options on macOS" --- test/t/test_vipw.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/t/test_vipw.py b/test/t/test_vipw.py index b78fcbda8b0..07b454bff4f 100644 --- a/test/t/test_vipw.py +++ b/test/t/test_vipw.py @@ -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 From 8fbd9b64447887ceff4642c7bb30ccaa93388f8a Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Fri, 4 Jul 2025 19:12:12 +0300 Subject: [PATCH 13/15] DEBUG: test ps output --- test/t/test_ps.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/t/test_ps.py b/test/t/test_ps.py index a6bfec13c7c..56378fbaff7 100644 --- a/test/t/test_ps.py +++ b/test/t/test_ps.py @@ -1,5 +1,7 @@ import pytest +from conftest import assert_bash_exec + def is_int(s): try: @@ -35,7 +37,9 @@ def test_4(self, completion): assert not completion @pytest.mark.complete("ps --pid ") - def test_5(self, completion): + def test_5(self, completion, bash): + ps_pid_output = assert_bash_exec(bash, "command ps ax -o pid=", want_output=True) + print("\n=====PS output=====\n", ps_pid_output, "\n======PS output end=====\n") assert completion assert all(map(is_int, completion)) From a9b3d6034a95792196803a533db7aa90e40347b4 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Fri, 4 Jul 2025 18:54:53 +0300 Subject: [PATCH 14/15] fix(patch, truncate): Get help correctly on macos The usage output on macos is in bsd style, not gnu style --- completions/patch | 6 +++++- completions/truncate | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/completions/patch b/completions/patch index bba184ceb4a..6e24f64640d 100644 --- a/completions/patch +++ b/completions/patch @@ -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 diff --git a/completions/truncate b/completions/truncate index 94534a285bc..f8eddde2e6f 100644 --- a/completions/truncate +++ b/completions/truncate @@ -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 From 2e6e2c9e3997e2ebb5e455386dbb2703974dfe92 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Sun, 6 Jul 2025 22:44:18 +0300 Subject: [PATCH 15/15] DEBUG: tar set -x --- .github/workflows/ci.yaml | 2 +- completions/tar | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d9c76f57f68..e7074eae1f1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -99,4 +99,4 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v4 - - run: env PYTESTFLAGS="--verbose -p no:cacheprovider --color=yes" test/macos-script.sh + - run: env PYTESTFLAGS="--verbose -p no:cacheprovider --color=yes -k '(TestTar and test_25) or TestPs'" test/macos-script.sh diff --git a/completions/tar b/completions/tar index e4423b154bb..8b95653fbe9 100644 --- a/completions/tar +++ b/completions/tar @@ -299,6 +299,7 @@ _comp_cmd_tar__preparse_cmdline() # Generate completions for -f/--file. _comp_cmd_tar__file_option() { + set -x local ext="$1" case "$tar_mode" in @@ -510,6 +511,7 @@ _comp_cmd_tar__is_bsdtar() _comp_cmd_tar__detect_ext() { + set -x local tars='@(@(tar|spkg)?(.@(Z|[bgx]z|bz2|lz?(ma|o)|zst))|t@([abglx]z|b?(z)2|zst)|cbt|gem|xbps)' if _comp_cmd_tar__is_bsdtar; then # https://github.com/libarchive/libarchive/wiki/LibarchiveFormats @@ -787,6 +789,7 @@ _comp_cmd_tar__posix() local ext + set -x _comp_cmd_tar__detect_ext _comp_cmd_tar__adjust_PREV_from_old_option