Skip to content

Commit

Permalink
Use real git project to test local config
Browse files Browse the repository at this point in the history
Use 'git config <key>' to read default values.
Start local or global configuration from user options.

#93
  • Loading branch information
extsoft committed Dec 22, 2017
1 parent d4b848b commit 4613c66
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
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
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 ]
}

0 comments on commit 4613c66

Please sign in to comment.