@cryptotaxi247 / kubo / commits / e5f24dc26

sharness: expanded on readme

Juan Batiz-Benet committed Jan 4, 2015 at 22:22 UTC e5f24dc26b8469be623a8f6105f54f4171b19c3a
1 file changed +63
test/README.md
+63
@@ -24,3 +24,66 @@ Please do not change anything in the "lib/sharness" directory.
24 If you really need some changes in sharness, please fork it from
25 [its cannonical repo](https://github.com/mlafeldt/sharness/) and
26 send pull requests there.
27 +
28 +## Writing Tests
29 +
30 +
31 +### Diagnostics
32 +
33 +Make your test case output helpful for when running sharness verbosely.
34 +This means cating certain files, or running diagnostic commands.
35 +For example:
36 +
37 +```
38 +test_expect_success ".go-ipfs/ has been created" '
39 + test -d ".go-ipfs" &&
40 + test -f ".go-ipfs/config" &&
41 + test -d ".go-ipfs/datastore" ||
42 + fsh ls -al .go-ipfs
43 +'
44 +```
45 +
46 +The `|| ...` is a diagnostic run when the preceding command fails.
47 +`bin/fsh` is a trivial script that echoes the args, runs the cmd,
48 +and then also fails, making sure the test case fails. (wouldnt want
49 +the diagnostic accidentally returning true and making it _seem_ like
50 +the test case succeeded!).
51 +
52 +
53 +### Testing commands on daemon or mounted
54 +
55 +Use the provided functions in `lib/test-lib.sh` to run the daemon or mount:
56 +
57 +To init, run daemon, and mount in one go:
58 +
59 +```sh
60 +test_launch_ipfs_daemon_and_mount
61 +
62 +test_expect_success "'ipfs add --help' succeeds" '
63 + ipfs add --help >actual
64 +'
65 +
66 +# other tests here...
67 +
68 +# dont forget to kill the daemon!!
69 +test_kill_ipfs_daemon
70 +```
71 +
72 +To init, run daemon, and then mount separately:
73 +
74 +```sh
75 +test_init_ipfs
76 +
77 +# tests inited but not running here
78 +
79 +test_launch_ipfs_daemon
80 +
81 +# tests running but not mounted here
82 +
83 +test_mount_ipfs
84 +
85 +# tests mounted here
86 +
87 +# dont forget to kill the daemon!!
88 +test_kill_ipfs_daemon
89 +```