minor doc update
[lnf] / test / test
1 #!/bin/bash
2 # Copyright (C) 2014 Ian Kelling
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18 # some basic sanity / verification
19
20 # I don't recommend actually running this unless you have a reason to,
21 # since it creates & deletes files, and being a test, it is not as thoroughly
22 # inspected for bugs
23
24 # assumes we have trash-put in path, and that lnf-function is in .. to this files location
25
26
27 # 2 arguments, test that a file in the link location is removed and replaed with a link
28 case1() {
29 touch b
30 lnf -T a b
31 [[ -L b ]]
32 }
33
34 # 2 arguments, test that directory in link location is removed and replaced with a link
35 case2() {
36 mkdir b
37 lnf -T a b
38 [[ -L b ]]
39 }
40
41 # single argument, test that an existing non-empty directory is removed and replaced by a link
42 case3() {
43 mkdir a
44 touch a/b
45 lnf ../a
46 [[ -L a ]]
47 }
48
49 # 4 arguments, 2 of the link locations already contain files.
50 # test that they got removed and replaced by links
51 case4() {
52 mkdir a
53 touch a/b
54 touch a/c
55 lnf b c d a
56 [[ -L a/b && -L a/c && -L a/d ]]
57 }
58
59 # 2 arguments, test that link is made correctly
60 case5() {
61 mkdir b
62 lnf a b
63 [[ -L b/a ]]
64 }
65
66
67
68 cleanup() {
69 rm -rf *
70 }
71
72
73 docases() {
74 for x in {1..5}; do
75 case$x
76 cleanup
77 done
78 }
79
80 PATH="$(readlink -f ${0%/*}/..):$PATH"
81
82 # might want to undo this if things go wrong
83 # set -x
84
85 # trap errors, and output a simple bash stack trace
86 set -E;
87 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
88 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"' ERR
89 tempdir=$(mktemp -d)
90 cd $tempdir
91 docases
92 # test again, using rm -rf in place of trash-put.
93 trash-put() { rm -rf -- "$@"; }
94 export -f trash-put
95 docases
96
97 rm -rf $tempdir
98 echo tests concluded