1
1
#! /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
+ # #===----------------------------------------------------------------------===##
2
15
3
16
# Test that error output streamed from containertool is printed correctly by the plugin.
4
17
5
- set -exo pipefail
18
+ set -euo pipefail
6
19
7
20
log () { printf -- " ** %s\n" " $* " >&2 ; }
8
21
error () { printf -- " ** ERROR: %s\n" " $* " >&2 ; }
@@ -16,23 +29,27 @@ cleanup() {
16
29
}
17
30
trap cleanup EXIT
18
31
32
+ # Create a test project which depends on this checkout of the plugin repository
33
+ REPO_ROOT=$( git rev-parse --show-toplevel)
19
34
swift package --package-path " $PKGPATH " init --type executable --name hello
20
35
cat >> " $PKGPATH /Package.swift" << EOF
21
36
package.dependencies += [
22
- .package(path: "$PWD "),
37
+ .package(path: "$REPO_ROOT "),
23
38
]
24
39
EOF
40
+ cat " $PKGPATH /Package.swift"
25
41
26
42
# Run the plugin, forgetting a mandatory argument. Verify that the output is not corrupted.
27
43
# The `swift package` command will return a nonzero exit code. This is expected, so disable pipefail.
28
44
set +o pipefail
29
45
swift package --package-path " $PKGPATH " --allow-network-connections all build-container-image 2>&1 | tee " $PKGPATH /output"
30
46
set -o pipefail
31
47
48
+ # This checks that the output lines are not broken, but not that they appear in the correct order
32
49
grep -F -x -e " error: Missing expected argument '--repository <repository>'" \
33
50
-e " error: Help: --repository <repository> Repository path" \
34
51
-e " error: Usage: containertool [<options>] --repository <repository> <executable>" \
35
52
-e " error: See 'containertool --help' for more information." " $PKGPATH /output"
36
53
37
- echo Plugin error output: PASSED
54
+ log Plugin error output: PASSED
38
55
0 commit comments