Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update unit tests #105

Merged
merged 2 commits into from
Dec 22, 2017
Merged
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
8 changes: 4 additions & 4 deletions src/main/git-elegant-configure
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ _core_comment_char_default="|"
_core_comment_char_message="commit message won't start with"

_user_name_key="user.name"
_user_name_default=$(git config --global "$_user_name_key")
_user_name_default=$(git config "$_user_name_key")
_user_name_message="your user name"

_user_email_key="user.email"
_user_email_default=$(git config --global "$_user_email_key")
_user_email_default=$(git config "$_user_email_key")
_user_email_message="your user email"

_apply_whitespace_key="apply.whitespace"
Expand Down Expand Up @@ -54,8 +54,8 @@ _configure() {
done
}

GLOBALS=(_core_comment_char _user_name _user_email _apply_whitespace _alias)
LOCALS=(_core_comment_char _user_name _user_email _apply_whitespace)
GLOBALS=(_user_name _user_email _core_comment_char _apply_whitespace _alias)
LOCALS=(_user_name _user_email _core_comment_char _apply_whitespace)

default() {
case "$1" in
Expand Down
1 change: 1 addition & 0 deletions src/test/addons-common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ check(){
run "$@"
echo "> Exit code: \$status=$status"
local IFS=$'\n'
echo "> stdout+stderr size: ${#lines[@]}"
for line in ${lines[@]}; do
echo "> stdout+stderr: '$line'"
done
Expand Down
3 changes: 1 addition & 2 deletions src/test/addons-fake.bash
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ PROGRAM_PATH=\"$MOCK_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
exit \$(cat \"\$FIXTURE_HOME/exit_code\")
" | tee -i "$MOCK"
_ex_fake chmod +x "$MOCK"
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/addons-read.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

read() {
sleep 0
echo ""
}

export -f read
2 changes: 1 addition & 1 deletion src/test/git-elegant-add.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ setup() {
}

@test "'add': successful adding of modified file" {
run git-elegant add
check git-elegant add
[ "$status" -eq 0 ]
}
12 changes: 6 additions & 6 deletions src/test/git-elegant-check.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@ preconditions() {

@test "'check': '-a' option is available" {
preconditions
run git-elegant check -a
check git-elegant check -a
[ "$status" -eq 0 ]
}

@test "'check': '--all' option is available" {
preconditions
run git-elegant check --all
check git-elegant check --all
[ "$status" -eq 0 ]
}

@test "'check': '-u' option is available" {
preconditions
run git-elegant check -u
check git-elegant check -u
[ "$status" -eq 0 ]
}

@test "'check': '--unstaged' option is available" {
preconditions
run git-elegant check --unstaged
check git-elegant check --unstaged
[ "$status" -eq 0 ]
}

@test "'check': '-s' option is available" {
preconditions
run git-elegant check -s
check git-elegant check -s
[ "$status" -eq 0 ]
}

@test "'check': '--staged' option is available" {
preconditions
run git-elegant check --staged
check git-elegant check --staged
[ "$status" -eq 0 ]
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/git-elegant-clear-local.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ teardown() {
}

@test "'clear-local': command is available" {
run git-elegant clear-local
check git-elegant clear-local
[ "$status" -eq 0 ]
}
4 changes: 2 additions & 2 deletions src/test/git-elegant-clone.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ teardown() {
}

@test "'clone': raise an error if cloneable URL isn't set" {
run git-elegant clone
check git-elegant clone
[[ "${lines[0]}" =~ "Cloneable URL is not set" ]]
}

@test "'clone': clone the repo" {
run git-elegant clone https://github.com/extsoft/elegant-git.git
check git-elegant clone https://github.com/extsoft/elegant-git.git
[ "$status" -eq 0 ]
}
4 changes: 2 additions & 2 deletions src/test/git-elegant-commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ teardown() {
}

@test "'commands': print all available commands" {
run git-elegant commands
check git-elegant commands
[ "${lines[0]}" = "feature" ]
[ "${lines[1]}" = "pull" ]
[ "${lines[2]}" = "push" ]
Expand All @@ -24,6 +24,6 @@ teardown() {
}

@test "'commands': default exit code is 0" {
run git-elegant commands
check git-elegant commands
[ "$status" -eq 0 ]
}
51 changes: 29 additions & 22 deletions src/test/git-elegant-configure.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
load addons-common
load addons-read
load addons-fake
load addons-git

setup() {
fake-preconditions() {
fake-pass git "elegant commands"

fake-pass git "config --global user.name" "UserName"
fake-pass git "config --global user.email" "UserEmail"
fake-pass git "config user.name" "UserName"
fake-pass git "config user.email" "UserEmail"

fake-pass git "config --global core.commentChar"
fake-pass git "config --local core.commentChar"
Expand All @@ -24,39 +25,45 @@ setup() {

teardown() {
clean-fake
clean-git
}

@test "'configure': exit code is 11 when no arguments provided" {
run git-elegant configure
[ "$status" -eq 11 ]
fake-preconditions
check git-elegant configure
[ "$status" -eq 11 ]
}


@test "'configure': '--global' option is available" {
run git-elegant configure --global
[ "$status" -eq 0 ]
fake-preconditions
check git-elegant configure --global
[ "$status" -eq 0 ]
}

@test "'configure': '--local' option is available" {
run git-elegant configure --local
[ "$status" -eq 0 ]
fake-preconditions
check git-elegant configure --local
[ "$status" -eq 0 ]
}

@test "'configure': sequence of the global git configuration is correct" {
run git-elegant configure --global
[ "${lines[0]}" = "commit message won't start with [|]: " ]
[ "${lines[1]}" = "your user name [UserName]: " ]
[ "${lines[2]}" = "your user email [UserEmail]: " ]
[ "${lines[3]}" = "whitespace issues on patching [fix]: " ]
[ "${lines[4]}" = "add git aliases for all 'elegant git' commands [yes]: " ]
[ ${#lines[@]} -eq 5 ]
fake-preconditions
check git-elegant configure --global
[ "${lines[0]}" = "your user name [UserName]: " ]
[ "${lines[1]}" = "your user email [UserEmail]: " ]
[ "${lines[2]}" = "commit message won't start with [|]: " ]
[ "${lines[3]}" = "whitespace issues on patching [fix]: " ]
[ "${lines[4]}" = "add git aliases for all 'elegant git' commands [yes]: " ]
[ ${#lines[@]} -eq 5 ]
}

@test "'configure': sequence of the local git configuration is correct" {
run git-elegant configure --local
[ "${lines[0]}" = "commit message won't start with [|]: " ]
[ "${lines[1]}" = "your user name [UserName]: " ]
[ "${lines[2]}" = "your user email [UserEmail]: " ]
[ "${lines[3]}" = "whitespace issues on patching [fix]: " ]
[ ${#lines[@]} -eq 4 ]
init-repo
check git-elegant configure --local
[ "${lines[0]}" = "your user name [Elegant Git]: " ]
[ "${lines[1]}" = "your user email [[email protected]]: " ]
[ "${lines[2]}" = "commit message won't start with [|]: " ]
[ "${lines[3]}" = "whitespace issues on patching [fix]: " ]
[ ${#lines[@]} -eq 4 ]
}
12 changes: 6 additions & 6 deletions src/test/git-elegant-feature.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@ teardown() {
}

@test "'feature': branch with given name is created successfully" {
run git-elegant feature test-feature
check git-elegant feature test-feature
[ "$status" -eq 0 ]
}

@test "'feature': exit code is 255 when branch name isn't set" {
run git-elegant feature
check git-elegant feature
[ "$status" -eq 255 ]
}

@test "'feature': print error message when branch name isn't set" {
run git-elegant feature
check git-elegant feature
[[ "${lines[0]}" =~ "Feature name is not set" ]]
}

@test "'feature': use stash for available changes" {
fake-pass git "stash save elegant-git" "Saved working directory"
fake-pass git "stash apply stash^{/elegant-git}"
fake-pass git "stash drop stash@{0}"
run git-elegant feature test-feature
check git-elegant feature test-feature
[ "$status" -eq 0 ]
}

@test "'feature': ignore stash if there are no changes" {
fake-pass git "stash save elegant-git" "No local changes to save"
run git-elegant feature test-feature
check git-elegant feature test-feature
[ "$status" -eq 0 ]
}

@test "'feature': exit code is 100 when stash wasn't applied" {
fake-pass git "stash save elegant-git" "Saved working directory"
fake-pass git "stash apply stash^{/elegant-git}"
fake-fail git "stash drop stash@{0}"
run git-elegant feature test-feature
check git-elegant feature test-feature
[ "$status" -eq 100 ]
}
2 changes: 1 addition & 1 deletion src/test/git-elegant-init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ teardown() {
}

@test "'init': command is available" {
run git-elegant init
check git-elegant init
[ "$status" -eq 0 ]
}
4 changes: 2 additions & 2 deletions src/test/git-elegant-pull.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ teardown() {
fake-pass git "fetch --tags"
fake-pass git pull

run git-elegant pull
check git-elegant pull
[ "$status" -eq 0 ]
}

Expand All @@ -20,6 +20,6 @@ teardown() {
fake-pass git "fetch --tags"
fake-pass git pull

run git-elegant pull master
check git-elegant pull master
[ "$status" -eq 0 ]
}
2 changes: 1 addition & 1 deletion src/test/git-elegant-push-after-rebase.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ teardown() {
}

@test "'push-after-rebase': command is available" {
run git-elegant push-after-rebase
check git-elegant push-after-rebase
[ "$status" -eq 0 ]
}
2 changes: 1 addition & 1 deletion src/test/git-elegant-push.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ setup() {
}

@test "'push': command is available" {
run git-elegant push
check git-elegant push
[ "$status" -eq 0 ]
}
2 changes: 1 addition & 1 deletion src/test/git-elegant-rebase.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ teardown() {
}

@test "'rebase': command is available" {
run git-elegant rebase
check git-elegant rebase
[ "$status" -eq 0 ]
}