-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to write integration tests
CONTRIBUTING.md describes contribution rules for the project. addons-git.bash allows to work with real git repository and create unit integration tests. #89
- Loading branch information
1 parent
60acb89
commit cbe6bc6
Showing
5 changed files
with
117 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Usage | ||
===== | ||
Installation | ||
------------ | ||
Use `./install.bash dev` to get an installation from the current sources. | ||
|
||
Debug mode | ||
---------- | ||
Use `export GED=1` to switch on the debug of `git elegant` or `unset GED` to switch off. | ||
|
||
Unit tests | ||
========== | ||
[bats](https://github.com/sstephenson/bats) is used for unit testing. | ||
|
||
Addons | ||
------ | ||
Add the following line to the test file if the extension is required: | ||
- `load commons` to have the working test (**mandatory**) | ||
- `load addons-git` to interact with real git repository (**optional**) | ||
- `load fake-cd` to fake `cd` unix command (**optional**) | ||
- `load fake-read` to fake `read` unix command (**optional**) | ||
|
||
@todo #89 Use some name template for the addons. | ||
|
||
Bats restrictions | ||
----------------- | ||
1. **Don't use `setup()` or `teardown()`** bats methods. | ||
2. Use **`check` instead of bats `run`** to execute a command to test. | ||
|
||
Assertions | ||
---------- | ||
- `[ "${lines[0]}" = "+ the space " ]` for a output line (index starts from 0) | ||
- `[ "$status" -eq 2 ]` for a command status | ||
- `[ "${#lines[@]}" -eq 0 ]` for an empty command output | ||
|
||
Test name template | ||
------------------ | ||
Use the following test name template - `'<command args>': <describe what will be tested>` like `'check -s': trailing spaces in the staged changes`. | ||
|
||
@todo #89 Apply test name template for all unit tests. Please update assertions if required. | ||
|
||
Run | ||
--- | ||
Use one of the following commands to run the unit tests: | ||
- `bats src/test` | ||
- `./run-tests` | ||
- `docker run -t --rm -v $PWD:/src -w /src extsoft/rultor-runtime:r24b04p0g2 ./run-tests` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
GIT_REPO_DIR="$BATS_TMPDIR/mock-repo" | ||
FILE_TO_MODIFY=file | ||
|
||
_gilog(){ | ||
echo "$(basename ${BASH_SOURCE[0]}): $@" | ||
} | ||
|
||
_ex() { | ||
_gilog "$@" | ||
eval "$@" | ||
} | ||
|
||
init-repo() { | ||
if [ -n "$GIT_REPO_DIR" ]; then | ||
_ex mkdir -p $GIT_REPO_DIR | ||
_ex cd $GIT_REPO_DIR | ||
_ex git init | ||
_ex git config --local user.email "[email protected]" | ||
_ex git config --local user.name "Elegant Git" | ||
_ex touch $FILE_TO_MODIFY | ||
_ex git add . | ||
_ex git commit -m "Add $FILE_TO_MODIFY" | ||
else | ||
exit 1 | ||
fi | ||
} | ||
|
||
add-unst-change(){ | ||
_ex "echo -e \"$@\" >> $FILE_TO_MODIFY" | ||
} | ||
|
||
add-st-change(){ | ||
add-unst-change "$@" | ||
_ex git add $FILE_TO_MODIFY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,61 @@ | ||
#!/usr/bin/env bats | ||
|
||
load commons | ||
load addons-git | ||
|
||
setup() { | ||
preconditions() { | ||
fake-pass git "diff --check" | ||
fake-pass git "diff --cached --check" | ||
fake-pass git "elegant check --all" | ||
} | ||
|
||
@test "exit code is 0 when run 'git-elegant check -a'" { | ||
preconditions | ||
run git-elegant check -a | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "exit code is 0 when run 'git-elegant check -s'" { | ||
run git-elegant check -s | ||
@test "'check -s': no trailing spaces in the staged changes" { | ||
init-repo && add-st-change "no space" | ||
check git-elegant check -s | ||
[ "$status" -eq 0 ] | ||
[ "${#lines[@]}" -eq 0 ] | ||
} | ||
|
||
@test "'check -s': trailing spaces in the staged changes" { | ||
init-repo && add-st-change "the space " | ||
check git-elegant check -s | ||
[ "$status" -eq 2 ] | ||
[ "${lines[1]}" = "+the space " ] | ||
|
||
} | ||
|
||
@test "exit code is 0 when run 'git-elegant check -u'" { | ||
preconditions | ||
run git-elegant check -u | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "exit code is 0 when run 'git-elegant check --all'" { | ||
preconditions | ||
run git-elegant check --all | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "exit code is 0 when run 'git-elegant check --staged'" { | ||
preconditions | ||
run git-elegant check --staged | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "exit code is 0 when run 'git-elegant check --unstaged'" { | ||
preconditions | ||
run git-elegant check --unstaged | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "exit code is 0 when run 'git-elegant check'" { | ||
preconditions | ||
run git-elegant check | ||
[ "$status" -eq 0 ] | ||
} |