From 60e4157f6a26d6c8586e850456e0983d584a638f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 19 Mar 2026 02:05:35 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20[testing=20improvement]=20Add=20?= =?UTF-8?q?error=20handling=20test=20for=20clean=5Fand=5Fdeploy.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added `set -e` to `shell/clean_and_deploy.sh` to ensure it exits on error. - Created `tests/mock_bin/hexo` to simulate hexo command failures. - Created `tests/test_error.sh` to verify script exit codes on failure. Co-authored-by: Shirolin <34873864+Shirolin@users.noreply.github.com> --- shell/clean_and_deploy.sh | 1 + tests/mock_bin/hexo | 10 ++++++++++ tests/test_error.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100755 tests/mock_bin/hexo create mode 100755 tests/test_error.sh 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