annotate README.md @ 2:078a17d15fa5

Support calling a spied command with arguments. `b.sh` was not compatible with calling a spied command with arguments. Example: my_test() { spy diff diff --brief test/a test/b ok "$(cat $T/spy.diff.exit)" = 0 } bricolage my_test This was not work. `diff` was complaining about 'illegal option'. This commit fix this.
author Jakukyo Friel <weakish@gmail.com>
date Sun, 29 Mar 2015 08:56:42 +0800
parents bce8021ad094
children 0798045f37b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
1 # Bricolage
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
2
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
3 Bricolage is an ultimately minimal testing library for UNIX Shell. It follows the idea of klud.js and gambiarra.lua
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
4
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
5 ## Usage
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
6
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
7 # include b.sh
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
8 . b.sh
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
9
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
10 # optionally define pass/fail handlers
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
11 pass() {
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
12 echo "PASS $*"
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
13 }
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
14
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
15 fail() {
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
16 echo "FAIL $*"
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
17 }
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
18
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
19 # write your test functions
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
20 mytest() {
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
21 # inside use test assertions
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
22 ok 1 -eq 1
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
23 ok $FOO = "somevalue"
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
24 # mock/spy some commands
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
25 spy ls
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
26 # give fake command output
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
27 echo "file.txt" > $T/spy.ls
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
28 # use fake ls
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
29 ls /some/dir
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
30 # ensure that argument was passed correctly
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
31 ok $(cat $T/spy.ls.args) = "/some/dir"
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
32 # ensure that command return expected output
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
33 ok $(cat $T/spy.ls.stdout) = "file.txt"
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
34 }
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
35
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
36 # run your tests
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
37 bricolage mytest
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
38
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
39 # cleanup
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
40 rm -r $T
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
41
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
42 ## License
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
43
bce8021ad094 added README
Serge A. Zaitsev <zaitsev.serge@gmail.com>
parents:
diff changeset
44 Distributed under MIT license