diff --git a/Makefile b/Makefile index 9b24608..63143e9 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 + echo OK