diff --git a/shell/clean_and_deploy.sh b/shell/clean_and_deploy.sh index 36eaa9c..d225795 100644 --- a/shell/clean_and_deploy.sh +++ b/shell/clean_and_deploy.sh @@ -1,3 +1,4 @@ #!/bin/bash +set -e hexo clean && hexo g && hexo d \ No newline at end of file diff --git a/tests/mock_bin/hexo b/tests/mock_bin/hexo new file mode 100755 index 0000000..932ce48 --- /dev/null +++ b/tests/mock_bin/hexo @@ -0,0 +1,10 @@ +#!/bin/bash + +# A simple mock hexo that fails if the environment variable HEXO_SHOULD_FAIL is set +if [[ -n "$HEXO_SHOULD_FAIL" ]]; then + echo "Mock hexo: simulated failure" >&2 + exit 1 +fi + +echo "Mock hexo: success" +exit 0 diff --git a/tests/test_error.sh b/tests/test_error.sh new file mode 100755 index 0000000..80aac39 --- /dev/null +++ b/tests/test_error.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Setup environment +export PATH="$(pwd)/tests/mock_bin:$PATH" + +echo "Testing clean_and_deploy.sh failure handling..." + +# Case: Hexo fails +export HEXO_SHOULD_FAIL=1 +if bash shell/clean_and_deploy.sh; then + echo "TEST FAILED: clean_and_deploy.sh should have exited with a non-zero code." + exit 1 +else + echo "TEST PASSED: clean_and_deploy.sh correctly exited with a non-zero code when hexo failed." +fi + +# Case: Hexo succeeds +unset HEXO_SHOULD_FAIL +if bash shell/clean_and_deploy.sh; then + echo "TEST PASSED: clean_and_deploy.sh correctly exited with a zero code when hexo succeeded." +else + echo "TEST FAILED: clean_and_deploy.sh should have exited with a zero code." + exit 1 +fi + +echo "All tests passed!" +exit 0