From 85aa8edd05f32e05e5e46297ff9c8374b6e274de 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/11] 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 f3999114d63ad4a79ce890c018bd6da355ae6394 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/11] ci(macos): add macOS CI test config --- .github/workflows/ci.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dbd834c0726..7769d06e576 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -107,3 +107,11 @@ 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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: false + - run: env PYTESTFLAGS=--verbose test/macos-script.sh From a3545baf1bbd2d086f3e4b4a8a3999c89f5896f9 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Mon, 24 Feb 2025 22:36:34 +0200 Subject: [PATCH 03/11] ci(macos): Align macos script with current linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also use venv instead of global install brew/python doesn't like installing python packages globally: ``` error: externally-managed-environment × This environment is externally managed ``` --- .github/workflows/ci.yaml | 2 +- test/macos-script.sh | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7769d06e576..6572de2205f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -114,4 +114,4 @@ jobs: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: persist-credentials: false - - 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..d40142f66b4 100755 --- a/test/macos-script.sh +++ b/test/macos-script.sh @@ -8,6 +8,9 @@ brew install \ automake \ bash +python3 -m venv venv +#shellcheck disable=SC1091 +source venv/bin/activate python3 -m pip install -r test/requirements.txt export bashcomp_bash=bash @@ -18,5 +21,4 @@ autoreconf -i make -j make distcheck \ - PYTESTFLAGS="${PYTESTFLAGS---verbose --numprocesses=auto --dist=loadfile}" -cp -p bash-completion-*.tar.* "$oldpwd/" + PYTESTFLAGS="${PYTESTFLAGS---verbose -p no:cacheprovider --numprocesses=auto --dist=loadfile}" From 00b2cae051622bf38713bbc6bb09fa45fa8f8125 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Tue, 25 Feb 2025 21:30:50 +0200 Subject: [PATCH 04/11] 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 6572de2205f..a3ac8b686a5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -114,4 +114,4 @@ jobs: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: persist-credentials: false - - 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 00f7d90aba5e917e1d000af24dacf61665d362f6 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Fri, 4 Jul 2025 17:08:34 +0300 Subject: [PATCH 05/11] 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 8074741e7a7830a295f0c1ddbfd4115d3a0f7f3d Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Thu, 18 Sep 2025 20:26:36 +0300 Subject: [PATCH 06/11] test: Sort completion results items It seems there is some behaviour differences regarding the order completions are returned in between linux and macos, specifically regarding sorting of upper case and lowercase letters. Sorting them ourselves in the tests makes it consistent. --- test/t/conftest.py | 4 ++-- test/t/unit/test_unit_dequote.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/t/conftest.py b/test/t/conftest.py index dbd139df7ca..c13c46097f1 100644 --- a/test/t/conftest.py +++ b/test/t/conftest.py @@ -776,7 +776,7 @@ 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()]) def __eq__(self, expected: object) -> bool: """ @@ -791,7 +791,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() diff --git a/test/t/unit/test_unit_dequote.py b/test/t/unit/test_unit_dequote.py index 117a487758d..8b5b3a5ef54 100644 --- a/test/t/unit/test_unit_dequote.py +++ b/test/t/unit/test_unit_dequote.py @@ -1,3 +1,5 @@ +import re + import pytest from conftest import assert_bash_exec, bash_env_saved @@ -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() == "" + items = sorted(re.findall(r"<[^>]*>", output)) + assert "".join(items) == "" def test_7_quote_1(self, bash, functions): output = assert_bash_exec( From aaebd24bc919ec39a6915d6ec6f65c117cffb3b2 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Sun, 21 Sep 2025 16:10:15 +0300 Subject: [PATCH 07/11] test: Remove empty strings from completion results --- 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 c13c46097f1..991a21f04f2 100644 --- a/test/t/conftest.py +++ b/test/t/conftest.py @@ -776,7 +776,9 @@ def startswith(self, prefix: str) -> bool: return self.output.startswith(prefix) def _items(self) -> List[str]: - return sorted([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: """ From 57a88fd36fea68142ff033936de5a39d8e78a2ea Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Tue, 7 Oct 2025 22:21:04 +0300 Subject: [PATCH 08/11] test(tar): skip test_25 for non-gnu tar --- test/t/test_tar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/t/test_tar.py b/test/t/test_tar.py index 73db7c30905..8d03da296f0 100644 --- a/test/t/test_tar.py +++ b/test/t/test_tar.py @@ -129,7 +129,7 @@ def test_24(self, completion): # Test compression detection of gnu style options @pytest.mark.complete("tar --extract --xz --file ", cwd="tar") - def test_25(self, completion): + def test_25(self, completion, gnu_tar): assert completion == "archive.tar.xz dir/ dir2/".split() # TODO: "tar tf escape.tar a/b" From 14c8dce35a792bd9ac4600c9f9a75262e215f982 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Wed, 8 Oct 2025 00:20:25 +0300 Subject: [PATCH 09/11] test(unit_load): Delete files we create in fixture On macOS we need sudo to delete them, maybe because they were created by a different prcoess? --- test/t/unit/test_unit_load.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/t/unit/test_unit_load.py b/test/t/unit/test_unit_load.py index 5fcfda2dfe6..bfc8daf0706 100644 --- a/test/t/unit/test_unit_load.py +++ b/test/t/unit/test_unit_load.py @@ -1,4 +1,5 @@ import os +import sys import pytest @@ -33,7 +34,11 @@ def fixture_dir(self, request, bash): assert_bash_exec( bash, "ln -sf ../prefix1/sbin/cmd2 %s/bin/cmd2" % tmpdir ) - return str(tmpdir) + yield str(tmpdir) + if sys.platform == "darwin": + assert_bash_exec(bash, "sudo rm -rf %s/*" % tmpdir) + else: + assert_bash_exec(bash, "rm -rf %s/*" % tmpdir) def test_userdir_1(self, bash, fixture_dir): with bash_env_saved(bash) as bash_env: From 5d7913792db815ca90f18dee7d923504a1dc2ff3 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Sat, 18 Oct 2025 21:43:45 +0300 Subject: [PATCH 10/11] Revert "test: Sort completion results items" This reverts commit 8074741e7a7830a295f0c1ddbfd4115d3a0f7f3d. --- test/t/conftest.py | 6 ++---- test/t/unit/test_unit_dequote.py | 7 +++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/t/conftest.py b/test/t/conftest.py index 991a21f04f2..59f27d68dd7 100644 --- a/test/t/conftest.py +++ b/test/t/conftest.py @@ -776,9 +776,7 @@ def startswith(self, prefix: str) -> bool: return self.output.startswith(prefix) def _items(self) -> List[str]: - return sorted( - [x.strip() for x in self.output.strip().splitlines() if x] - ) + return [x.strip() for x in self.output.strip().splitlines() if x] def __eq__(self, expected: object) -> bool: """ @@ -793,7 +791,7 @@ def __eq__(self, expected: object) -> bool: return False else: expiter = expected - return self._items() == sorted(expiter) + return self._items() == expiter def __contains__(self, item: str) -> bool: return item in self._items() diff --git a/test/t/unit/test_unit_dequote.py b/test/t/unit/test_unit_dequote.py index 8b5b3a5ef54..e2a70d85910 100644 --- a/test/t/unit/test_unit_dequote.py +++ b/test/t/unit/test_unit_dequote.py @@ -1,5 +1,3 @@ -import re - import pytest from conftest import assert_bash_exec, bash_env_saved @@ -39,9 +37,10 @@ def test_5_brace(self, bash, functions): assert output.strip() == "" def test_6_glob(self, bash, functions): + LC_out = assert_bash_exec(bash, "env | grep LC_", want_output=True) + print(f"LC_ vars:\n\n{LC_out}\n") output = assert_bash_exec(bash, "__tester 'a?b'", want_output=True) - items = sorted(re.findall(r"<[^>]*>", output)) - assert "".join(items) == "" + assert output.strip() == "" def test_7_quote_1(self, bash, functions): output = assert_bash_exec( From e70aa4689b630bba7af2cefde2511772b4c0dfd6 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Sat, 25 Oct 2025 23:03:50 +0300 Subject: [PATCH 11/11] test(_comp_load): Copy files with python Instead of running bash commands, copy directories and create symlinks using pure python. This should hopefully make macos GHA not fail to delete these directories. --- test/t/unit/test_unit_load.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/test/t/unit/test_unit_load.py b/test/t/unit/test_unit_load.py index bfc8daf0706..53ab798570f 100644 --- a/test/t/unit/test_unit_load.py +++ b/test/t/unit/test_unit_load.py @@ -1,5 +1,5 @@ import os -import sys +import shutil import pytest @@ -25,20 +25,16 @@ def fixture_dir(self, request, bash): set up symbolic links. """ - tmpdir = prepare_fixture_dir(request, files=[], dirs=[]) - assert_bash_exec(bash, "cp -R %s/* %s/" % (os.getcwd(), tmpdir)) - assert_bash_exec(bash, "mkdir -p %s/bin" % tmpdir) - assert_bash_exec( - bash, "ln -sf ../prefix1/bin/cmd1 %s/bin/cmd1" % tmpdir - ) - assert_bash_exec( - bash, "ln -sf ../prefix1/sbin/cmd2 %s/bin/cmd2" % tmpdir - ) - yield str(tmpdir) - if sys.platform == "darwin": - assert_bash_exec(bash, "sudo rm -rf %s/*" % tmpdir) - else: - assert_bash_exec(bash, "rm -rf %s/*" % tmpdir) + tmpdir = prepare_fixture_dir(request, files=[], dirs=["bin"]) + try: + shutil.copytree(os.getcwd(), str(tmpdir), dirs_exist_ok=True) + except TypeError: # For python <= 3.7 + from distutils import dir_util # type: ignore[import-not-found] + + dir_util.copy_tree(os.getcwd(), str(tmpdir)) + os.symlink("../prefix1/bin/cmd1", f"{tmpdir}/bin/cmd1") + os.symlink("../prefix1/sbin/cmd2", f"{tmpdir}/bin/cmd2") + return str(tmpdir) def test_userdir_1(self, bash, fixture_dir): with bash_env_saved(bash) as bash_env: