Skip to content
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

Run a command n number of times. #45

Open
mohitkyadav opened this issue Jun 10, 2022 · 0 comments
Open

Run a command n number of times. #45

mohitkyadav opened this issue Jun 10, 2022 · 0 comments

Comments

@mohitkyadav
Copy link
Collaborator

mohitkyadav commented Jun 10, 2022

Usecase: Run a flaky test n number of times to test it if fails. But you can run any command.

#!/bin/sh

if [[ "$1" == "-h" ]]
then
    echo "
        Usage: repeat-cmd.sh <number of times to repeat> <command to repeat>
        Example: repeat-cmd.sh 5 "CI=true npm run test -- SomeComponent.test" -s

        -s: Silent mode, does not show any output from the command.
        "
    exit 0
fi

passed=0
totalTests=$1
i=0
while [ $i -ne $totalTests ]
do
    i=$(($i+1))
    if [[ "$3" == "-s" ]]
    then
        eval $2 > /dev/null 2>&1
    else
        echo "----------------------------------------------"
        echo "Test $i/$totalTests"
        echo "----------------------------------------------"
        eval $2
    fi


    if [ $? -eq 0 ]
    then
        passed=$(($passed+1))
        echo "Test $i: PASSED"
    else
        echo "Test $i: FAILED"
    fi
done

echo "Passed: $passed / $totalTests"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant