Advertisement
Darksider3

Untitled

Feb 3rd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.67 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. colors()
  3. {
  4.   NC="\033[0m"
  5.   RED="\033[0;31m"
  6.   GREEN="\033[0;32m"
  7. }
  8. global_vars() {
  9.   global_title="fancy TIL"
  10.   global_author="darksider3"
  11.  
  12.   create_dirs=0
  13.   create_index=0
  14.   override_index=0
  15.  
  16.   license="LICENSE.md"
  17.   index="README.md"
  18.  
  19.  
  20.   testfile="testfile.txt"
  21.   testdir="test"
  22.   cwd="."
  23. }
  24.  
  25. cleanup() {
  26.   find . -maxdepth 1 -type d -delete
  27. }
  28.  
  29. test_find() {
  30.   colors
  31.   mkdir ${cwd}/${testdir}
  32.   if [ $? -eq 0 ]; then
  33.     echo -e "${GREEN}[OK]${NC} created ${cwd}/${testdir}"
  34.   else
  35.     echo -e "${RED}[FAIL]${NC} Unable to create ${cwd}/${testdir}\n${RED}Aborting${NC}"
  36.     exit 1
  37.   fi
  38.  
  39.   echo "Creating 100 test directorys in ${cwd}/${testdir}/"
  40.   for i in {1..100}
  41.   do
  42.     mkdir test/$i
  43.   done
  44.   touch ${cwd}/${testdir}/${testfile}
  45.   if [ $? -eq 0 ]; then
  46.     echo -e "${GREEN}[OK]${NC} created ${cwd}/${testdir}/${testfile}"
  47.   else
  48.     echo -e "${RED}[FAIL]${NC} Unable to creade ${cwd}/${testdir}/${testfile}"
  49.     echo -e "${RED}Aborting..${NC}"
  50.     exit 1
  51.   fi
  52.   echo "Deleting *only* directorys"
  53.   cd test;find . -maxdepth 1 -type d -delete;cd ..
  54.   echo "Check if only the .txt file survived"
  55.   tested=($( find ./test -maxdepth 1))
  56.   if [ "${tested[1]}" = "${cwd}/${testdir}/${testfile}" ]; then
  57.     echo -e "${GREEN}!![OK]!! \t Yay, anything wen't good. :)${NC}"
  58.   else
  59.     echo "{$RED}[FAIL] Meh, didn't work. Maybe wrong permissions?${NC}"
  60.     echo "${cwd}/${testdir}/${testfile}"
  61.     exit
  62.   fi
  63.  
  64.   echo "Deleting ${testdir}/${testfile}"
  65.   rm -f ${testdir}/${testfile}
  66.   echo "Deleting ${testdir}"
  67.   rm -r ${testdir}
  68.   echo -e "${GREEN}[OK] All tests succeed. Grats! o/ ${NC}"
  69. }
  70. global_vars
  71. test_find
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement