X-Git-Url: https://iankelling.org/git/?p=lnf;a=blobdiff_plain;f=test%2Ftest;fp=test%2Ftest;h=218b67c1ddd981ebadb9dd2c863c7730cd7ddfa9;hp=c2bdb6a95bb612573967deba3f82f8ae00f05b81;hb=a5d3fe7ecee597e33e7081f45847a6c9f25a22fb;hpb=15c4639b1ee74247ac931088eea77e3ea37ba7c3 diff --git a/test/test b/test/test index c2bdb6a..218b67c 100755 --- a/test/test +++ b/test/test @@ -1,42 +1,43 @@ #!/bin/bash # 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 + [[ -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 + [[ -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 ]] } cleanup() { @@ -58,14 +59,17 @@ docases() { source ${0%/*}/../lnf-function # 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) docases -trash-put() { - rm -rf "$@" -} +# test again, using rm -rf in place of trash-put. +# assumes that rm is in /bin and trash-put is in /usr/bin +PATH="${PATH//:\/usr\/bin}" +PATH="${PATH//\/usr\/bin:}" docases -echo success +echo tests concluded