Skip to content

Make dev-container-features-test-lib script POSIX compliant (fixes #438) #959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
45 changes: 17 additions & 28 deletions src/spec-node/featuresCLI/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,70 +57,59 @@ export interface LaunchResult {

// dev-container-features-test-lib
export const testLibraryScript = `
#!/bin/bash
SCRIPT_FOLDER="$(cd "$(dirname $0)" && pwd)"
USERNAME=\${1:-root}
export TERM=\${TERM:-dumb}

if [ -z $HOME ]; then
HOME="/root"
fi

FAILED=()

echoStderr()
{
echo "$@" 1>&2
}
FAILED=""

check() {
LABEL=$1
shift
echo -e "\n"
echo -e "🔄 Testing '$LABEL'"
echo -e '\\033[37m'
printf "\n🔄 Testing '%s'%s" "\${LABEL}" "$(tput setaf 7)"
if "$@"; then
echo -e "\n"
echo "✅ Passed '$LABEL'!"
printf "\n✅ Passed '%s'!" "\${LABEL}"
return 0
else
echo -e "\n"
echoStderr "❌ $LABEL check failed."
FAILED+=("$LABEL")
printf "\n"
printf "❌ %s check failed." "\${LABEL}" >&2
FAILED="\${FAILED}\n\${LABEL}"
return 1
fi
}

checkMultiple() {
PASSED=0
LABEL="$1"
echo -e "\n"
echo -e "🔄 Testing '$LABEL'."
printf "\n🔄 Testing '%s'." "\${LABEL}"
shift; MINIMUMPASSED=$1
shift; EXPRESSION="$1"
while [ "$EXPRESSION" != "" ]; do
if $EXPRESSION; then ((PASSED+=1)); fi
if $EXPRESSION; then PASSED=$((PASSED+1)); fi
shift; EXPRESSION=$1
done
if [ $PASSED -ge $MINIMUMPASSED ]; then
echo -e "\n"
echo "✅ Passed!"
printf "\n✅ Passed!"
return 0
else
echo -e "\n"
echoStderr "❌ '$LABEL' check failed."
FAILED+=("$LABEL")
printf "\n"
printf "❌ '%s' check failed." "\${LABEL}" >&2
FAILED="\${FAILED}\n\${LABEL}"
return 1
fi
}

reportResults() {
if [ \${#FAILED[@]} -ne 0 ]; then
echo -e "\n"
echoStderr -e "💥 Failed tests: \${FAILED[@]}"
if [ "\${FAILED}" ]; then
printf "\n"
printf "💥 Failed tests: %s" "\${FAILED}" >&2
exit 1
else
echo -e "\n"
echo -e "Test Passed!"
printf "\nTest Passed!"
exit 0
fi
}`;