Skip to content

Commit

Permalink
Test running tests directly on action runner
Browse files Browse the repository at this point in the history
To be able to test on different systems.
  • Loading branch information
erijo committed Nov 18, 2024
1 parent 30fa6f0 commit 8f1a0cb
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 94 deletions.
93 changes: 89 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,98 @@
---
name: Tests

on: # yamllint disable-line rule:truthy
- push
- pull_request
- workflow_dispatch

env:
SC_VER: "0.10.0"
ESH_VER: "0.3.2"

jobs:
Tests:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- ubuntu-24.04
- macos-13
- macos-15
steps:
- uses: actions/checkout@v2
- name: Tests
run: make test
- uses: actions/checkout@v4

- 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
- name: Install dependencies on macOS
if: ${{ runner.os == 'macOS' }}
run: |
brew install expect
- name: Prepare tools directory
run: |
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"
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"
BASE_URL="https://github.com/jirutka/esh/raw/refs/tags"
curl -L -o esh "$BASE_URL/v$ESH_VER/esh"
chmod +x esh
- name: Add old yadm versions # to test upgrades
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"
done
- name: Set up Python 3.11
if: ${{ runner.os == 'macOS' }}
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r test/requirements.txt
- name: Run tests
run: |
git config --global user.email test@yadm.io
git config --global user.name "Yadm Test"
pytest -v --color=yes --basetemp="$RUNNER_TEMP/pytest"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.testyadm
_site
testenv
__pycache__/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ man-ps:
@groff -man -Tps ./yadm.1 > yadm.ps

yadm.md: yadm.1
@groff -man -Tutf8 -Z ./yadm.1 | grotty -c | col -bx | sed 's/^[A-Z]/## &/g' | sed '/yadm(1)/d' > yadm.md
@groff -man -Tutf8 -Z ./yadm.1 | grotty -c | col -bx | sed 's/^[A-Z]/## &/g' | sed '/YADM(1)/d' > yadm.md

.PHONY: contrib
contrib: SHELL = /bin/bash
Expand Down
9 changes: 7 additions & 2 deletions test/test_syntax.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Syntax checks"""

import os
import shutil

import pytest

Expand Down Expand Up @@ -77,7 +78,11 @@ def test_yamllint(pytestconfig, runner, yamllint_version):

def test_man(runner):
"""Check for warnings from man"""
run = runner(command=["man.REAL", "--warnings", "./yadm.1"])
if shutil.which("mandoc"):
command = ["mandoc", "-T", "lint"]
else:
command = ["groff", "-ww", "-z"]
run = runner(command=command + ["-man", "./yadm.1"])
assert run.success
assert run.out == ""
assert run.err == ""
assert "yadm - Yet Another Dotfiles Manager" in run.out
4 changes: 3 additions & 1 deletion test/test_unit_configure_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def run_test(runner, paths, args, expected_matches, cwd=None):
XDG_DATA_HOME=
HOME="{HOME}" set_yadm_dirs
configure_paths
declare -p | grep -E '(YADM|GIT)_'
for var in "${{!YADM_@}}" "${{!GIT_@}}"; do
echo "$var=\\"${{!var}}\\""
done
"""
run = runner(command=["bash"], inp=script, cwd=cwd)
assert run.success
Expand Down
23 changes: 13 additions & 10 deletions test/test_unit_parse_encrypt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Unit tests: parse_encrypt"""

import sys

import pytest


Expand Down Expand Up @@ -123,16 +125,17 @@ def create_test_encrypt_data(paths):
expected.add("ex ex/file4")
expected.add("ex ex/file6.text")

# double star
edata += "doublestar/**/file*\n"
edata += "!**/file3\n"
paths.work.join("doublestar/a/b/file1").write("", ensure=True)
paths.work.join("doublestar/c/d/file2").write("", ensure=True)
paths.work.join("doublestar/e/f/file3").write("", ensure=True)
paths.work.join("doublestar/g/h/nomatch").write("", ensure=True)
expected.add("doublestar/a/b/file1")
expected.add("doublestar/c/d/file2")
# doublestar/e/f/file3 is excluded
# double star (not supported on bash 3 which is the default on macOS)
if sys.platform != "darwin":
edata += "doublestar/**/file*\n"
edata += "!**/file3\n"
paths.work.join("doublestar/a/b/file1").write("", ensure=True)
paths.work.join("doublestar/c/d/file2").write("", ensure=True)
paths.work.join("doublestar/e/f/file3").write("", ensure=True)
paths.work.join("doublestar/g/h/nomatch").write("", ensure=True)
expected.add("doublestar/a/b/file1")
expected.add("doublestar/c/d/file2")
# doublestar/e/f/file3 is excluded

return edata, expected

Expand Down
6 changes: 4 additions & 2 deletions test/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
],
)
@pytest.mark.parametrize("submodule", [False, True], ids=["no submodule", "with submodules"])
def test_upgrade(tmpdir, runner, versions, submodule):
def test_upgrade(tmpdir, runner, paths, versions, submodule):
"""Upgrade tests"""
# pylint: disable=too-many-statements
home = tmpdir.mkdir("HOME")
env = {"HOME": str(home)}
runner(["git", "config", "--global", "init.defaultBranch", "master"], env=env)
runner(["git", "config", "--global", "protocol.file.allow", "always"], env=env)
runner(["git", "config", "--global", "user.email", "test@yadm.io"], env=env)
runner(["git", "config", "--global", "user.name", "Yadm Test"], env=env)

if submodule:
ext_repo = tmpdir.mkdir("ext_repo")
Expand All @@ -39,7 +41,7 @@ def test_upgrade(tmpdir, runner, versions, submodule):
os.environ.pop("XDG_DATA_HOME", None)

def run_version(version, *args, check_stderr=True):
yadm = f"yadm-{version}" if version else "/yadm/yadm"
yadm = f"yadm-{version}" if version else paths.pgm
run = runner([yadm, *args], shell=True, cwd=str(home), env=env)
assert run.success
if check_stderr:
Expand Down
Loading

0 comments on commit 8f1a0cb

Please sign in to comment.