Skip to content

Commit

Permalink
Unify the assertions look for all tests
Browse files Browse the repository at this point in the history
For consistency, now all tests follow the following:
1. all assertions are in double square quotes like [[ .... ]]
2. left part of the assertions is described without quotes
3. all variables are in ${...} format
  • Loading branch information
extsoft committed Apr 5, 2020
1 parent 940d3d1 commit 821bc43
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 184 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,17 @@ Also, there are several optional addons which can be useful in some circumstance
5. Do not fake `git-elegant` commands within the tests.

#### Assertions
- `[[ "${lines[0]}" = "+ the space " ]]` for an output line (index starts from 0)
- `[[ "$status" -eq 2 ]]` for a command status
- `[[ "${#lines[@]}" -eq 0 ]]` for a length of command output
- `[[ "${lines[@]}" =~ "exact string" ]]` for an output line within whole output
- `[[ ${status} -eq 2 ]]` for a command status
- `[[ ${#lines[@]} -eq 0 ]]` for a length of command output
- `[[ ${lines[0]} = "+ the space " ]]` for an output line (index starts from 0)
- `[[ ${lines[@]} =~ "exact string" ]]` for an output line within whole output

#### Test name template
Use the following test name template - `'<command args>': <describe what will be tested>` like
`'clone-repository': raise an error if cloneable URL isn't set`.
Use the following test name template - `'<command>': <describes the behavior that will be tested>`
like `'clone-repository': stops with exit code 45 if cloneable URL is not set`.

The behavior should be descriptive-style (`stops with exit code 45 if cloneable URL is not set`)
rather than imperative-style (`stop with exit code 45 if cloneable URL is not set`).

