Skip to content

Commit

Permalink
Test running tests on WSL
Browse files Browse the repository at this point in the history
  • Loading branch information
erijo committed Jan 9, 2025
1 parent 1d69ce3 commit b991981
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 33 deletions.
82 changes: 56 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,68 @@ jobs:
- ubuntu-24.04
- macos-13
- macos-15
- windows-2022

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v4

- uses: Vampire/setup-wsl@v4
if: ${{ runner.os == 'Windows' }}

- name: Install dependencies on Linux
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt-get update
sudo apt-get install -y expect
if [ "${{ matrix.os }}" != "ubuntu-20.04" ]; then
sudo apt-get install -y j2cli
fi
sudo apt-get install -y \
expect \
${{ matrix.os != 'ubuntu-20.04' && 'j2cli' || '' }}
- name: Install dependencies on macOS
if: ${{ runner.os == 'macOS' }}
run: |
command -v expect || brew install expect
- name: Install dependencies on Windows (WSL)
if: ${{ runner.os == 'Windows' }}
shell: wsl-bash {0}
run: |
apt-get update
apt-get install -y --no-install-recommends \
dos2unix \
expect \
gettext-base \
git \
gnupg \
j2cli \
lsb-release \
man \
python3-pip
- name: Prepare tools directory
run: |
mkdir "$RUNNER_TEMP/tools"
echo "$RUNNER_TEMP/tools" >> "$GITHUB_PATH"
mkdir "${{ runner.temp }}/tools"
echo "${{ runner.temp }}/tools" >> "${{ github.path }}"
- name: Install shellcheck
run: |
if [ "$RUNNER_OS" = "macOS" ]; then
OS=darwin
else
OS=linux
fi
if [ "$RUNNER_ARCH" = "ARM64" ]; then
ARCH=aarch64
else
ARCH=x86_64
fi
cd "${{ runner.temp }}"
cd "$RUNNER_TEMP"
OS=${{ runner.os == 'macOS' && 'darwin' || 'linux' }}
ARCH=${{ runner.arch == 'ARM64' && 'aarch64' || 'x86_64' }}
BASE_URL="https://github.com/koalaman/shellcheck/releases/download"
SC="v$SC_VER/shellcheck-v$SC_VER.$OS.$ARCH.tar.xz"
curl -L "$BASE_URL/$SC" | tar Jx shellcheck-v$SC_VER/shellcheck
mv shellcheck-v$SC_VER/shellcheck tools
- name: Install esh
run: |
cd "$RUNNER_TEMP/tools"
cd "${{ runner.temp }}/tools"
BASE_URL="https://github.com/jirutka/esh/raw/refs/tags"
curl -L -o esh "$BASE_URL/v$ESH_VER/esh"
Expand All @@ -76,8 +92,9 @@ jobs:
run: |
for version in 1.12.0 2.5.0; do
git fetch origin $version:refs/tags/$version
git cat-file blob $version:yadm > "$RUNNER_TEMP/tools/yadm-$version"
chmod +x "$RUNNER_TEMP/tools/yadm-$version"
git cat-file blob $version:yadm \
> "${{ runner.temp }}/tools/yadm-$version"
chmod +x "${{ runner.temp }}/tools/yadm-$version"
done
- name: Set up Python 3.11
Expand All @@ -86,13 +103,26 @@ jobs:
with:
python-version: 3.11

- name: Install Python dependencies
- name: Install dependencies and run tests
if: ${{ runner.os != 'Windows' }}
run: |
python -m pip install --upgrade pip
python -m pip install -r test/requirements.txt
git config --global user.email [email protected]
git config --global user.name "Yadm Test"
- name: Run tests
python3 -m pip install --upgrade pip
python3 -m pip install -r test/requirements.txt
pytest -v --color=yes --basetemp="${{ runner.temp }}/pytest"
- name: Install dependencies and run tests
if: ${{ runner.os == 'Windows' }}
shell: wsl-bash {0}
run: |
git config --global user.email [email protected]
git config --global user.name "Yadm Test"
pytest -v --color=yes --basetemp="$RUNNER_TEMP/pytest"
dos2unix yadm.1 .github/workflows/*.yml test/pinentry-mock
chmod +x test/pinentry-mock
python3 -m pip install --upgrade pip
python3 -m pip install -r test/requirements.txt
pytest -v --color=yes
22 changes: 17 additions & 5 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,31 @@ def tst_distro(runner):


@pytest.fixture(scope="session")
def tst_distro_family(runner):
def tst_distro_family():
"""Test session's distro_family"""
family = ""
with contextlib.suppress(Exception):
run = runner(command=["grep", "-oP", r"ID_LIKE=\K.+", "/etc/os-release"], report=False)
family = run.out.strip()
return family
with open("/etc/os-release", encoding="utf-8") as f:
for line in f.readlines():
if line.startswith("ID_LIKE="):
family = line[8:]
break
if line.startswith("ID="):
family = line[3:]
# No break, only used as fallback in case ID_LIKE isn't found
return family.replace('"', "").rstrip()


@pytest.fixture(scope="session")
def tst_sys():
"""Test session's uname value"""
return platform.system()
system = platform.system()
if system == "Linux":
# Additional check for WSL
with open("/proc/version", encoding="utf-8") as f:
if "icrosoft" in f.read():
return "WSL"
return system


@pytest.fixture(scope="session")
Expand Down
2 changes: 1 addition & 1 deletion test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_man(runner):
if shutil.which("mandoc"):
command = ["mandoc", "-T", "lint"]
else:
command = ["groff", "-ww", "-z"]
command = ["groff", "-K", "utf-8", "-ww", "-z"]
run = runner(command=command + ["-man", "./yadm.1"])
assert run.success
assert run.out == ""
Expand Down
2 changes: 1 addition & 1 deletion test/test_unit_set_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ def test_set_operating_system(runner, paths, tst_sys, proc_value, expected_os):
assert run.success
assert run.err == ""
if expected_os == "uname":
expected_os = tst_sys
expected_os = tst_sys if tst_sys != "WSL" else "Linux"
assert run.out.rstrip() == expected_os

0 comments on commit b991981

Please sign in to comment.