From 4613c664f339ff98ab3e2ffd9a811108a94fad09 Mon Sep 17 00:00:00 2001 From: Dmytro Serdiuk Date: Fri, 22 Dec 2017 11:11:35 +0200 Subject: [PATCH] Use real git project to test local config Use 'git config ' to read default values. Start local or global configuration from user options. #93 --- src/main/git-elegant-configure | 8 ++--- src/test/addons-common.bash | 1 + src/test/addons-fake.bash | 3 +- src/test/addons-read.bash | 2 +- src/test/git-elegant-configure.bats | 51 ++++++++++++++++------------- 5 files changed, 36 insertions(+), 29 deletions(-) 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-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 ] }