license change
[lnf] / test / test
index c2bdb6a95bb612573967deba3f82f8ae00f05b81..c3b90e166a0d7cc6d02dea10b7de23437aff6b3d 100755 (executable)
--- a/test/test
+++ b/test/test
 #!/bin/bash
+# I, Ian Kelling, follow the GNU license recommendations at
+# https://www.gnu.org/licenses/license-recommendations.en.html. They
+# recommend that small programs, < 300 lines, be licensed under the
+# Apache License 2.0. This file contains or is part of one or more small
+# programs. If a small program grows beyond 300 lines, I plan to switch
+# its license to GPL.
+
+# Copyright 2024 Ian Kelling
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+
 # some basic sanity / verification
-# assumes we have trash-put in path
+
 # I don't recommend actually running this unless you have a reason to,
 # since it creates & deletes files, and being a test, it is not as thoroughly
 # inspected for bugs
 
-err() {
-    echo error
-}
-# target linkname
+# assumes we have trash-put in path, and that lnf-function is in .. to this files location
+
+
+# 2 arguments, test that a file in the link location is removed and replaed with a link
 case1() {
     touch b
-    lnf a b
-    [[ -L b ]] || err
+    lnf -T a b
+    [[ -L b ]]
 }
 
-# target directory
+# 2 arguments, test that directory in link location is removed and replaced with a link
 case2() {
     mkdir b
-    lnf a b
-    [[ -L b/a ]] || err
+    lnf -T a b
+    [[ -L b ]]
 }
 
-# target
+# single argument, test that an existing non-empty directory is removed and replaced by a link
 case3() {
     mkdir a
     touch a/b
     lnf ../a
-    [[ -L a ]] || err
+    [[ -L a ]]
 }
 
-# target target directory
+# 4 arguments, 2 of the link locations already contain files.
+# test that they got removed and replaced by links
 case4() {
     mkdir a
     touch a/b
     touch a/c
     lnf b c d a
-    [[ -L a/b && -L a/c && -L a/d ]] || err
+    [[ -L a/b && -L a/c && -L a/d ]]
+}
+
+# 2 arguments, test that link is made correctly
+case5() {
+    mkdir b
+    lnf a b
+    [[ -L b/a ]]
 }
 
+
+
 cleanup() {
     rm -rf *
 }
 
 
 docases() {
-    case1
-    cleanup
-    case2
-    cleanup
-    case3
-    cleanup
-    case4
-    cleanup
+    for x in {1..5}; do
+        case$x
+        cleanup
+    done
 }
 
-source ${0%/*}/../lnf-function
+PATH="$(readlink -f ${0%/*}/..):$PATH"
+
 # might want to undo this if things go wrong
 # set -x
-set -eE;
+
+# trap errors, and output a simple bash stack trace
+set -E;
 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\"  }\$?=$?"' ERR
-cd $(mktemp -d)
+tempdir=$(mktemp -d)
+cd $tempdir
 docases
-trash-put() {
-    rm -rf "$@"
-}
+# test again, using rm -rf in place of trash-put.
+trash-put() { rm -rf -- "$@"; }
+export -f trash-put
 docases
 
-echo success
+rm -rf $tempdir
+echo tests concluded