diff --git a/src/main/git-elegant-configure b/src/main/git-elegant-configure index 6b0a4f0..6baac60 100755 --- a/src/main/git-elegant-configure +++ b/src/main/git-elegant-configure @@ -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" @@ -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 diff --git a/src/test/addons-common.bash b/src/test/addons-common.bash index 7e84063..b1f5ef1 100755 --- a/src/test/addons-common.bash +++ b/src/test/addons-common.bash @@ -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 diff --git a/src/test/addons-fake.bash b/src/test/addons-fake.bash index 3f7c965..6354a72 100644 --- a/src/test/addons-fake.bash +++ b/src/test/addons-fake.bash @@ -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" } diff --git a/src/test/addons-read.bash b/src/test/addons-read.bash index 7ddfbbe..cd84a03 100755 --- a/src/test/addons-read.bash +++ b/src/test/addons-read.bash @@ -3,7 +3,7 @@ set -e read() { - sleep 0 + echo "" } export -f read diff --git a/src/test/git-elegant-add.bats b/src/test/git-elegant-add.bats index 95692fd..adf24d6 100644 --- a/src/test/git-elegant-add.bats +++ b/src/test/git-elegant-add.bats @@ -15,6 +15,6 @@ setup() { } @test "'add': successful adding of modified file" { - run git-elegant add + check git-elegant add [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-check.bats b/src/test/git-elegant-check.bats index 5a11e01..287f890 100644 --- a/src/test/git-elegant-check.bats +++ b/src/test/git-elegant-check.bats @@ -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 ] } diff --git a/src/test/git-elegant-clear-local.bats b/src/test/git-elegant-clear-local.bats index fd35bdb..f0cd5ae 100644 --- a/src/test/git-elegant-clear-local.bats +++ b/src/test/git-elegant-clear-local.bats @@ -15,6 +15,6 @@ teardown() { } @test "'clear-local': command is available" { - run git-elegant clear-local + check git-elegant clear-local [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-clone.bats b/src/test/git-elegant-clone.bats index 4232de0..96861e7 100644 --- a/src/test/git-elegant-clone.bats +++ b/src/test/git-elegant-clone.bats @@ -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 ] } diff --git a/src/test/git-elegant-commands.bats b/src/test/git-elegant-commands.bats index dccf42b..af1c668 100644 --- a/src/test/git-elegant-commands.bats +++ b/src/test/git-elegant-commands.bats @@ -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" ] @@ -24,6 +24,6 @@ teardown() { } @test "'commands': default exit code is 0" { - run git-elegant commands + check git-elegant commands [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-configure.bats b/src/test/git-elegant-configure.bats index d686f88..b86f202 100644 --- a/src/test/git-elegant-configure.bats +++ b/src/test/git-elegant-configure.bats @@ -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" @@ -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 [elegant-git@example.com]: " ] + [ "${lines[2]}" = "commit message won't start with [|]: " ] + [ "${lines[3]}" = "whitespace issues on patching [fix]: " ] + [ ${#lines[@]} -eq 4 ] } diff --git a/src/test/git-elegant-feature.bats b/src/test/git-elegant-feature.bats index dd342ab..354b0d9 100644 --- a/src/test/git-elegant-feature.bats +++ b/src/test/git-elegant-feature.bats @@ -14,17 +14,17 @@ 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" ]] } @@ -32,13 +32,13 @@ teardown() { 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 ] } @@ -46,6 +46,6 @@ teardown() { 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 ] } diff --git a/src/test/git-elegant-init.bats b/src/test/git-elegant-init.bats index 20781e2..b87e0b7 100644 --- a/src/test/git-elegant-init.bats +++ b/src/test/git-elegant-init.bats @@ -14,6 +14,6 @@ teardown() { } @test "'init': command is available" { - run git-elegant init + check git-elegant init [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-pull.bats b/src/test/git-elegant-pull.bats index bba386a..8316708 100644 --- a/src/test/git-elegant-pull.bats +++ b/src/test/git-elegant-pull.bats @@ -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 ] } @@ -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 ] } diff --git a/src/test/git-elegant-push-after-rebase.bats b/src/test/git-elegant-push-after-rebase.bats index 32e7cba..ecc0ccb 100644 --- a/src/test/git-elegant-push-after-rebase.bats +++ b/src/test/git-elegant-push-after-rebase.bats @@ -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 ] } diff --git a/src/test/git-elegant-push.bats b/src/test/git-elegant-push.bats index b3c95ba..946807a 100644 --- a/src/test/git-elegant-push.bats +++ b/src/test/git-elegant-push.bats @@ -14,6 +14,6 @@ setup() { } @test "'push': command is available" { - run git-elegant push + check git-elegant push [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-rebase.bats b/src/test/git-elegant-rebase.bats index 8304fb6..e0704e9 100644 --- a/src/test/git-elegant-rebase.bats +++ b/src/test/git-elegant-rebase.bats @@ -13,6 +13,6 @@ teardown() { } @test "'rebase': command is available" { - run git-elegant rebase + check git-elegant rebase [ "$status" -eq 0 ] }