Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions shell/clean_and_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
set -e

hexo clean && hexo g && hexo d
10 changes: 10 additions & 0 deletions tests/mock_bin/hexo
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions tests/test_error.sh
Original file line number Diff line number Diff line change
@@ -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
Loading