Skip to content
Merged
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
47 changes: 47 additions & 0 deletions .github/workflows/test-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: "ZUnit (Zsh matrix)"

on:
schedule:
- cron: "0 3 * * 3"
workflow_dispatch: {}

permissions:
contents: read

jobs:
zunit-matrix:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
zsh_version: ["5.5.1", "5.6.2", "5.7.1", "5.8", "5.8.1", "5.9"]
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v4
- name: Build test image
run: |
cat > Dockerfile.ci <<'EOF'
FROM alpine:3.20
ARG ZSH_VERSION
RUN apk add --no-cache autoconf gcc make musl-dev ncurses-dev curl git xz yodl
RUN curl -fsSL --retry 3 --retry-delay 5 "https://sourceforge.net/projects/zsh/files/zsh/${ZSH_VERSION}/zsh-${ZSH_VERSION}.tar.xz/download" -o /tmp/zsh.tar.xz \
&& tar -C /tmp -xf /tmp/zsh.tar.xz \
&& cd "/tmp/zsh-${ZSH_VERSION}" \
&& ./configure --prefix=/usr/local \
&& make \
&& make install
RUN mkdir -p /opt/zunit/.bin \
&& curl -fsSL 'https://raw.githubusercontent.com/zdharma/revolver/master/revolver' > /opt/zunit/.bin/revolver \
&& curl -fsSL 'https://raw.githubusercontent.com/zdharma/color/master/color.zsh' > /opt/zunit/.bin/color \
&& chmod u+x /opt/zunit/.bin/{color,revolver}
WORKDIR /opt/zunit
EOF
docker build --build-arg ZSH_VERSION="${{ matrix.zsh_version }}" -f Dockerfile.ci -t "zunit-ci:${{ matrix.zsh_version }}" .
- name: Run tests
run: |
docker run --rm \
--volume "$PWD:/opt/zunit" \
--workdir /opt/zunit \
"zunit-ci:${{ matrix.zsh_version }}" \
sh -lc 'export PATH="/opt/zunit/.bin:$PATH"; ./build.zsh >/dev/null; ./zunit --tap tests'
32 changes: 32 additions & 0 deletions .github/workflows/test-native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: "ZUnit (native)"

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "0 12 * * 1"
workflow_dispatch: {}

permissions:
contents: read

jobs:
zunit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -yq zsh
mkdir -p .bin
curl -fsSL 'https://raw.githubusercontent.com/zdharma/revolver/master/revolver' > .bin/revolver
curl -fsSL 'https://raw.githubusercontent.com/zdharma/color/master/color.zsh' > .bin/color
chmod u+x .bin/{color,revolver}
- name: Build
run: ./build.zsh
- name: Run test suite
run: PATH="$PWD/.bin:$PATH" ./zunit --tap tests
27 changes: 27 additions & 0 deletions .github/workflows/zsh-n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: "✅ Zsh Check"

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: {}

permissions:
contents: read

