218b67c1ddd981ebadb9dd2c863c7730cd7ddfa9
[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 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 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 cleanup() {
44 rm -rf *
45 }
46
47
48 docases() {
49 case1
50 cleanup
51 case2
52 cleanup
53 case3
54 cleanup
55 case4
56 cleanup
57 }
58
59 source ${0%/*}/../lnf-function
60 # might want to undo this if things go wrong
61 # set -x
62
63 # trap errors, and output a simple bash stack trace
64 set -E;
65 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
66 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"' ERR
67 cd $(mktemp -d)
68 docases
69 # test again, using rm -rf in place of trash-put.
70 # assumes that rm is in /bin and trash-put is in /usr/bin
71 PATH="${PATH//:\/usr\/bin}"
72 PATH="${PATH//\/usr\/bin:}"
73 docases
74
75 echo tests concluded