]> Dogcows Code - chaz/docker-connect/blob - tap.sh
explain how the script works in the documentation
[chaz/docker-connect] / tap.sh
1
2 : <<'=cut'
3 =pod
4
5 =head1 NAME
6
7 tap.sh - Useful subset of TAP (Test Anything Protocol) for shell scripts
8
9 =head1 SYNOPSIS
10
11 . ./tap.sh
12
13 plan 6
14
15 ok '1 = 1' 'Make sure that one equals one'
16 ok '1 != 2' 'Make sure that one is not two'
17
18 is 2 2 'Two is two'
19 isnt 2 3 'Two is not three'
20
21 pass 'It worked!'
22 fail 'Uh oh'
23
24 diag 'This is a diagnostic message'
25 note - <<NOTE
26 Can also use a heredoc for diag and note
27 NOTE
28
29 =head1 SEE ALSO
30
31 * https://testanything.org - TAP website
32
33 =head1 AUTHOR
34
35 Charles McGarvey <chazmcgarvey@brokenzipper.com>
36
37 =head1 LICENSE
38
39 This software is copyright (c) 2017 by Charles McGarvey.
40
41 This is free software, licensed under:
42
43 The MIT (X11) License
44
45 =cut
46
47 next_test_number=1
48
49 plan() {
50 _n=$1; shift
51 echo "1..$_n"
52 }
53
54 ok() {
55 _t=$1; shift
56 _m=$1; shift
57 if eval "test $_t"; then pass "$_m"; else fail "$_m"; fi
58 }
59
60 is() {
61 _a=$1; shift
62 _b=$1; shift
63 _m=$1; shift
64 if [ "$_a" = "$_b" ]
65 then
66 pass "$_m"
67 else
68 fail "$_m"
69 note "Expected: $_b" " Got: $_a"
70 fi
71 }
72
73 isnt() {
74 _a=$1; shift
75 _b=$1; shift
76 _m=$1; shift
77 if [ "$_a" != "$_b" ]
78 then
79 pass "$_m"
80 else
81 fail "$_m"
82 note "Expected: != $_b" " Got: $_a"
83 fi
84 }
85
86 pass() {
87 echo "ok $next_test_number - $@"
88 next_test_number=$(expr $next_test_number + 1)
89 }
90
91 fail() {
92 echo "not ok $next_test_number - $@"
93 next_test_number=$(expr $next_test_number + 1)
94 }
95
96 diag() {
97 if [ "$1" != '-' ]
98 then
99 for _m in "$@"
100 do
101 echo "# $_m"
102 done
103 else
104 while read _m
105 do
106 echo "# $_m"
107 done
108 fi
109 }
110
111 note() {
112 diag "$@"
113 }
114
This page took 0.0398 seconds and 4 git commands to generate.