update README for gitorious move
[lnf] / test / test
1 #!/bin/bash
2 # some basic sanity / verification
3
4 # I don't recommend actually running this unless you have a reason to,
5 # since it creates & deletes files, and being a test, it is not as thoroughly
6 # inspected for bugs
7
8 # assumes we have trash-put in path, and that lnf-function is in .. to this files location
9
10
11 # 2 arguments, test that a file in the link location is removed and replaed with a link
12 case1() {
13 touch b
14 lnf -T a b
15 [[ -L b ]]
16 }
17
18 # 2 arguments, test that directory in link location is removed and replaced with a link
19 case2() {
20 mkdir b
21 lnf -T a b
22 [[ -L b ]]
23 }
24
25 # single argument, test that an existing non-empty directory is removed and replaced by a link
26 case3() {
27 mkdir a
28 touch a/b
29 lnf ../a
30 [[ -L a ]]
31 }
32
33 # 4 arguments, 2 of the link locations already contain files.
34 # test that they got removed and replaced by links
35 case4() {
36 mkdir a
37 touch a/b
38 touch a/c
39 lnf b c d a
40 [[ -L a/b && -L a/c && -L a/d ]]
41 }
42
43 # 2 arguments, test that link is made correctly
44 case5() {
45 mkdir b
46 lnf a b
47 [[ -L b/a ]]
48 }
49
50
51
52 cleanup() {
53 rm -rf *
54 }
55
56
57 docases() {
58 for x in {1..5}; do
59 case$x
60 cleanup
61 done
62 }
63
64 source ${0%/*}/../lnf-function
65 # might want to undo this if things go wrong
66 # set -x
67
68 # trap errors, and output a simple bash stack trace
69 set -E;
70 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
71 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"' ERR
72 cd $(mktemp -d)
73 docases
74 # test again, using rm -rf in place of trash-put.
75 # assumes that rm is in /bin and trash-put is in /usr/bin
76 PATH="${PATH//:\/usr\/bin}"
77 PATH="${PATH//\/usr\/bin:}"
78 docases
79
80 echo tests concluded