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
4 changes: 1 addition & 3 deletions .github/workflows/test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ jobs:
&& ./configure --prefix=/usr/local \
&& make \
&& make install
RUN mkdir -p /opt/zunit/.bin \
&& 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 }}" .
Expand All @@ -42,4 +40,4 @@ jobs:
--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'
sh -lc 'zsh build.zsh >/dev/null && ./zunit --tap tests'
6 changes: 2 additions & 4 deletions .github/workflows/test-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -yq zsh
mkdir -p .bin
chmod u+x .bin/{color,revolver}
- name: Build
run: ./build.zsh
run: zsh build.zsh
- name: Run test suite
run: PATH="$PWD/.bin:$PATH" ./zunit --tap tests
run: ./zunit --tap tests
9 changes: 9 additions & 0 deletions .zunit.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ZUnit configuration
ZUNIT_TESTS_DIR='tests'
ZUNIT_OUTPUT_DIR='tests/_output'
ZUNIT_SUPPORT_DIR='tests/_support'
ZUNIT_FAIL_FAST=false
ZUNIT_ALLOW_RISKY=false
ZUNIT_TIME_LIMIT=15
ZUNIT_TAP=false
ZUNIT_VERBOSE=false
2 changes: 0 additions & 2 deletions lib/color.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ function _zunit_color() {
*) echo "\033[${b};38;5;$(( ${color} ))m${@}\033[0;m" ;;
esac
}

