Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions base_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,31 @@ base_init_source_stdlib() {
}
}

base_init_bash_libs_version_is_supported() {
local version="${1:-}"

[[ "$version" =~ ^1[.][0-9]+[.][0-9]+$ ||
"$version" =~ ^2[.][0-9]+[.][0-9]+(-(alpha|beta|rc)[.](0|[1-9][0-9]*))?$ ]]
}

base_init_require_bash_libs_version() {
local loaded_version="${BASE_BASH_LIBS_VERSION:-}"

if ! base_init_bash_libs_version_is_supported "$loaded_version"; then
base_init_error "Base requires base-bash-libs 1.4.0 or a compatible release with the v2 API; loaded version is '$loaded_version'."
return 1
fi

case "$loaded_version" in
1.*|2.*)
# The v2 namespace landed before the coordinated v2 release. Keep
# the source checkout usable while the release train is completed;
# the final cutover will raise this floor to 2.0.0.
1.*)
if ! base_require_version 1.4.0; then
base_init_error "Base requires base-bash-libs 1.4.0 or newer; loaded version is '$loaded_version'."
return 1
fi
;;
*)
base_init_error "Base requires base-bash-libs 1.4.0 or a compatible release with the v2 API; loaded version is '$loaded_version'."
return 1
2.*)
# The v2 API is valid during the coordinated prerelease and GA
# window. Do not pass its prerelease form to the v1 numeric helper.
;;
esac
}
Expand Down
40 changes: 31 additions & 9 deletions tests/base_init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ EOF
}

@test "base_init exports the Base runtime path contract" {
local expected_bash_libs_dir
local expected_bash_libs_dir expected_bash_libs_version

expected_bash_libs_dir="$(cd "$TEST_TMPDIR/base-bash-libs/lib/bash" && pwd -P)"
expected_bash_libs_version="$(<"$TEST_TMPDIR/base-bash-libs/VERSION")"

run_base_init_script '
base_home="$1"
Expand Down Expand Up @@ -101,7 +102,7 @@ EOF
[[ "$output" == *"BASE_BASH_LIB_DIR=$TEST_BASE_HOME/lib/bash"* ]]
[[ "$output" == *"BASE_BASH_LIBS_DIR=$expected_bash_libs_dir"* ]]
[[ "$output" == *"BASE_BASH_LIBS_SOURCE=sibling"* ]]
[[ "$output" == *"BASE_BASH_LIBS_VERSION=1.4.0"* ]]
[[ "$output" == *"BASE_BASH_LIBS_VERSION=$expected_bash_libs_version"* ]]
[[ "$output" == *"BASE_SHELL_DIR=$TEST_BASE_HOME/lib/shell"* ]]
}

Expand All @@ -118,15 +119,36 @@ EOF
[[ "$output" == *"loaded version is '1.2.0'"* ]]
}

@test "base_init accepts the v2 base-bash-libs namespace during the cutover" {
printf '2.0.0\n' > "$TEST_TMPDIR/base-bash-libs/VERSION"
@test "base_init accepts v2 prerelease and GA base-bash-libs versions" {
local version

run_base_init_script '
base_home="$1"
source "$base_home/base_init.sh"
'
for version in 2.0.0-alpha.1 2.0.0-beta.2 2.0.0-rc.1 2.0.0; do
printf '%s\n' "$version" > "$TEST_TMPDIR/base-bash-libs/VERSION"

[ "$status" -eq 0 ]
run_base_init_script '
base_home="$1"
source "$base_home/base_init.sh"
'

[ "$status" -eq 0 ]
done
}

@test "base_init rejects malformed v2 prerelease versions" {
local version

for version in 2.0.0-rc 2.0.0-gamma.1 3.0.0; do
printf '%s\n' "$version" > "$TEST_TMPDIR/base-bash-libs/VERSION"

run_base_init_script '
base_home="$1"
source "$base_home/base_init.sh"
'

[ "$status" -ne 0 ]
[[ "$output" == *"loaded version is '$version'"* ]]
[[ "$output" != *"base_require_version expects dotted numeric versions"* ]]
done
}

@test "base_init preserves explicit symlinked BASE_HOME paths" {
Expand Down
Loading