aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <typebrook@gmail.com>2020-07-03 14:19:57 +0800
committerHsieh Chin Fan <typebrook@gmail.com>2020-07-03 16:54:22 +0800
commit4e0539c1488e1e84deb2be221d0acc420c5818c6 (patch)
tree0f8b10731e773f9d5b62770ac6d9af33318dd7a4
parentbfa6223d0da884122ad89508134f3a32ab09d334 (diff)
parent3caf12f4112fa8b9ce136d5e475461e1ffb76508 (diff)
Merge branch 'bat-test'
-rwxr-xr-xgist3
-rw-r--r--test.bats78
2 files changed, 79 insertions, 2 deletions
diff --git a/gist b/gist
index 0cfca1e..b54aaaa 100755
--- a/gist
+++ b/gist
@@ -49,7 +49,6 @@
49# Since now a gist is a local cloned repo 49# Since now a gist is a local cloned repo
50# It is your business to do git commit and git push 50# It is your business to do git commit and git push
51 51
52# TODO Add bat tests
53# TODO Add mark when user is in repo 52# TODO Add mark when user is in repo
54# TODO change gist from public to private or reverse versa 53# TODO change gist from public to private or reverse versa
55# TODO feature to exclude tag-value or grep-string 54# TODO feature to exclude tag-value or grep-string
@@ -332,7 +331,7 @@ _print_records() {
332 331
333 raw_output="$(printf "%-3s" "$index") $message $extra ${status:+${status} }$(_color_pattern '^(\[.+\])' <<<"$description")" 332 raw_output="$(printf "%-3s" "$index") $message $extra ${status:+${status} }$(_color_pattern '^(\[.+\])' <<<"$description")"
334 decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) 333 decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 ))
335 echo -e "$raw_output" | cut -c -$(( $COLUMNS +decorator )) 334 echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator ))
336 done \ 335 done \
337 | if [[ $display == 'tag' && -n $pin ]]; then 336 | if [[ $display == 'tag' && -n $pin ]]; then
338 local pinned_tags=($pin); local pattern="$(_pattern_pinned_tags ${pinned_tags[@]/#/#})" 337 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
3export TOOL_NAME='gist'
4export GIST_USER='phamhsieh'
5export 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}