test: add bats unit tests and CI job#21
Open
CheapFuck wants to merge 1 commit into
Open
Conversation
Add a bats-core unit-test suite plus a gating CI job so logic regressions fail PRs/pushes before semantic-release cuts a release (the issue's goal: prevent broken releases). - tests/update_compare.bats: _towel_update_compare semver lt/gt/eq, incl. numeric-vs-lexical (1.10.0 > 1.9.0) and missing-field defaults. - tests/common_helpers.bats: inside_towel, exports/host path helpers, towel_repoquery_exportables filtering (dnf mocked via PATH shim), and towel_export_bin_wrapper output. - tests/cli.bats: CLI exit-code contract (towel update misuse -> 64, --help -> 0, towel --version format, unknown command -> 1). - tests/helpers/load.bash: sources scripts into the test shell with an isolated TOWEL_DATA, tolerating the enable/unalias hardening under errexit. To make towel-update unit-testable, add a source-safe guard '(return 0 2>/dev/null) && return 0' before its imperative tail; direct execution is unchanged (dispatcher always execs subcommands). CI: new 'tests' job runs 'bats --print-output-on-failure tests' and is added to the release job's needs. Exclude tests/ from the release tarball and note the command in AGENTS.md. Closes codam-coding-college#11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11.
Adds a
bats-coreunit-test suite plus a CI job that gates the release, so a logic regression fails the PR/push beforesemantic-releasecuts a new version.Tests (
tests/)update_compare.bats—_towel_update_comparesemver logic (lt/gt/eq). This is the function that decides whether a newer release exists, so it's the most release-critical piece. Covers equal/patch/minor/major, missing-field defaults (1.2==1.2.0), and numeric-vs-lexical (1.10.0 > 1.9.0).common_helpers.bats—inside_towel, the exports/host path helpers,towel_repoquery_exportablesfiltering (withdnfmocked via aPATHshim), andtowel_export_bin_wrapperoutput (wrapper is executable, contains the trampoline, host symlink created).cli.bats— the documented CLI exit-code contract as real subprocesses:towel updatemisuse →64,--help→0,towel --versionformat, unknown command →1.helpers/load.bash— sources scripts into the test shell with an isolatedTOWEL_DATA(under$BATS_TEST_TMPDIR), tolerating theenable/unaliasshell-hardening under bats' errexit.Production change (minimal)
To unit-test
_towel_update_compare/_towel_fetch_latest_version,towel-updateneeded to be source-safe. Added one guard before its imperative tail:Direct execution is unchanged — the dispatcher always executes subcommands (
"$TOWEL_BIN_DIR/towel-$cmd" "$@"), never sources them. Verified locally:towel updatewith no args still exits64, and the script lints clean (shellcheck -x+shfmt -d).CI / release
testsjob:bats --print-output-on-failure tests.teststo thereleasejob'sneeds:so failing tests blocksemantic-release..batsfiles use the bats DSL (not plain bash), so they stay out of theshellcheck/shfmtglobs (which only targetinstall+bin/*) — the existing lint jobs are unaffected.tests/from the release tarball in.releaserc.yml, and documentedbats --print-output-on-failure testsinAGENTS.md.Notes / possible follow-ups
apt-get install -y bats(Ubuntu's 1.10.0). Happy to switch to a pinnedbats-coredownload instead, to match theshfmt/distrobox pinning style — let me know your preference._towel_fetch_latest_versionis intentionally left for a follow-up: it calls/usr/bin/curlby absolute path (per the repo's hardening convention), which can't be mocked offline without adding an injection seam. Can do that separately if you'd like it covered.All 22 tests pass locally.