Skip to content

[Features][test-lib] Add message arg to the check function #1010

@cschot

Description

@cschot

I would like to propose a change to the check function of the dev-container-features-test-lib script.

The function should take a message to display when the test fails, like other testing frameworks have.

The current function code is:

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

I propose to add a message on $2 or the last argument.
Any thoughts on this?

I would suggest something like this:

check() { 
     LABEL=$1 
     MESSAGE = $2 or ${!#}
 
     #
     # the rest of the function
     #
 } 

The new function should work like the examples below, and be backwards compatible

old: 
check "java version LTS installed as default" \
          grep "LTS" <(java --version)

new:
check "java version LTS installed as default" \
         grep "LTS" <(java --version) \
        "REASON: The installed version is: $(java --version)"

or 

check "java version LTS installed as default"  \
        "REASON: The installed version is: $(java --version)" \
        grep "LTS" <(java --version)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions