Skip to content

Commit bb98b64

Browse files
committed
tests: Improve test-plugin-output-streaming.sh diagnostics and robust
1 parent 27dfb56 commit bb98b64

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

scripts/test-plugin-output-streaming.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
#!/usr/bin/env bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftContainerPlugin open source project
5+
##
6+
## Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
215

316
# Test that error output streamed from containertool is printed correctly by the plugin.
417

5-
set -exo pipefail
18+
set -euo pipefail
619

720
log() { printf -- "** %s\n" "$*" >&2; }
821
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
@@ -16,23 +29,27 @@ cleanup() {
1629
}
1730
trap cleanup EXIT
1831

32+
# Create a test project which depends on this checkout of the plugin repository
33+
REPO_ROOT=$(git rev-parse --show-toplevel)
1934
swift package --package-path "$PKGPATH" init --type executable --name hello
2035
cat >> "$PKGPATH/Package.swift" <<EOF
2136
package.dependencies += [
22-
.package(path: "$PWD"),
37+
.package(path: "$REPO_ROOT"),
2338
]
2439
EOF
40+
cat "$PKGPATH/Package.swift"
2541

2642
# Run the plugin, forgetting a mandatory argument. Verify that the output is not corrupted.
2743
# The `swift package` command will return a nonzero exit code. This is expected, so disable pipefail.
2844
set +o pipefail
2945
swift package --package-path "$PKGPATH" --allow-network-connections all build-container-image 2>&1 | tee "$PKGPATH/output"
3046
set -o pipefail
3147

48+
# This checks that the output lines are not broken, but not that they appear in the correct order
3249
grep -F -x -e "error: Missing expected argument '--repository <repository>'" \
3350
-e "error: Help: --repository <repository> Repository path" \
3451
-e "error: Usage: containertool [<options>] --repository <repository> <executable>" \
3552
-e "error: See 'containertool --help' for more information." "$PKGPATH/output"
3653

37-
echo Plugin error output: PASSED
54+
log Plugin error output: PASSED
3855

0 commit comments

Comments
 (0)