diff --git a/CHANGELOG.md b/CHANGELOG.md index 23bb8f7b..7f62c1e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +### Fixed +- `watch` subcommand failed with `bashunit::watch::run: command not found` in the released binary because `src/watch.sh` was missing from the build; it is now bundled (#735) + ### Changed - Faster test execution by removing subprocess forks from hot paths (no behaviour change) diff --git a/build.sh b/build.sh index 6963c94a..b622f331 100755 --- a/build.sh +++ b/build.sh @@ -107,6 +107,7 @@ function build::dependencies() { "src/helpers.sh" "src/test_title.sh" "src/upgrade.sh" + "src/watch.sh" "src/assertions.sh" "src/reports.sh" "src/runner.sh" diff --git a/tests/unit/build_test.sh b/tests/unit/build_test.sh new file mode 100644 index 00000000..8c52416e --- /dev/null +++ b/tests/unit/build_test.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +ROOT_DIR="" + +function set_up_before_script() { + ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +} + +function src_files_sourced_by_entrypoint() { + # Dev-only helpers under src/dev/ are intentionally excluded from the build. + grep -oE 'src/[a-zA-Z0-9_/]+\.sh' "$ROOT_DIR/bashunit" | grep -v '^src/dev/' | sort -u +} + +function src_files_in_build() { + grep -oE 'src/[a-zA-Z0-9_/]+\.sh' "$ROOT_DIR/build.sh" | sort -u +} + +# Every src file the dev entrypoint sources (except dev-only helpers) must also be +# bundled by build.sh, otherwise its functions are missing from the distributable +# single-file binary (regressions: bench #0.31.0, watch #735). +function test_build_bundles_every_src_file_sourced_by_entrypoint() { + local missing + missing=$(comm -23 <(src_files_sourced_by_entrypoint) <(src_files_in_build)) + + assert_empty "$missing" +} + +function test_built_binary_defines_watch_run() { + local build_dir + build_dir=$(bashunit::temp_dir) + + (cd "$ROOT_DIR" && bash build.sh "$build_dir") >/dev/null 2>&1 + + assert_file_exists "$build_dir/bashunit" + assert_equals "1" "$(grep -c 'function bashunit::watch::run()' "$build_dir/bashunit")" +}