Skip to content

Commit

Permalink
feat: build zunit via makefile (#12)
Browse files Browse the repository at this point in the history
* fix(build): remove build.zsh
* docs(readme): zinit install

---------

Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
  • Loading branch information
vladdoster committed Feb 20, 2024
1 parent 7c4cc63 commit b15c870
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 134 deletions.
114 changes: 114 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# vim: ft=make sw=4 ts=4 noet!

PREFIX ?= /usr/local
SHELL ?= sh

CRAM_OPTS ?= -v

PROJECT ?= $(CURDIR)
BIN ?= ${PROJECT}/bin
DOCS ?= ${PROJECT}/docs
SRC ?= ${PROJECT}/src
TESTS ?= ${PROJECT}/tests

ZSH_VERSION ?= zsh-5.8
CONTAINER_ROOT ?= /zunit
USE_CONTAINER ?= docker
CONTAINER_IMAGE ?= desyncr/zsh-docker-

PROG ?= ${BIN}/zunit
SRC ?= ${SRC}
GLOB ?=

LIB = $(filter-out ${SRC}/zunit.zsh,$(wildcard ${SRC}/*.zsh))
COMMANDS = $(sort $(wildcard ${SRC}/commands/*.zsh))
REPORTS = $(sort $(wildcard ${SRC}/reports/*.zsh))
GLOB += ${LIB} ${REPORTS} ${COMMANDS} ${SRC}/zunit.zsh

VERSION ?= develop
VERSION_FILE = ${PROJECT}/VERSION

BANNER_SEP = $(shell printf '%*s' 70 | tr ' ' '\#')
BANNER_TEXT = This file was autogenerated by \`make\`. Do not edit it directly!
BANNER = ${BANNER_SEP}\n\# ${BANNER_TEXT}\n${BANNER_SEP}\n
HEADER_TEXT =\
\#!/usr/bin/env zsh\n\
\# Zunit: A unit test framework for zsh\n\
\# License: MIT License\n
define ised
sed $(1) $(2) > "$(2).1"
mv "$(2).1" "$(2)"
endef
define isede
sed -E $(1) $(2) > "$(2).1"
mv "$(2).1" "$(2)"
endef
.PHONY: all build clean install itests tests uninstall
all: build
release:
git checkout develop
git checkout -b release/${VERSION}
${MAKE} build tests
${EDITOR} CHANGELOG.md
git add CHANGELOG.md README.mkd ${VERSION_FILE}
git commit -S -m "Update changelog for ${VERSION}"
git add ${PROG}
git commit -S -m "Build release ${VERSION}"
publish:
git push origin release/${VERSION}
deploy:
git checkout develop
git tag -m "Build release ${VERSION}" -s ${VERSION}
git archive --output=${VERSION}.tar.gz --prefix=zunit-$$(echo ${VERSION}|sed s/v//)/ ${VERSION}
zcat ${VERSION}.tar.gz | gpg --armor --detach-sign >${VERSION}.tar.gz.sign
zcat ${VERSION}.tar.gz | gpg --verify ${VERSION}.tar.gz.sign -
git push upstream ${VERSION}
.container:
ifeq (${USE_CONTAINER}, docker)
@docker run --rm --privileged=true -it -v ${PROJECT}:/zunit ${CONTAINER_IMAGE}${ZSH_VERSION} $(shell echo "${COMMAND}" | sed "s|${PROJECT}|${CONTAINER_ROOT}|g")
else ifeq (${USE_CONTAINER}, no)
${COMMAND}
endif
docs:
mkdir ${DOCS}; cd ${DOCS}; zsh -dfilc "zsd -v --scomm --cignore '(\#*FUNCTION:[[:space:]][\:\∞\.\+\@\-a-zA-Z0-9]*[\[]*|}[[:space:]]\#[[:space:]][\]]*)' ${GLOB}"
info:
@${MAKE} .container COMMAND="sh -c 'cat ${PROJECT}/VERSION; zsh --version; git --version; env'"
tests:
@${make} .container command="sh -c 'zdotdir=${tests} zunit=${project} cram ${cram_opts} --shell=zsh ${test}'"
tests:
${PROG} run
install:
install -cv -m755 ${PROG} ${PREFIX}/bin/zunit
uninstall:
rm -f ${PREFIX}/bin/zunit
clean:
rm -rf ${BIN} Makefile
install-deps:
sudo pip install cram=='0.6.*'
build:
@echo Building Zunit...
@mkdir -p ${BIN}
@printf "${HEADER_TEXT}" > ${PROG}
@echo "${BANNER}" >> ${PROG}
@for src in ${GLOB}; do echo "----> $$src"; cat "$$src" | grep -v -e '#\svim.*' -e '^(\s*#.*|\s*)\$$' >> ${PROG}; done
@$(call ised,"s/{{ZUNIT_REVISION}}/$$(git log -n1 --format=%h -- src)/",${PROG})
@$(call ised,"s/{{ZUNIT_REVISION_DATE}}/$$(git log -n1 --format='%ai' -- src)/",${PROG})
@$(call ised,"s/{{ZUNIT_VERSION}}/$$(cat ${VERSION_FILE})/",${PROG})
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ ZUnit is a powerful unit testing framework for ZSH
### [Zinit](https://github.com/zdharma-continuum/zinit)

```sh
zinit for \
as'command' \
atclone'./build.zsh' \
nocompile \
pick'zunit' \
@zdharma-continuum/zunit
zinit build for @zdharma-continuum/zunit
```

### Manual

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

## Writing Tests
Expand Down
30 changes: 0 additions & 30 deletions build.zsh

This file was deleted.

71 changes: 71 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/zsh
# vim: ft=zsh sw=4 ts=4 noet!
target=Makefile
arguments="$@"
typeset -A opts;
opts=(prefix /usr/local)

if [[ $1 == "--help" || $1 == "-h" ]]; then
cat >&1 <<EOH
Usage:
./configure --prefix[=[PATH]]
Available options:
- prefix - Set install prefix
All options are enabled by default.
Example:
# Disable lock, parallel, cache and defer
./configure --disable-extensions
# Disable completion
./configure --disable-completion
# Enable debug
./configure --with-debug
EOH
exit 0
fi


while [[ $# -gt 0 ]]; do
argkey="${1%\=*}"
key="${argkey//--/}"
if [[ $1 = *=* ]]; then
value="${1#*=}"
else
value=$opts[$key]
fi

if [[ $opts[$key] != "" ]]; then
opts[$key]=$value
else
printf "Invalid argument: %s (%s)\n" $key $1 >&2
exit 1
fi

shift

done

BANNER_SEP=$(printf '%*s' 70 | tr ' ' '\#')

cat > $target <<EOM
${BANNER_SEP}
# This file was autogenerated by 'configure'. Do not edit it directly!
# Invocation was: $0 $arguments
${BANNER_SEP}
EOM

{
for config in ${(k)opts}; do
echo "${${config:u}//-/_}=${opts[$config]}"
done

echo ${BANNER_SEP}
cat Makefile.in
} >> $target
106 changes: 46 additions & 60 deletions src/reports/html.zsh

Large diffs are not rendered by default.

60 changes: 26 additions & 34 deletions src/reports/tap.zsh
Original file line number Diff line number Diff line change
@@ -1,66 +1,58 @@
########################################
# Functions for handling TAP reporting #
########################################
# vim: ft=zsh sw=4 ts=4 et foldmarker=[[[,]]] foldmethod=marker

###
# Output a TAP compatible success message
###
function _zunit_tap_success() {
echo "ok ${total} - ${name}"
}

###
# Output a TAP compatible failure message
###
function _zunit_tap_failure() {
# FUNCTION: _zunit_tap_error [[[
# Output a TAP compatible error message
function _zunit_tap_error() {
local message="$@"

echo "not ok ${total} - Failure: ${name}"
echo "not ok ${total} - Error: ${name}"
echo " ---"
echo " message: ${message}"
echo " severity: fail"
echo " ..."

[[ -n $fail_fast ]] && echo "Bail out!"
}

###
# Output a TAP compatible error message
###
function _zunit_tap_error() {
} # ]]]
# FUNCTION: _zunit_tap_failure [[[
# Output a TAP compatible failure message
function _zunit_tap_failure() {
local message="$@"

echo "not ok ${total} - Error: ${name}"
echo "not ok ${total} - Failure: ${name}"
echo " ---"
echo " message: ${message}"
echo " severity: fail"
echo " ..."

[[ -n $fail_fast ]] && echo "Bail out!"
}

###
# Output a TAP compatible warning message
###
function _zunit_tap_warn() {
} # ]]]
# FUNCTION: _zunit_tap_skip [[[
# Output a TAP compatible skipped test message
function _zunit_tap_skip() {
local message="$@"

echo "ok ${total} - Warning: ${name}"
echo "ok ${total} - # SKIP ${name}"
echo " ---"
echo " message: ${message}"
echo " severity: comment"
echo " ..."
}

###
# Output a TAP compatible skipped test message
###
function _zunit_tap_skip() {
} # ]]]
# FUNCTION: _zunit_tap_success [[[
# Output a TAP compatible success message
function _zunit_tap_success() {
echo "ok ${total} - ${name}"
} # ]]]
# FUNCTION: _zunit_tap_warn [[[
# Output a TAP compatible warning message
function _zunit_tap_warn() {
local message="$@"

echo "ok ${total} - # SKIP ${name}"
echo "ok ${total} - Warning: ${name}"
echo " ---"
echo " message: ${message}"
echo " severity: comment"
echo " ..."
}
} # ]]]
2 changes: 1 addition & 1 deletion src/zunit.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function _zunit_usage() {
# FUNCTION: _zunit_version [[[
# Output the version number
function _zunit_version() {
echo '0.9.0'
echo '0.10.0'
} # ]]]
# FUNCTION: _zunit [[[
# The main zunit process
Expand Down

0 comments on commit b15c870

Please sign in to comment.