Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for helper functions #51

Merged
merged 2 commits into from
Jan 22, 2025
Merged
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
38 changes: 33 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# Distros to test install.sh on

unsupported := alpine voidlinux/voidlinux-musl ubuntu_16.04 debian_9 linuxmintd/mint18-amd64 fedora_26 opensuse/leap_42.3
supported := ubuntu_18.04 debian_10 linuxmintd/mint19-amd64 fedora_27 fedora_41 opensuse/leap_15 opensuse/tumbleweed rockylinux_9 manjarolinux/base
distros := $(unsupported) $(supported)

test: $(distros)
test: shellcheck ut $(distros)

# Output per target, use bash in recipes, fail on errors, be quiet by default

MAKEFLAGS := -rRO
SHELL := $(shell command -v bash)
.SHELLFLAGS := -eEo pipefail -c
.ONESHELL:
$(V).SILENT:
.PHONY: clean shellcheck test $(distros) $(distros:%=%_clean)
.PHONY: clean shellcheck test ut $(distros) $(distros:%=%_clean)

# Test install.sh on different distributions via docker

$(distros): distro = $(subst _,:,$@)
$(distros) $(distros:%=%_clean): log = $(subst /,_,$(subst _,:,$(@:%_clean=%))).log
Expand All @@ -35,10 +41,32 @@ $(supported):
printf "Failed\n\n" && tail -v "$(log)" && false
fi

shellcheck:
shellcheck -e SC2086 install.sh

clean: $(distros:%=%_clean)

$(distros:%=%_clean):
rm -f "$(log)"

# Test helper functions from install.sh in an alpine container

uts := ut_available ut_first_of ut_show ut_newer ut_supported
.PHONY: $(uts)
ut: $(uts)

ut_available: test = available ls && ! available foo
ut_first_of: test = [ $$(first_of ls foo) = ls ] && [ $$(first_of foo bar ls) = ls ]
ut_show: test = show ls 2>&1 >/dev/null|grep -qFx "+ ls"
ut_newer: test = newer 1.12 1.9 && newer 0.1.1 0.0.2 && ! newer "" non-empty
ut_supported: test = supported foo 1.12 1.9

$(uts): ut_%:
printf "Testing $*()... "
docker run --rm -v "$$PWD/install.sh:/install.sh" alpine \
sh -$(if $(V),x,)ec 'source <(grep -x "\w\w*() {.*}" /install.sh) && $(test)'
echo OK

# Analyze install.sh with shellcheck

shellcheck:
printf "Analyzing install.sh with shellcheck... "
shellcheck -e SC2086 install.sh
wknapik marked this conversation as resolved.
Show resolved Hide resolved
echo OK
Loading