Skip to content

Commit 4b666f5

Browse files
committed
Make dev-container-features-test-lib script POSIX compliant (fixes #438)
1 parent c8efeb6 commit 4b666f5

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@devcontainers/cli",
33
"description": "Dev Containers CLI",
4-
"version": "0.74.0",
4+
"version": "0.75.0",
55
"bin": {
66
"devcontainer": "devcontainer.js"
77
},

src/spec-node/featuresCLI/utils.ts

+17-28
Original file line numberDiff line numberDiff line change
@@ -57,70 +57,59 @@ export interface LaunchResult {
5757

5858
// dev-container-features-test-lib
5959
export const testLibraryScript = `
60-
#!/bin/bash
6160
SCRIPT_FOLDER="$(cd "$(dirname $0)" && pwd)"
6261
USERNAME=\${1:-root}
62+
export TERM=\${TERM:-dumb}
6363
6464
if [ -z $HOME ]; then
6565
HOME="/root"
6666
fi
6767
68-
FAILED=()
69-
70-
echoStderr()
71-
{
72-
echo "$@" 1>&2
73-
}
68+
FAILED=""
7469
7570
check() {
7671
LABEL=$1
7772
shift
78-
echo -e "\n"
79-
echo -e "🔄 Testing '$LABEL'"
80-
echo -e '\\033[37m'
73+
printf "\n🔄 Testing '%s'%s" "\${LABEL}" "$(tput setaf 7)"
8174
if "$@"; then
82-
echo -e "\n"
83-
echo "✅ Passed '$LABEL'!"
75+
printf "\n✅ Passed '%s'!" "\${LABEL}"
8476
return 0
8577
else
86-
echo -e "\n"
87-
echoStderr "❌ $LABEL check failed."
88-
FAILED+=("$LABEL")
78+
printf "\n"
79+
printf "❌ %s check failed." "\${LABEL}" >&2
80+
FAILED="\${FAILED}\n\${LABEL}"
8981
return 1
9082
fi
9183
}
9284
9385
checkMultiple() {
9486
PASSED=0
9587
LABEL="$1"
96-
echo -e "\n"
97-
echo -e "🔄 Testing '$LABEL'."
88+
printf "\n🔄 Testing '%s'." "\${LABEL}"
9889
shift; MINIMUMPASSED=$1
9990
shift; EXPRESSION="$1"
10091
while [ "$EXPRESSION" != "" ]; do
101-
if $EXPRESSION; then ((PASSED+=1)); fi
92+
if $EXPRESSION; then PASSED=$((PASSED+1)); fi
10293
shift; EXPRESSION=$1
10394
done
10495
if [ $PASSED -ge $MINIMUMPASSED ]; then
105-
echo -e "\n"
106-
echo "✅ Passed!"
96+
printf "\n✅ Passed!"
10797
return 0
10898
else
109-
echo -e "\n"
110-
echoStderr "❌ '$LABEL' check failed."
111-
FAILED+=("$LABEL")
99+
printf "\n"
100+
printf "❌ '%s' check failed." "\${LABEL}" >&2
101+
FAILED="\${FAILED}\n\${LABEL}"
112102
return 1
113103
fi
114104
}
115105
116106
reportResults() {
117-
if [ \${#FAILED[@]} -ne 0 ]; then
118-
echo -e "\n"
119-
echoStderr -e "💥 Failed tests: \${FAILED[@]}"
107+
if [ "\${FAILED}" ]; then
108+
printf "\n"
109+
printf "💥 Failed tests: %s" "\${FAILED}" >&2
120110
exit 1
121111
else
122-
echo -e "\n"
123-
echo -e "Test Passed!"
112+
printf "\nTest Passed!"
124113
exit 0
125114
fi
126115
}`;

0 commit comments

Comments
 (0)