color "$@"
34 changes: 17 additions & 17 deletions lib/revolver.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ revolver_spinners=(
###
# Output usage information and exit
###
function revolver_usage() {
function _zunit_revolver_usage() {
echo "\033[0;33mUsage:\033[0;m"
echo " revolver [options] <command> <message>"
echo
Expand All @@ -85,7 +85,7 @@ function revolver_usage() {
###
# The main revolver process, which contains the loop
###
function revolver_process() {
function _zunit_revolver_process() {
local dir statefile state msg pid="$1" spinner_index=0

# Find the directory and load the statefile
Expand Down Expand Up @@ -123,15 +123,15 @@ function revolver_process() {

# Output the current spinner frame, and add a
# slight delay before the next one
revolver_spin
_zunit_revolver_spin
sleep ${interval:-"0.1"}
done
}

###
# Output the spinner itself, along with a message
###
function revolver_spin() {
function _zunit_revolver_spin() {
local dir statefile state pid frame

# ZSH arrays start at 1, so we need to bump the index if it's 0
Expand Down Expand Up @@ -162,12 +162,12 @@ function revolver_spin() {
###
# Stop the current spinner process
###
function revolver_stop() {
function _zunit_revolver_stop() {
local dir statefile state pid

# Find the directory and load the statefile
dir=${REVOLVER_DIR:-"${ZDOTDIR:-$HOME}/.revolver"}
statefile="$dir/$PPID"
statefile="$dir/$$"

# If the statefile does not exist, raise an error.
# The spinner process itself performs the same check
Expand Down Expand Up @@ -196,12 +196,12 @@ function revolver_stop() {

###
# Update the message being displayed
function revolver_update() {
function _zunit_revolver_update() {
local dir statefile state pid msg="$1"

# Find the directory and load the statefile
dir=${REVOLVER_DIR:-"${ZDOTDIR:-$HOME}/.revolver"}
statefile="$dir/$PPID"
statefile="$dir/$$"

# If the statefile does not exist, raise an error.
# The spinner process itself performs the same check
Expand All @@ -228,7 +228,7 @@ function revolver_update() {
###
# Create a new spinner with the specified message
###
function revolver_start() {
function _zunit_revolver_start() {
local dir statefile msg="$1"

# Find the directory and create it if it doesn't exist
Expand All @@ -238,7 +238,7 @@ function revolver_start() {
fi

# Create the filename for the statefile
statefile="$dir/$PPID"
statefile="$dir/$$"

touch $statefile
if [[ ! -f $statefile ]]; then
Expand All @@ -248,7 +248,7 @@ function revolver_start() {
fi

# Start the spinner process in the background
revolver_process $PPID &!
_zunit_revolver_process $$ &!

# Save the current state to the statefile
echo "$! $msg" >! $statefile
Expand All @@ -257,18 +257,18 @@ function revolver_start() {
###
# Demonstrate each of the included spinner styles
###
function revolver_demo() {
function _zunit_revolver_demo() {
for style in "${(@k)revolver_spinners[@]}"; do
revolver --style $style start $style
_zunit_revolver --style $style start $style
sleep 2
revolver stop
_zunit_revolver stop
done
}

###
# Handle command input
###
function revolver() {
function _zunit_revolver() {
# Get the context from the first parameter
local help version style ctx="$1"

Expand All @@ -280,7 +280,7 @@ function revolver() {

# Output usage information and exit
if [[ -n $help ]]; then
revolver_usage
_zunit_revolver_usage
exit 0
fi

Expand Down Expand Up @@ -308,7 +308,7 @@ function revolver() {
start|update|stop|demo)
# Check if a valid command is passed,
# and if so, run it
revolver_${ctx} "${(@)@:2}"
_zunit_revolver_${ctx} "${(@)@:2}"
;;
*)
# If the context is not recognised,
Expand Down
41 changes: 22 additions & 19 deletions src/commands/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# Output usage information and exit
###
function _zunit_init_usage() {
echo "($(_zunit_color yellow 'Usage:')"
echo "$(_zunit_color yellow 'Usage:')"
echo " zunit init [options]"
echo
echo "($(_zunit_color yellow 'Options:')"
echo "$(_zunit_color yellow 'Options:')"
echo " -h, --help Output help text and exit"
echo " -g, --github-actions Generate .github/workflows/zunit.yml in project"
echo " -t, --travis Generate legacy .travis.yml in project"
Expand Down Expand Up @@ -46,21 +46,22 @@ function _zunit_init() {
g=with_github_actions -github-actions=with_github_actions \
t=with_travis -travis=with_travis

# The contents of .zunit.yml
local yaml="tap: false
directories:
tests: tests
output: tests/_output
support: tests/_support
time_limit: 0
fail_fast: false
allow_risky: false"
# The contents of .zunit.zsh
local zunit_zsh="# ZUnit configuration
ZUNIT_TESTS_DIR='tests'
ZUNIT_OUTPUT_DIR='tests/_output'
ZUNIT_SUPPORT_DIR='tests/_support'
ZUNIT_FAIL_FAST=false
ZUNIT_ALLOW_RISKY=false
ZUNIT_TIME_LIMIT=0
ZUNIT_TAP=false
ZUNIT_VERBOSE=false"

# An example test file
local example="#!/usr/bin/env zunit

@test 'Example' {
assert "'"true"'" same_as "'"false"'"
assert \"true\" same_as \"true\"
}"

# An empty bootstrap script
Expand Down Expand Up @@ -112,18 +113,20 @@ jobs:

# Check that a config file doesn't already exist so that
# we don't overwrite it
if [[ -f "$PWD/.zunit.yml" ]]; then
echo ($(_zunit_color yellow "ZUnit config file already exists at $PWD/.zunit.yml. Skipping...")
if [[ -f "$PWD/.zunit.zsh" ]]; then
echo "$(_zunit_color yellow "ZUnit config file already exists at $PWD/.zunit.zsh. Skipping...")"
elif [[ -f "$PWD/.zunit.yml" ]]; then
echo "$(_zunit_color yellow "ZUnit config file already exists at $PWD/.zunit.yml. Skipping...")"
else
Comment thread
ss-o marked this conversation as resolved.
# Write the contents to the config file
echo "Writing ZUnit config file to $PWD/.zunit.yml"
echo "$yaml" > "$PWD/.zunit.yml"
echo "Writing ZUnit config file to $PWD/.zunit.zsh"
echo "$zunit_zsh" > "$PWD/.zunit.zsh"
fi

# Check that the tests directory doesn't already exist so that
# we don't overwrite it
if [[ -d "$PWD/tests" ]]; then
echo ($(_zunit_color yellow "Test directory already exists at $PWD/tests. Skipping...")
echo "$(_zunit_color yellow "Test directory already exists at $PWD/tests. Skipping...")"
else
Comment thread
ss-o marked this conversation as resolved.
echo "Creating test directory at $PWD/tests"
# Create the directory structure for tests
Expand All @@ -138,7 +141,7 @@ jobs:
# If GitHub Actions config has been requested
if [[ -n $with_github_actions ]]; then
if [[ -f "$PWD/.github/workflows/zunit.yml" ]]; then
echo ($(_zunit_color yellow "GitHub Actions workflow already exists at $PWD/.github/workflows/zunit.yml. Skipping...")
echo "$(_zunit_color yellow "GitHub Actions workflow already exists at $PWD/.github/workflows/zunit.yml. Skipping...")"
else
Comment thread
ss-o marked this conversation as resolved.
echo "Writing GitHub Actions workflow to $PWD/.github/workflows/zunit.yml"
mkdir -p "$PWD/.github/workflows"
Expand All @@ -151,7 +154,7 @@ jobs:
# Check that a travis config doesn't already exist so that
# we don't overwrite it
if [[ -f "$PWD/.travis.yml" ]]; then
echo ($(_zunit_color yellow "Travis config already exists at $PWD/.travis.yml. Skipping...")
echo "$(_zunit_color yellow "Travis config already exists at $PWD/.travis.yml. Skipping...")"
else
echo "Writing Travis CI config to $PWD/.travis.yml"
# Write the contents to the config file
Expand Down
Loading
Loading