
How to Test Install Scripts Before Publishing Them
Test an install script before publishing: clean containers per distro, root and non-root runs, a local web server for curl pipe sh, and uninstall checks.
Tag
11 posts

Test an install script before publishing: clean containers per distro, root and non-root runs, a local web server for curl pipe sh, and uninstall checks.

Use test driven development for shell scripts with Bats: write a failing test, make it pass, refactor, and structure the script so functions can be sourced.

Test Go command line tools with table driven tests: a testable run function, in-memory streams, subtests, temp directories and a real binary test.

Test a Python command line tool with pytest: subprocess and in-process runs, exit codes and output, tmp_path, monkeypatch and parametrized cases.

Test command line output with golden files: store expected output, compare with diff, normalize volatile text, update on demand and review changes.

Test scripts that delete or overwrite in a throwaway sandbox: temp trees, containers with no network, fake commands and checks that nothing else changed.

Compare Bats, shunit2 and ShellSpec for shell testing: syntax, assertions, mocking, parallel runs, portability and which to choose for your project.

Test cron jobs and timers without waiting a day: clean environment runs, triggering units by hand, a temporary schedule, a faked clock and logs.

Test systemd calendar expressions with systemd-analyze calendar: see the normalized form, the next run times, time zone effects and traps in daily and weekly.

Use the curl command to download files, follow redirects, send headers and data, show response codes and timing, and fail properly in scripts.

Why mocking is hard in shell and what to do instead: PATH stubs, function overrides, injected command variables, containers, and when to test the real tool.