-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ merge: | |
release: | ||
script: |- | ||
echo "Release ${tag}" | ||
bats $PWD | ||
bats src/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/bash -e | ||
|
||
bats $PWD | ||
bats src/test | ||
rm -rf tmp/* | ||
pdd --source=$(pwd) --verbose --file=/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
THIS="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
BIN_DIR="$THIS/../../src/main" | ||
TMP_DIR="$THIS/../../tmp" | ||
export PATH=$TMP_DIR:$BIN_DIR:$PATH | ||
|
||
|
||
fake() { | ||
# sample: fake <command> <subcommand> <exit> <stdout> <stderr> | ||
BASENAME=$(basename $1) | ||
PROGRAM_PATH="$TMP_DIR/$BASENAME-app" | ||
FIXTURE_HOME="$PROGRAM_PATH/$(echo "$2" | sed 's/[^0-9a-zA-Z]*//g')" | ||
MOCK="$TMP_DIR/$BASENAME" | ||
|
||
[ -d "$FIXTURE_HOME" ] && rm -r "$FIXTURE_HOME" | ||
mkdir -p "$FIXTURE_HOME" | ||
echo -e "$3" > "$FIXTURE_HOME/exit_code" | ||
echo -e "$4" > "$FIXTURE_HOME/stdout" | ||
echo -e "$5" > "$FIXTURE_HOME/stderr" | ||
|
||
[ -e "$MOCK" ] && rm -r "$MOCK" | ||
echo "#!/usr/bin/env bash | ||
PROGRAM_PATH=\"$TMP_DIR/$BASENAME-app\" | ||
FIXTURE_HOME=\"\$PROGRAM_PATH/\$(echo \"\$@\" | sed 's/[^0-9a-zA-Z]*//g')\" | ||
cat \"\$FIXTURE_HOME/stdout\" | ||
cat \"\$FIXTURE_HOME/stderr\" >&2 | ||
read -r exit_code < \"\$FIXTURE_HOME/exit_code\" | ||
exit \$exit_code | ||
" > "$MOCK" | ||
chmod +x "$MOCK" | ||
} | ||
|
||
fake-pass() { | ||
# sample: fake-pass <command> <subcommand> <stdout> | ||
COMMAND="$1"; shift | ||
SUBCOMMAND="$1"; shift | ||
fake "$COMMAND" "$SUBCOMMAND" 0 "$@" | ||
} | ||
|
||
fake-fail() { | ||
# sample: fake-fail <command> <subcommand> <stderr> | ||
COMMAND="$1"; shift | ||
SUBCOMMAND="$2"; shift | ||
fake "$COMMAND" "$SUBCOMMAND" 100 " " "$@" | ||
} | ||
|
||
export -f fake | ||
export -f fake-pass | ||
export -f fake-fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This is a mock for system function 'read' | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
read() { | ||
sleep 0 | ||
} | ||
|
||
export -f read |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bats -ex | ||
|
||
load commons | ||
load fake-read | ||
|
||
@test "print available commands when run 'git-elegant'" { | ||
run git-elegant | ||
[[ "${lines[0]}" =~ "feature" ]] | ||
[[ "${lines[1]}" =~ "pull" ]] | ||
[[ "${lines[2]}" =~ "push" ]] | ||
[[ "${lines[3]}" =~ "push-after-rebase" ]] | ||
[[ "${lines[4]}" =~ "rebase" ]] | ||
[[ "${lines[5]}" =~ "init" ]] | ||
[[ "${lines[6]}" =~ "clone" ]] | ||
[[ "${lines[7]}" =~ "add" ]] | ||
[[ "${lines[8]}" =~ "clear-local" ]] | ||
} | ||
|
||
|
||
@test "exit code is 10 when run 'git-elegant'" { | ||
run git-elegant | ||
echo $status | ||
[ "$status" -eq 10 ] | ||
} | ||
|
||
|
||
@test "exit code is 0 when run 'git-elegant commands'" { | ||
run git-elegant commands | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
|
||
setup() { | ||
fake-pass git init | ||
fake-pass git "config --global user.name" aaa | ||
fake-pass git "config --global user.email" [email protected] | ||
fake-pass git "config --local user.name aaa" | ||
fake-pass git "config --local user.email [email protected]" | ||
} | ||
|
||
@test "exit code is 0 when run 'git-elegant init'" { | ||
run git-elegant init | ||
[ "$status" -eq 0 ] | ||
} |