jobs:
zsh-n:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install zsh
run: sudo apt-get update && sudo apt-get install -yq zsh
- name: Check Zsh syntax
run: |
find src -type f -name '*.zsh' -print | sort | while read -r file; do
zsh -n "$file"
done
zsh -n build.zsh
zsh -n zunit.zsh-completion
38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
![ZUnit](https://zunit.xyz/img/logo.png)

[![GitHub release](https://img.shields.io/github/release/zunit-zsh/zunit.svg)](https://github.com/zunit-zsh/zunit/releases/latest) [![Build Status](https://travis-ci.org/zunit-zsh/zunit.svg?branch=master)](https://travis-ci.org/zunit-zsh/zunit) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/zunit-zsh/zunit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![GitHub release](https://img.shields.io/github/release/zunit-zsh/zunit.svg)](https://github.com/zunit-zsh/zunit/releases/latest) [![ZUnit (native)](https://github.com/z-shell/zunit/actions/workflows/test-native.yml/badge.svg)](https://github.com/z-shell/zunit/actions/workflows/test-native.yml) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/zunit-zsh/zunit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

ZUnit is a powerful unit testing framework for ZSH
ZUnit is a powerful unit testing framework for ZSH.

This repository is maintained by the Z-Shell organization as the active
workspace mirror used by the wider Zi/Z-Shell ecosystem. Historical upstream
links are preserved where they still describe the original project, while
runtime integrations continue to follow the currently published package
coordinates used across the ecosystem.

> **Note:** The install snippets below intentionally reference `zdharma/zunit`
> and `zdharma/revolver` — those are the package coordinates that zplug,
> Homebrew, and related tooling still resolve at runtime. The `z-shell/zunit`
> repository (where this README and the CI badges live) is the active
> development mirror; the `zdharma/*` names are preserved to avoid breaking
> existing user configurations.

## Maintenance

The Z-Shell mirror validates the project with GitHub Actions using native tests,
Zsh syntax checks, and a scheduled Zsh compatibility matrix. The matrix follows
the versions used by the surrounding Z-Shell test infrastructure so downstream
projects can rely on the same compatibility baseline.
Comment thread
ss-o marked this conversation as resolved.

## Installation

Expand All @@ -27,10 +47,10 @@ zulu install zunit
ZUnit and its dependencies can all be installed with zplug.

```sh
zplug 'molovo/revolver', \
zplug 'zdharma/revolver', \
as:command, \
use:revolver
zplug 'zunit-zsh/zunit', \
zplug 'zdharma/zunit', \
as:command, \
use:zunit, \
hook-build:'./build.zsh'
Expand All @@ -46,14 +66,14 @@ brew install zunit-zsh/zunit/zunit
### Manual

```sh
git clone https://github.com/zunit-zsh/zunit
git clone https://github.com/zdharma/zunit
cd ./zunit
./build.zsh
chmod u+x ./zunit
cp ./zunit /usr/local/bin
```

> ZUnit requires [Revolver](https://github.com/molovo/revolver) to be installed, and in your `$PATH`. The zulu or homebrew installation methods will install this dependency for you.
> ZUnit requires [Revolver](https://github.com/zdharma/revolver) to be installed, and in your `$PATH`. The zulu or homebrew installation methods will install this dependency for you.

## Writing Tests

Expand All @@ -71,6 +91,12 @@ Tests in ZUnit have a simple syntax, which is inspired by the [BATS](https://git

The body of each test can contain any valid ZSH code. The zunit shebang `#!/usr/bin/env zunit` **MUST** appear at the top of each test file, or ZUnit will not run it.

To bootstrap a new project with a current CI example, run:

```sh
zunit init --github-actions
```

## Documentation

For a full breakdown of ZUnit's syntax and functionality, check out the [official documentation](https://zunit.xyz/docs/).
Expand Down
2 changes: 2 additions & 0 deletions build.zsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env zsh
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et

# Clear the file to start with
cat /dev/null > zunit
Expand Down
2 changes: 2 additions & 0 deletions src/assertions.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
################################
# Internal assertion functions #
################################
Expand Down
61 changes: 54 additions & 7 deletions src/commands/init.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
############################
# The 'zunit init' command #
############################
Expand All @@ -10,9 +12,10 @@ function _zunit_init_usage() {
echo " zunit init [options]"
echo
echo "$(color yellow 'Options:')"
echo " -h, --help Output help text and exit"
echo " -v, --version Output version information and exit"
echo " -t, --travis Generate .travis.yml in project"
echo " -h, --help Output help text and exit"
echo " -v, --version Output version information and exit"
echo " -g, --github-actions Generate .github/workflows/zunit.yml in project"
echo " -t, --travis Generate legacy .travis.yml in project"
}

###
Expand All @@ -38,9 +41,11 @@ function _zunit_parse_yaml() {
}

function _zunit_init() {
local with_travis
local with_github_actions with_travis zunit_version

zparseopts -D t=with_travis -travis=with_travis
zparseopts -D \
g=with_github_actions -github-actions=with_github_actions \
t=with_travis -travis=with_travis

# The contents of .zunit.yml
local yaml="tap: false
Expand Down Expand Up @@ -72,13 +77,44 @@ allow_risky: false"
install:
- mkdir .bin
- curl -L https://github.com/zunit-zsh/zunit/releases/download/v$(_zunit_version)/zunit > .bin/zunit
- curl -L https://raw.githubusercontent.com/molovo/revolver/master/revolver > .bin/revolver
- curl -L https://raw.githubusercontent.com/molovo/color/master/color.zsh > .bin/color
- curl -L https://raw.githubusercontent.com/zdharma/revolver/master/revolver > .bin/revolver
- curl -L https://raw.githubusercontent.com/zdharma/color/master/color.zsh > .bin/color
before_script:
- chmod u+x .bin/{color,revolver,zunit}
- export PATH=\"\$PWD/.bin:\$PATH\"
script: zunit"

zunit_version="$(_zunit_version)"

# An example GitHub Actions workflow
local github_actions_yml="---
name: \"ZUnit\"

on:
push:
pull_request:
workflow_dispatch: {}

permissions:
contents: read

jobs:
zunit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -yq zsh
mkdir -p .bin
curl -fsSL 'https://github.com/zunit-zsh/zunit/releases/download/v${zunit_version}/zunit' > .bin/zunit
curl -fsSL 'https://raw.githubusercontent.com/zdharma/revolver/master/revolver' > .bin/revolver
curl -fsSL 'https://raw.githubusercontent.com/zdharma/color/master/color.zsh' > .bin/color
chmod u+x .bin/{color,revolver,zunit}
- name: Test
run: PATH=\"\$PWD/.bin:\$PATH\" zunit --tap tests"

# Check that a config file doesn't already exist so that
# we don't overwrite it
if [[ -f "$PWD/.zunit.yml" ]]; then
Expand All @@ -104,6 +140,17 @@ script: zunit"
echo "$example" > "$PWD/tests/example.zunit"
fi

# If GitHub Actions config has been requested
if [[ -n $with_github_actions ]]; then
if [[ -f "$PWD/.github/workflows/zunit.yml" ]]; then
echo $(color yellow "GitHub Actions workflow already exists at $PWD/.github/workflows/zunit.yml. Skipping...")
else
echo "Writing GitHub Actions workflow to $PWD/.github/workflows/zunit.yml"
mkdir -p "$PWD/.github/workflows"
echo "$github_actions_yml" > "$PWD/.github/workflows/zunit.yml"
fi
fi

# If travis config has been requested
if [[ -n $with_travis ]]; then
# Check that a travis config doesn't already exist so that
Expand Down
6 changes: 4 additions & 2 deletions src/commands/run.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
###########################
# The 'zunit run' command #
###########################
Expand All @@ -17,7 +19,7 @@ function _zunit_run_usage() {
echo " --verbose Prints full output from each test"
echo " --output-text Print results to a text log, in TAP compatible format"
echo " --output-html Print results to a HTML page"
echo " --allow-risky Supress warnings generated for risky tests"
echo " --allow-risky Suppress warnings generated for risky tests"
echo " --time-limit <n> Set a time limit of n seconds for each test"
}

Expand Down Expand Up @@ -475,7 +477,7 @@ function _zunit_run() {
# Make sure we have a config file, otherwise we can't determine
# which directory to write logs to
if [[ $missing_config -eq 1 ]]; then
echo $(color red '.zunit.yml could not be found. Run `zulu init`')
echo $(color red '.zunit.yml could not be found. Run `zunit init`')
exit 1
fi

Expand Down
2 changes: 2 additions & 0 deletions src/events.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
##########################################
# Functions for handling internal events #
##########################################
Expand Down
2 changes: 2 additions & 0 deletions src/helpers.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
################################
# Helpers for use within tests #
################################
Expand Down
Loading
Loading