### Updating documentation
In order to get the documentation preview locally, please install required dependencies with
Expand Down
96 changes: 48 additions & 48 deletions tests/git-elegant-acquire-git.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,73 +18,73 @@ teardown() {

@test "'acquire-git': all configurations work as expected" {
check git-elegant acquire-git
[[ "${status}" -eq 0 ]]
[[ ${status} -eq 0 ]]
}

@test "'acquire-git': basics are configured as expected" {
check git-elegant acquire-git
[[ "${lines[@]}" =~ "Please hit enter if you wish {default value}." ]]
[[ "${lines[@]}" =~ "What is your user name? {Elegant Git}: " ]]
[[ "${lines[@]}" =~ "==>> git config --global user.name Elegant Git" ]]
[[ "${lines[@]}" =~ "What is your user email? {[email protected]}: " ]]
[[ "${lines[@]}" =~ "==>> git config --global user.email [email protected]" ]]
[[ "${lines[@]}" =~ "Please specify a command to start the editor. {vi}: " ]]
[[ "${lines[@]}" =~ "==>> git config --global core.editor vi" ]]
[[ ${lines[@]} =~ "Please hit enter if you wish {default value}." ]]
[[ ${lines[@]} =~ "What is your user name? {Elegant Git}: " ]]
[[ ${lines[@]} =~ "==>> git config --global user.name Elegant Git" ]]
[[ ${lines[@]} =~ "What is your user email? {[email protected]}: " ]]
[[ ${lines[@]} =~ "==>> git config --global user.email [email protected]" ]]
[[ ${lines[@]} =~ "Please specify a command to start the editor. {vi}: " ]]
[[ ${lines[@]} =~ "==>> git config --global core.editor vi" ]]
}

@test "'acquire-git': standards are configured as expected on Windows" {
fake-pass "uname -s" Windows
check git-elegant acquire-git
[[ "${lines[@]}" =~ "==>> git config --global core.commentChar |" ]]
[[ "${lines[@]}" =~ "==>> git config --global apply.whitespace fix" ]]
[[ "${lines[@]}" =~ "==>> git config --global fetch.prune true" ]]
[[ "${lines[@]}" =~ "==>> git config --global fetch.pruneTags false" ]]
[[ "${lines[@]}" =~ "==>> git config --global core.autocrlf true" ]]
[[ "${lines[@]}" =~ "==>> git config --global pull.rebase true" ]]
[[ "${lines[@]}" =~ "==>> git config --global rebase.autoStash false" ]]
[[ "${lines[@]}" =~ "==>> git config --global elegant.acquired true" ]]
[[ ${lines[@]} =~ "==>> git config --global core.commentChar |" ]]
[[ ${lines[@]} =~ "==>> git config --global apply.whitespace fix" ]]
[[ ${lines[@]} =~ "==>> git config --global fetch.prune true" ]]
[[ ${lines[@]} =~ "==>> git config --global fetch.pruneTags false" ]]
[[ ${lines[@]} =~ "==>> git config --global core.autocrlf true" ]]
[[ ${lines[@]} =~ "==>> git config --global pull.rebase true" ]]
[[ ${lines[@]} =~ "==>> git config --global rebase.autoStash false" ]]
[[ ${lines[@]} =~ "==>> git config --global elegant.acquired true" ]]
# negative checks are used instead of checking commands size
[[ ! "${lines[@]}" =~ "==>> git config --global credential.helper osxkeychain" ]]
[[ ! "${lines[@]}" =~ "==>> git config --global core.autocrlf input" ]]
[[ ! ${lines[@]} =~ "==>> git config --global credential.helper osxkeychain" ]]
[[ ! ${lines[@]} =~ "==>> git config --global core.autocrlf input" ]]
}

@test "'acquire-git': standards are configured as expected on Linux" {
fake-pass "uname -s" Linux
check git-elegant acquire-git
[[ "${lines[@]}" =~ "==>> git config --global core.commentChar |" ]]
[[ "${lines[@]}" =~ "==>> git config --global apply.whitespace fix" ]]
[[ "${lines[@]}" =~ "==>> git config --global fetch.prune true" ]]
[[ "${lines[@]}" =~ "==>> git config --global fetch.pruneTags false" ]]
[[ "${lines[@]}" =~ "==>> git config --global core.autocrlf input" ]]
[[ "${lines[@]}" =~ "==>> git config --global pull.rebase true" ]]
[[ "${lines[@]}" =~ "==>> git config --global rebase.autoStash false" ]]
[[ "${lines[@]}" =~ "==>> git config --global elegant.acquired true" ]]
[[ ${lines[@]} =~ "==>> git config --global core.commentChar |" ]]
[[ ${lines[@]} =~ "==>> git config --global apply.whitespace fix" ]]
[[ ${lines[@]} =~ "==>> git config --global fetch.prune true" ]]
[[ ${lines[@]} =~ "==>> git config --global fetch.pruneTags false" ]]
[[ ${lines[@]} =~ "==>> git config --global core.autocrlf input" ]]
[[ ${lines[@]} =~ "==>> git config --global pull.rebase true" ]]
[[ ${lines[@]} =~ "==>> git config --global rebase.autoStash false" ]]
[[ ${lines[@]} =~ "==>> git config --global elegant.acquired true" ]]
# negative checks are used instead of checking commands size
[[ ! "${lines[@]}" =~ "==>> git config --global credential.helper osxkeychain" ]]
[[ ! "${lines[@]}" =~ "==>> git config --global core.autocrlf true" ]]
[[ ! ${lines[@]} =~ "==>> git config --global credential.helper osxkeychain" ]]
[[ ! ${lines[@]} =~ "==>> git config --global core.autocrlf true" ]]
}

@test "'acquire-git': standards are configured as expected on Darwin" {
fake-pass "uname -s" Darwin
check git-elegant acquire-git
[[ "${lines[@]}" =~ "==>> git config --global core.commentChar |" ]]
[[ "${lines[@]}" =~ "==>> git config --global apply.whitespace fix" ]]
[[ "${lines[@]}" =~ "==>> git config --global fetch.prune true" ]]
[[ "${lines[@]}" =~ "==>> git config --global fetch.pruneTags false" ]]
[[ "${lines[@]}" =~ "==>> git config --global core.autocrlf input" ]]
[[ "${lines[@]}" =~ "==>> git config --global pull.rebase true" ]]
[[ "${lines[@]}" =~ "==>> git config --global rebase.autoStash false" ]]
[[ "${lines[@]}" =~ "==>> git config --global credential.helper osxkeychain" ]]
[[ "${lines[@]}" =~ "==>> git config --global elegant.acquired true" ]]
[[ ${lines[@]} =~ "==>> git config --global core.commentChar |" ]]
[[ ${lines[@]} =~ "==>> git config --global apply.whitespace fix" ]]
[[ ${lines[@]} =~ "==>> git config --global fetch.prune true" ]]
[[ ${lines[@]} =~ "==>> git config --global fetch.pruneTags false" ]]
[[ ${lines[@]} =~ "==>> git config --global core.autocrlf input" ]]
[[ ${lines[@]} =~ "==>> git config --global pull.rebase true" ]]
[[ ${lines[@]} =~ "==>> git config --global rebase.autoStash false" ]]
[[ ${lines[@]} =~ "==>> git config --global credential.helper osxkeychain" ]]
[[ ${lines[@]} =~ "==>> git config --global elegant.acquired true" ]]
# negative checks are used instead of checking commands size
[[ ! "${lines[@]}" =~ "==>> git config --global core.autocrlf true" ]]
[[ ! ${lines[@]} =~ "==>> git config --global core.autocrlf true" ]]
}

@test "'acquire-git': new aliases are configured as expected" {
check git-elegant acquire-git
for next in $(git-elegant show-commands); do
echo "Test aliasing of '${next}' command"
[[ "${lines[@]}" =~ "==>> git config --global alias.${next} elegant ${next}" ]]
[[ ${lines[@]} =~ "==>> git config --global alias.${next} elegant ${next}" ]]
echo "Tested successfully!"
done
}
Expand All @@ -93,26 +93,26 @@ teardown() {
repo git config --global "alias.aaa" "\"elegant aaa\""
repo git config --global "alias.bbb" "\"elegant bbb\""
check git-elegant acquire-git
[[ "$status" -eq 0 ]]
[[ "${lines[@]}" =~ "2 Elegant Git aliases were removed." ]]
[[ ${status} -eq 0 ]]
[[ ${lines[@]} =~ "2 Elegant Git aliases were removed." ]]
}

@test "'acquire-git': a message is displayed if global configuration is disabled" {
read-clean
read-answer "n"
check git-elegant acquire-git
[[ "$status" -eq 0 ]]
[[ "${lines[@]}" =~ "You've decided to stay with local configurations. Great!" ]]
[[ ${status} -eq 0 ]]
[[ ${lines[@]} =~ "You've decided to stay with local configurations. Great!" ]]
}

@test "'acquire-git': the basics are not changed if they are already configured" {
repo git config --global user.name aaaa
repo git config --global user.email aaaa
repo git config --global core.editor aaaa
check git-elegant acquire-git
[[ "$status" -eq 0 ]]
[[ "${lines[@]}" =~ "==>> git config --global user.name aaaa" ]]
[[ "${lines[@]}" =~ "==>> git config --global user.email aaaa" ]]
[[ "${lines[@]}" =~ "==>> git config --global core.editor aaaa" ]]
[[ ! "${lines[@]}" =~ "Please hit enter if you wish {default value}." ]]
[[ ${status} -eq 0 ]]
[[ ${lines[@]} =~ "==>> git config --global user.name aaaa" ]]
[[ ${lines[@]} =~ "==>> git config --global user.email aaaa" ]]
[[ ${lines[@]} =~ "==>> git config --global core.editor aaaa" ]]
[[ ! ${lines[@]} =~ "Please hit enter if you wish {default value}." ]]
}
92 changes: 46 additions & 46 deletions tests/git-elegant-acquire-repository.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,69 @@ teardown() {

@test "'acquire-repository': all configurations work as expected" {
check git-elegant acquire-repository
[[ "${status}" -eq 0 ]]
[[ ${status} -eq 0 ]]
}

@test "'acquire-repository': basics are configured as expected" {
check git-elegant acquire-repository
[[ "${lines[@]}" =~ "What is your user name? {Elegant Git}: " ]]
[[ "${lines[@]}" =~ "==>> git config --local user.name Elegant Git" ]]
[[ "${lines[@]}" =~ "What is your user email? {[email protected]}: " ]]
[[ "${lines[@]}" =~ "==>> git config --local user.email [email protected]" ]]
[[ "${lines[@]}" =~ "Please specify a command to start the editor. {vi}: " ]]
[[ "${lines[@]}" =~ "==>> git config --local core.editor vi" ]]
[[ ${lines[@]} =~ "What is your user name? {Elegant Git}: " ]]
[[ ${lines[@]} =~ "==>> git config --local user.name Elegant Git" ]]
[[ ${lines[@]} =~ "What is your user email? {[email protected]}: " ]]
[[ ${lines[@]} =~ "==>> git config --local user.email [email protected]" ]]
[[ ${lines[@]} =~ "Please specify a command to start the editor. {vi}: " ]]
[[ ${lines[@]} =~ "==>> git config --local core.editor vi" ]]
}

@test "'acquire-repository': standards are configured as expected on Windows" {
fake-pass "uname -s" Windows
check git-elegant acquire-repository
[[ "${lines[@]}" =~ "==>> git config --local core.commentChar |" ]]
[[ "${lines[@]}" =~ "==>> git config --local apply.whitespace fix" ]]
[[ "${lines[@]}" =~ "==>> git config --local fetch.prune true" ]]
[[ "${lines[@]}" =~ "==>> git config --local fetch.pruneTags false" ]]
[[ "${lines[@]}" =~ "==>> git config --local core.autocrlf true" ]]
[[ "${lines[@]}" =~ "==>> git config --local pull.rebase true" ]]
[[ "${lines[@]}" =~ "==>> git config --local rebase.autoStash false" ]]
[[ ${lines[@]} =~ "==>> git config --local core.commentChar |" ]]
[[ ${lines[@]} =~ "==>> git config --local apply.whitespace fix" ]]
[[ ${lines[@]} =~ "==>> git config --local fetch.prune true" ]]
[[ ${lines[@]} =~ "==>> git config --local fetch.pruneTags false" ]]
[[ ${lines[@]} =~ "==>> git config --local core.autocrlf true" ]]
[[ ${lines[@]} =~ "==>> git config --local pull.rebase true" ]]
[[ ${lines[@]} =~ "==>> git config --local rebase.autoStash false" ]]
# negative checks are used instead of checking commands size
[[ ! "${lines[@]}" =~ "==>> git config --local credential.helper osxkeychain" ]]
[[ ! "${lines[@]}" =~ "==>> git config --local core.autocrlf input" ]]
[[ ! ${lines[@]} =~ "==>> git config --local credential.helper osxkeychain" ]]
[[ ! ${lines[@]} =~ "==>> git config --local core.autocrlf input" ]]
}

@test "'acquire-repository': standards are configured as expected on Linux" {
fake-pass "uname -s" Linux
check git-elegant acquire-repository
[[ "${lines[@]}" =~ "==>> git config --local core.commentChar |" ]]
[[ "${lines[@]}" =~ "==>> git config --local apply.whitespace fix" ]]
[[ "${lines[@]}" =~ "==>> git config --local fetch.prune true" ]]
[[ "${lines[@]}" =~ "==>> git config --local fetch.pruneTags false" ]]
[[ "${lines[@]}" =~ "==>> git config --local core.autocrlf input" ]]
[[ "${lines[@]}" =~ "==>> git config --local pull.rebase true" ]]
[[ "${lines[@]}" =~ "==>> git config --local rebase.autoStash false" ]]
[[ ${lines[@]} =~ "==>> git config --local core.commentChar |" ]]
[[ ${lines[@]} =~ "==>> git config --local apply.whitespace fix" ]]
[[ ${lines[@]} =~ "==>> git config --local fetch.prune true" ]]
[[ ${lines[@]} =~ "==>> git config --local fetch.pruneTags false" ]]
[[ ${lines[@]} =~ "==>> git config --local core.autocrlf input" ]]
[[ ${lines[@]} =~ "==>> git config --local pull.rebase true" ]]
[[ ${lines[@]} =~ "==>> git config --local rebase.autoStash false" ]]
# negative checks are used instead of checking commands size
[[ ! "${lines[@]}" =~ "==>> git config --local credential.helper osxkeychain" ]]
[[ ! "${lines[@]}" =~ "==>> git config --local core.autocrlf true" ]]
[[ ! ${lines[@]} =~ "==>> git config --local credential.helper osxkeychain" ]]
[[ ! ${lines[@]} =~ "==>> git config --local core.autocrlf true" ]]
}

@test "'acquire-repository': standards are configured as expected on Darwin" {
fake-pass "uname -s" Darwin
check git-elegant acquire-repository
[[ "${lines[@]}" =~ "==>> git config --local core.commentChar |" ]]
[[ "${lines[@]}" =~ "==>> git config --local apply.whitespace fix" ]]
[[ "${lines[@]}" =~ "==>> git config --local fetch.prune true" ]]
[[ "${lines[@]}" =~ "==>> git config --local fetch.pruneTags false" ]]
[[ "${lines[@]}" =~ "==>> git config --local core.autocrlf input" ]]
[[ "${lines[@]}" =~ "==>> git config --local pull.rebase true" ]]
[[ "${lines[@]}" =~ "==>> git config --local rebase.autoStash false" ]]
[[ "${lines[@]}" =~ "==>> git config --local credential.helper osxkeychain" ]]
[[ ${lines[@]} =~ "==>> git config --local core.commentChar |" ]]
[[ ${lines[@]} =~ "==>> git config --local apply.whitespace fix" ]]
[[ ${lines[@]} =~ "==>> git config --local fetch.prune true" ]]
[[ ${lines[@]} =~ "==>> git config --local fetch.pruneTags false" ]]
[[ ${lines[@]} =~ "==>> git config --local core.autocrlf input" ]]
[[ ${lines[@]} =~ "==>> git config --local pull.rebase true" ]]
[[ ${lines[@]} =~ "==>> git config --local rebase.autoStash false" ]]
[[ ${lines[@]} =~ "==>> git config --local credential.helper osxkeychain" ]]
# negative checks are used instead of checking commands size
[[ ! "${lines[@]}" =~ "==>> git config --local core.autocrlf true" ]]
[[ ! ${lines[@]} =~ "==>> git config --local core.autocrlf true" ]]
}

@test "'acquire-repository': new aliases are configured as expected" {
check git-elegant acquire-repository
for next in $(git-elegant show-commands); do
echo "Test aliasing of '${next}' command"
[[ "${lines[@]}" =~ "==>> git config --local alias.${next} elegant ${next}" ]]
[[ ${lines[@]} =~ "==>> git config --local alias.${next} elegant ${next}" ]]
echo "Tested successfully!"
done
}
Expand All @@ -89,8 +89,8 @@ teardown() {
repo git config --local "alias.aaa" "\"elegant aaa\""
repo git config --local "alias.bbb" "\"elegant bbb\""
check git-elegant acquire-repository
[[ "$status" -eq 0 ]]
[[ "${lines[@]}" =~ "2 Elegant Git aliases were removed." ]]
[[ ${status} -eq 0 ]]
[[ ${lines[@]} =~ "2 Elegant Git aliases were removed." ]]
}

@test "'acquire-repository': 'elegant.acquired' affects configuration correctly" {
Expand All @@ -99,15 +99,15 @@ teardown() {
repo git config --global "alias.bbb" "\"elegant bbb\""
repo git config --global "elegant.acquired" "true"
check git-elegant acquire-repository
[[ "${lines[@]}" =~ "What is your user name? {Elegant Git}: " ]]
[[ "${lines[@]}" =~ "==>> git config --local user.name Elegant Git" ]]
[[ "${lines[@]}" =~ "What is your user email? {[email protected]}: " ]]
[[ "${lines[@]}" =~ "==>> git config --local user.email [email protected]" ]]
[[ ! "${lines[@]}" =~ "Please specify a command to start the editor. {vi}: " ]]
[[ ! "${lines[@]}" =~ "==>> git config --local core.editor vi" ]]
[[ ! "${lines[@]}" =~ "==>> git config --local core.commentChar |" ]]
[[ "${lines[@]}" =~ "1 Elegant Git aliases were removed." ]]
[[ ! "${lines[@]}" =~ "==>> git config --local alias.acquire-repository elegant acquire-repository" ]]
[[ ${lines[@]} =~ "What is your user name? {Elegant Git}: " ]]
[[ ${lines[@]} =~ "==>> git config --local user.name Elegant Git" ]]
[[ ${lines[@]} =~ "What is your user email? {[email protected]}: " ]]
[[ ${lines[@]} =~ "==>> git config --local user.email [email protected]" ]]
[[ ! ${lines[@]} =~ "Please specify a command to start the editor. {vi}: " ]]
[[ ! ${lines[@]} =~ "==>> git config --local core.editor vi" ]]
[[ ! ${lines[@]} =~ "==>> git config --local core.commentChar |" ]]
[[ ${lines[@]} =~ "1 Elegant Git aliases were removed." ]]
[[ ! ${lines[@]} =~ "==>> git config --local alias.acquire-repository elegant acquire-repository" ]]
}

@test "'acquire-repository': configures a signature if GPG key is provided" {
Expand Down
8 changes: 4 additions & 4 deletions tests/git-elegant-amend-work.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ teardown() {
fake-pass "git commit --amend"
repo git checkout -b test
check git-elegant amend-work
[[ "${status}" -eq 0 ]]
[[ ${status} -eq 0 ]]
}

@test "'amend-work': exit code is 42 when current local branch is master" {
check git-elegant amend-work
[[ "${status}" -eq 42 ]]
[[ "${lines[@]}" =~ "== No commits to 'master' branch. Please read more on https://elegant-git.bees-hive.org ==" ]]
[[ "${lines[@]}" =~ "== Try 'git elegant start-work' prior to retrying this command. ==" ]]
[[ ${status} -eq 42 ]]
[[ ${lines[@]} =~ "== No commits to 'master' branch. Please read more on https://elegant-git.bees-hive.org ==" ]]
[[ ${lines[@]} =~ "== Try 'git elegant start-work' prior to retrying this command. ==" ]]
}
11 changes: 6 additions & 5 deletions tests/git-elegant-clone-repository.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ teardown() {
fake-clean
}

@test "'clone-repository': raise an error if cloneable URL isn't set" {
check git-elegant clone-repository
[[ "${lines[0]}" =~ "Cloneable URL is not set" ]]
@test "'clone-repository': stops with exit code 45 if cloneable URL is not set" {
check git-elegant clone-repository
[[ ${status} -eq 45 ]]
[[ ${lines[0]} =~ "Cloneable URL is not set" ]]
}

@test "'clone-repository': clone the repo" {
check git-elegant clone-repository https://github.com/extsoft/elegant-git.git
[ "$status" -eq 0 ]
check git-elegant clone-repository https://github.com/extsoft/elegant-git.git
[[ ${status} -eq 0 ]]
}
Loading

0 comments on commit 821bc43

Please sign in to comment.