diff options
| author | Hsieh Chin Fan <typebrook@gmail.com> | 2020-07-02 14:36:18 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <typebrook@gmail.com> | 2020-07-03 14:19:47 +0800 |
| commit | 3caf12f4112fa8b9ce136d5e475461e1ffb76508 (patch) | |
| tree | 4f949c1a14bd0250fed54f94cb335498551446e0 | |
| parent | bfa6223d0da884122ad89508134f3a32ab09d334 (diff) | |
Add bats test
| -rwxr-xr-x | gist | 2 | ||||
| -rw-r--r-- | test.bats | 78 |
2 files changed, 79 insertions, 1 deletions
| @@ -332,7 +332,7 @@ _print_records() { | |||
| 332 | 332 | ||
| 333 | raw_output="$(printf "%-3s" "$index") $message $extra ${status:+${status} }$(_color_pattern '^(\[.+\])' <<<"$description")" | 333 | raw_output="$(printf "%-3s" "$index") $message $extra ${status:+${status} }$(_color_pattern '^(\[.+\])' <<<"$description")" |
| 334 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) | 334 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) |
| 335 | echo -e "$raw_output" | cut -c -$(( $COLUMNS +decorator )) | 335 | echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator )) |
| 336 | done \ | 336 | done \ |
| 337 | | if [[ $display == 'tag' && -n $pin ]]; then | 337 | | if [[ $display == 'tag' && -n $pin ]]; then |
| 338 | local pinned_tags=($pin); local pattern="$(_pattern_pinned_tags ${pinned_tags[@]/#/#})" | 338 | local pinned_tags=($pin); local pattern="$(_pattern_pinned_tags ${pinned_tags[@]/#/#})" |
diff --git a/test.bats b/test.bats new file mode 100644 index 0000000..0316236 --- /dev/null +++ b/test.bats | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | #!/usr/bin/env bats | ||
| 2 | |||
| 3 | export TOOL_NAME='gist' | ||
| 4 | export GIST_USER='phamhsieh' | ||
| 5 | export GIST_API_TOKEN='dd43dc9949a5b4a1d6c7''b779f13af357282016e4' | ||
| 6 | |||
| 7 | @test "Testing ${TOOL_NAME} tool" { | ||
| 8 | echo "${TOOL_NAME}" | ||
| 9 | } | ||
| 10 | |||
| 11 | @test "The help command should print usage" { | ||
| 12 | run ./gist help | ||
| 13 | |||
| 14 | [[ "$status" -eq 0 ]] | ||
| 15 | [[ "${lines[0]}" = "${TOOL_NAME}" ]] | ||
| 16 | } | ||
| 17 | |||
| 18 | @test "Use config command to add configuarion for user" { | ||
| 19 | run ./gist config user ${GIST_USER} | ||
| 20 | [ "$status" -eq 0 ] | ||
| 21 | [ "${lines[0]}" = "user='${GIST_USER}'" ] | ||
| 22 | } | ||
| 23 | |||
| 24 | @test "Use config command to add configuarion for token" { | ||
| 25 | run ./gist config token ${GIST_API_TOKEN} | ||
| 26 | [ "$status" -eq 0 ] | ||
| 27 | [ "${lines[0]}" = "token=${GIST_API_TOKEN}" ] | ||
| 28 | } | ||
| 29 | |||
| 30 | @test "The new command should create a new public gist with gist command" { | ||
| 31 | hint=false run ./gist new --file gist --desc 'Manage gist like a pro' gist | ||
| 32 | [ "$status" -eq 0 ] | ||
| 33 | [[ "${lines[-1]}" =~ ([0-9]+ +https://gist.github.com/[0-9a-z]+) ]] | ||
| 34 | } | ||
| 35 | |||
| 36 | @test "The fetch command should fetch user gists" { | ||
| 37 | hint=false run ./gist fetch | ||
| 38 | [ "$status" -eq 0 ] | ||
| 39 | [[ "${lines[-1]}" =~ ([0-9]+ +https://gist.github.com/[0-9a-z]+) ]] | ||
| 40 | } | ||
| 41 | |||
| 42 | @test "The fetch command should fetch starred gists" { | ||
| 43 | hint=false run ./gist fetch star | ||
| 44 | [ "$status" -eq 0 ] | ||
| 45 | echo ${lines[-1]} | ||
| 46 | [[ "${lines[-1]}" =~ (Not a single valid gist|^ *s[0-9]+ +https://gist.github.com/[0-9a-z]+) ]] | ||
| 47 | } | ||
| 48 | |||
| 49 | @test "No arguments prints the list of gists" { | ||
| 50 | hint=false run ./gist | ||
| 51 | [ "$status" -eq 0 ] | ||
| 52 | [[ "${lines[-1]}" =~ ([0-9]+ +https://gist.github.com/[0-9a-z]+) ]] | ||
| 53 | } | ||
| 54 | |||
| 55 | @test "Specify an index to return the path of cloned repo" { | ||
| 56 | run ./gist 1 --no-action | ||
| 57 | [ "$status" -eq 0 ] | ||
| 58 | [[ "${lines[-1]}" =~ (${HOME}/gist/[0-9a-z]+) ]] | ||
| 59 | } | ||
| 60 | |||
| 61 | @test "The edit command should modify the description of a gist" { | ||
| 62 | ./gist edit 1 "Modified description" | ||
| 63 | run ./gist detail 1 | ||
| 64 | [ "$status" -eq 0 ] | ||
| 65 | [[ "${lines[0]}" =~ (Modified description$) ]] | ||
| 66 | } | ||
| 67 | |||
| 68 | @test "The delete command should delete specified gists" { | ||
| 69 | run ./gist delete 1 --force | ||
| 70 | [ "$status" -eq 0 ] | ||
| 71 | [ "${lines[0]}" = '1 deleted' ] | ||
| 72 | } | ||
| 73 | |||
| 74 | @test "The user command should get the list of public gists from a user" { | ||
| 75 | run ./gist user defunkt | ||
| 76 | [ "$status" -eq 0 ] | ||
| 77 | [[ "${lines[0]}" =~ (https://gist.github.com/[0-9a-z]+ defunkt) ]] | ||
| 78 | } | ||