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
12 changes: 9 additions & 3 deletions tests/bash-42-release-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ git() {
main() {
local expected_major="${1-}" expected_minor="${2-}" expected_patch="${3-}"
local script_dir repo_root release_script release_driver release_artifact
local capture_path output_path artifact_output source_commit artifact_fixture
local capture_path output_path artifact_output source_commit artifact_fixture source_repo

if (($# != 0 && $# != 3)); then
release_smoke_fail "usage: $0 [expected-major expected-minor expected-patch]"
Expand Down Expand Up @@ -117,11 +117,17 @@ main() {
artifact_output="$artifact_fixture"
else
artifact_output="$release_smoke_dir/artifact"
source_commit="$(command git -C "$repo_root" rev-parse --verify 'HEAD^{commit}' 2> /dev/null)" || {
source_repo="$release_smoke_dir/source-repo"
command git clone --local "$repo_root" "$source_repo" > /dev/null 2>&1 || {
release_smoke_fail "unable to create a clean source clone for artifact verification."
return 1
}
source_commit="$(command git -C "$source_repo" rev-parse --verify 'HEAD^{commit}' 2> /dev/null)" || {
release_smoke_fail "unable to resolve the source commit for artifact verification."
return 1
}
if ! "$release_artifact" build --version 2.0.0 --commit "$source_commit" \
if ! BASE_BASH_RELEASE_SOURCE_ROOT="$source_repo" \
"$release_artifact" build --version 2.0.0 --commit "$source_commit" \
--output "$artifact_output" > "$output_path" 2>&1; then
release_smoke_fail "canonical artifact build failed on Bash $BASH_VERSION."
return 1
Expand Down
25 changes: 20 additions & 5 deletions tests/release-artifact.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ load ../lib/bash/tests/test_helper.sh
setup() {
setup_test_tmpdir
RELEASE_ARTIFACT="$BASE_REPO_ROOT/scripts/release-artifact"
RELEASE_COMMIT="$(git -C "$BASE_REPO_ROOT" rev-parse HEAD)"
RELEASE_SOURCE_ROOT="$TEST_TMPDIR/source-repo"
git clone --local "$BASE_REPO_ROOT" "$RELEASE_SOURCE_ROOT" > /dev/null
RELEASE_COMMIT="$(git -C "$RELEASE_SOURCE_ROOT" rev-parse HEAD)"
export BASE_BASH_RELEASE_SOURCE_ROOT="$RELEASE_SOURCE_ROOT"
}

release_test_hash_file() {
Expand Down Expand Up @@ -181,6 +184,19 @@ EOF
[[ "$output" == *"Option '--commit' may be provided only once."* ]]
}

@test "release artifact build rejects a dirty source root" {
local dirty_source="$TEST_TMPDIR/dirty-source" output="$TEST_TMPDIR/dirty-artifact"

git clone --local "$BASE_REPO_ROOT" "$dirty_source" > /dev/null
printf 'dirty\n' >> "$dirty_source/VERSION"

bats_run env BASE_BASH_RELEASE_SOURCE_ROOT="$dirty_source" \
"$RELEASE_ARTIFACT" build --version 2.2.0-rc.1 --commit "$RELEASE_COMMIT" \
--output "$output"
[ "$status" -eq 1 ]
[[ "$output" == *"The source checkout must be clean."* ]]
}

@test "release artifact build and verify support post-GA patch and minor versions" {
local version artifact

Expand Down Expand Up @@ -310,10 +326,9 @@ EOF
@test "remote release verification rejects missing assets and cleans partial retries" {
local artifact="$TEST_TMPDIR/artifact" verified="$TEST_TMPDIR/verified" source_repo

# Build from a clean local clone because the test worktree contains the
# uncommitted remote-verifier changes themselves.
source_repo="$TEST_TMPDIR/source-repo"
git clone --local "$BASE_REPO_ROOT" "$source_repo" > /dev/null
# Build from the per-test clean local clone because the test worktree may
# contain uncommitted release-artifact changes itself.
source_repo="$RELEASE_SOURCE_ROOT"
export REMOTE_VERSION=2.0.0-rc.1 REMOTE_COMMIT="$RELEASE_COMMIT" REMOTE_SOURCE="$artifact"
"$source_repo/scripts/release-artifact" build --version "$REMOTE_VERSION" \
--commit "$REMOTE_COMMIT" --output "$artifact" > /dev/null
Expand Down
37 changes: 37 additions & 0 deletions tests/validate-driver.bats
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,40 @@ SCRIPT
[[ "$output" == *"Validation stage failed: ShellCheck error profile (exit 42)."* ]]
[ ! -e "$sentinel" ]
}

@test "validate detaches BATS from an interactive stdin" {
local shim_dir="$TEST_TMPDIR/shim"
local sentinel="$TEST_TMPDIR/bats-stdin"
local pty_runner="$TEST_TMPDIR/run-in-pty.py"

mkdir -p "$shim_dir"
cat > "$shim_dir/shellcheck" <<'SCRIPT'
#!/usr/bin/env bash
exit 0
SCRIPT
cat > "$shim_dir/bats" <<'SCRIPT'
#!/usr/bin/env bash
if [[ -t 0 ]]; then
printf 'tty\n' > "${VALIDATE_BATS_STDIN:?}"
else
printf 'non-tty\n' > "${VALIDATE_BATS_STDIN:?}"
fi
exit 42
SCRIPT
cat > "$pty_runner" <<'PYTHON'
#!/usr/bin/env python3
import os
import pty
import sys

wait_status = pty.spawn(sys.argv[1:])
sys.exit(os.waitstatus_to_exitcode(wait_status))
PYTHON
chmod +x "$shim_dir/shellcheck" "$shim_dir/bats" "$pty_runner"

run env PATH="$shim_dir:$PATH" VALIDATE_BATS_STDIN="$sentinel" \
"$pty_runner" "$BASE_REPO_ROOT/tests/validate.sh"

[ "$status" -eq 42 ]
[ "$(cat "$sentinel")" = "non-tty" ]
}
6 changes: 5 additions & 1 deletion tests/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,11 @@ while IFS= read -r file; do
[[ -n "$file" ]] && bats_files+=("$file")
done <<< "$manifest_test_paths"

run_stage "BATS test suites" bats \
run_bats_noninteractive() {
bats "$@" < /dev/null
}

run_stage "BATS test suites" run_bats_noninteractive \
"${bats_files[@]}" || exit $?

run_stage "Project intake REST contract" python3 tests/project-intake-test.py || exit $?
Expand Down
Loading