Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- colors()
- {
- NC="\033[0m"
- RED="\033[0;31m"
- GREEN="\033[0;32m"
- }
- global_vars() {
- global_title="fancy TIL"
- global_author="darksider3"
- create_dirs=0
- create_index=0
- override_index=0
- license="LICENSE.md"
- index="README.md"
- testfile="testfile.txt"
- testdir="test"
- cwd="."
- }
- cleanup() {
- find . -maxdepth 1 -type d -delete
- }
- test_find() {
- colors
- mkdir ${cwd}/${testdir}
- if [ $? -eq 0 ]; then
- echo -e "${GREEN}[OK]${NC} created ${cwd}/${testdir}"
- else
- echo -e "${RED}[FAIL]${NC} Unable to create ${cwd}/${testdir}\n${RED}Aborting${NC}"
- exit 1
- fi
- echo "Creating 100 test directorys in ${cwd}/${testdir}/"
- for i in {1..100}
- do
- mkdir test/$i
- done
- touch ${cwd}/${testdir}/${testfile}
- if [ $? -eq 0 ]; then
- echo -e "${GREEN}[OK]${NC} created ${cwd}/${testdir}/${testfile}"
- else
- echo -e "${RED}[FAIL]${NC} Unable to creade ${cwd}/${testdir}/${testfile}"
- echo -e "${RED}Aborting..${NC}"
- exit 1
- fi
- echo "Deleting *only* directorys"
- cd test;find . -maxdepth 1 -type d -delete;cd ..
- echo "Check if only the .txt file survived"
- tested=($( find ./test -maxdepth 1))
- if [ "${tested[1]}" = "${cwd}/${testdir}/${testfile}" ]; then
- echo -e "${GREEN}!![OK]!! \t Yay, anything wen't good. :)${NC}"
- else
- echo "{$RED}[FAIL] Meh, didn't work. Maybe wrong permissions?${NC}"
- echo "${cwd}/${testdir}/${testfile}"
- exit
- fi
- echo "Deleting ${testdir}/${testfile}"
- rm -f ${testdir}/${testfile}
- echo "Deleting ${testdir}"
- rm -r ${testdir}
- echo -e "${GREEN}[OK] All tests succeed. Grats! o/ ${NC}"
- }
- global_vars
- test_find
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement