In my android project I want to run tests using shell script. Depending on whether or not tests pass I want to do some further actions. My question is how my script is supposed to know if tests passed? To run tests I use ./gradlew test
command.
It would be nice if the return value of this command would be an integer or boolean but it’s not. This is my run_tests.sh
at the moment, however it doesn't work because OUTPUT is not a boolean value;
#!/bin/bash
OUTPUT=$(./gradlew test)
if [ "$OUTPUT" = true ]; then
echo "Tests passed. Do something."
else
echo "Tests didn't pass. Do something."
fi
This script always prints "Tests didn't pass. Do something.".
答案 0 :(得分:1)
为什么不检查./gradlew的退出状态? 如果脚本通过,退出状态将为0,否则它将是1或任何其他返回代码,通常由脚本开发人员决定。 此外,使用bash时使用双括号。
#!/bin/bash
./gradlew test
if [[ $? -eq 0 ]]; then
echo "Tests passed. Do something."
else
echo "Tests didn't pass. Do something."
fi