From 863ceeac8fdb10258a58d35bcee6874097fffc88 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 12 Apr 2026 23:48:14 -0400 Subject: test: add bats unit tests for common.sh and config.sh 23 bats tests covering the pure logic in installer/lib/common.sh (command_exists, require_command, info/warn/error, enable_color, require_root, log) and installer/lib/config.sh (parse_args, load_config, validate_config, check_config). Makefile adds a 'bats' target; 'test' now runs lint + bats (VM integration tests remain under test-install). --- Makefile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 870b0ec..bf0ea2f 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ # Usage: # make build - Build the ISO # make lint - Run shellcheck on all scripts -# make test - Run lint +# make bats - Run bats unit tests (tests/unit/) +# make test - Run lint + bats # make test-install - Run all automated install tests in VMs (slow) # make release - Full test + build + deploy # @@ -19,7 +20,7 @@ # # Test configurations are in scripts/test-configs/ -.PHONY: test test-install test-vm test-multi test-multi3 test-boot test-clean build release clean distclean lint +.PHONY: test test-install test-vm test-multi test-multi3 test-boot test-clean build release clean distclean lint bats # Lint all bash scripts lint: @@ -27,6 +28,13 @@ lint: @shellcheck -x build.sh scripts/*.sh installer/archangel installer/zfsrollback installer/zfssnapshot installer/lib/*.sh @echo "==> Shellcheck complete" +# Run bats unit tests +bats: + @command -v bats >/dev/null 2>&1 || { echo "bats not installed. Install: sudo pacman -S bats (Arch), brew install bats-core (macOS), apt install bats (Debian/Ubuntu)"; exit 1; } + @echo "==> Running bats unit tests..." + @bats tests/unit/ + @echo "==> Bats tests complete" + # Build the ISO (requires sudo) build: @echo "==> Building ISO..." @@ -37,8 +45,8 @@ test-install: build @echo "==> Running install tests..." ./scripts/test-install.sh -# All tests (lint only - VM tests via test-install) -test: lint +# All fast tests (lint + bats — VM integration tests via test-install) +test: lint bats # Full release: test everything, build, deploy release: test test-install -- cgit v1.2.3