Skip to content

Commit 8241a18

Browse files
committed
Support running bash tests
1 parent 6d10abf commit 8241a18

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.sh]
12+
indent_size = 2

tests/all-tests.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )";)
4+
5+
fail_count=0
6+
7+
for testfile in "$SCRIPT_DIR"/test-*.sh
8+
do
9+
echo ""
10+
echo "######### $(basename $testfile) ################"
11+
$testfile || ((fail_count++))
12+
done
13+
14+
exit $fail_count

tests/base.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
function run_test() {
3+
test_function="$1"
4+
5+
if [ -z "$test_function" ]; then
6+
echo "Test function missing. Specify one."
7+
exit 2
8+
fi
9+
10+
echo ""
11+
echo "--> Running $test_function"
12+
if $test_function ; then
13+
echo "++ Test successful"
14+
else
15+
echo "-- Test failed"
16+
exit 1
17+
fi
18+
}

tests/test-prompt-command.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )";)
4+
source "$SCRIPT_DIR/base.sh"
5+
6+
function test_prompt_command_is_set() {
7+
source "$SCRIPT_DIR/../gitprompt.sh"
8+
9+
echo "$PROMPT_COMMAND"
10+
[[ "$PROMPT_COMMAND" == "setLastCommandState;setGitPrompt" ]]
11+
}
12+
13+
function test_prompt_command_respecting_custom_function() {
14+
PROMPT_COMMAND="some"
15+
source "$SCRIPT_DIR/../gitprompt.sh"
16+
17+
echo "$PROMPT_COMMAND"
18+
[[ "$PROMPT_COMMAND" == "setLastCommandState;some;setGitPrompt" ]]
19+
}
20+
21+
run_test "test_prompt_command_is_set"
22+
run_test "test_prompt_command_respecting_custom_function"

0 commit comments

Comments
 (0)