Added tests and makefile (mainly for installing)

This commit is contained in:
Bruce Hill 2020-04-06 23:18:08 -07:00
parent 69d18056c4
commit 5d645924da
2 changed files with 58 additions and 0 deletions

31
Makefile Normal file
View File

@ -0,0 +1,31 @@
PREFIX=
all:
@echo "Nothing to do."
test:
@./tests.sh
install:
@prefix="$(PREFIX)"; \
if [ ! "$$prefix" ]; then \
printf '\033[1mWhere do you want to install? (default: /usr/local) \033[0m'; \
read prefix; \
fi; \
[ ! "$$prefix" ] && prefix="/usr/local"; \
mkdir -pv -m 755 "$$prefix/share/man/man1" "$$prefix/bin" \
&& cp -v trash.1 "$$prefix/share/man/man1/" \
&& rm -f "$$prefix/bin/trash" \
&& cp -v trash "$$prefix/bin/"
uninstall:
@prefix="$(PREFIX)"; \
if [ ! "$$prefix" ]; then \
printf '\033[1mWhere do you want to uninstall from? (default: /usr/local) \033[0m'; \
read prefix; \
fi; \
[ ! "$$prefix" ] && prefix="/usr/local"; \
echo "Deleting..."; \
rm -rvf "$$prefix/bin/trash" "$$prefix/share/man/man1/trash.1"
.PHONY: all, test, install, uninstall

27
tests.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh
# Simple test suite
set -e
tmp="tests"
mkdir -p "$tmp"
trap 'rm -rf "$tmp"' EXIT
testdirs="1.testdir 2.testdir 3.testdir 4.testdir"
testfiles="1.testfile 2.testfile 3.testfile"
for d in $testdirs; do
mkdir -p "$tmp/$d"
for f in $testfiles; do touch "$tmp/$d/$f"; done
done
./trash -v "$tmp/1.testdir/1.testfile" "$tmp/1.testdir/2.testfile" "$tmp/2.testdir" "$tmp/3.testdir"
./trash -vfu 1.testfile
./trash -vfu 2.testdir
[ -e "$tmp/1.testdir/1.testfile" ]
! [ -e "$tmp/1.testdir/2.testfile" ]
[ -e "$tmp/1.testdir/3.testfile" ]
[ -e "$tmp/2.testdir" ]
[ -e "$tmp/2.testdir/1.testfile" ]
! [ -e "$tmp/3.testdir" ]
[ -e "$tmp/4.testdir" ]
echo "Tests passed!"