test.sh (1592B)
1 #!/usr/bin/env sh 2 3 # no color 4 if [ -z "$NOCOLOR" ]; then 5 RED='\033[0;31m' 6 GREEN='\033[0;32m' 7 NC='\033[0m' 8 else 9 RED="" 10 GREEN="" 11 NC="" 12 fi 13 14 test () { 15 OUTPUT=$(eval "$2" 2>&1) 16 EXPECT="$3" 17 if [ "$OUTPUT" = "$EXPECT" ]; then 18 printf "TEST: %-20.20s ${GREEN}PASSED${NC}\n" "$1" 19 else 20 printf "TEST: %-20.20s ${RED}FAILED${NC}\n" "$1" 21 echo "EXPECTED:" 22 echo "$EXPECT" 23 echo "GOT:" 24 echo "$OUTPUT" 25 fi 26 } 27 28 tmp_file () { 29 eval "FILE$1=$(mktemp /tmp/tagger-test-file-XXXXXX)" 30 eval "BASENAME$1=$(basename $FILE$1)" 31 } 32 33 tmp_dir () { 34 FOLDER=$(mktemp -d /tmp/tagger-test-XXXXXX) 35 LS_FOLDER="&& cd $FOLDER && find ." 36 } 37 38 tmp_dir 39 40 test "init" "./tagger $FOLDER init $LS_FOLDER" \ 41 ". 42 ./.base" 43 44 test "init: already exist" "./tagger $FOLDER init" \ 45 "folder is already contain tagger: $FOLDER" 46 47 tmp_file 48 test "add file" "./tagger $FOLDER add $FILE $LS_FOLDER" \ 49 ". 50 ./.base 51 ./.base/$BASENAME" 52 rm -f "$FILE" 53 54 test "tag file" "./tagger $FOLDER tag $BASENAME a $LS_FOLDER" \ 55 ". 56 ./.base 57 ./.base/$BASENAME 58 ./a 59 ./a/$BASENAME" 60 61 test "untag file" "./tagger $FOLDER untag $BASENAME a $LS_FOLDER" \ 62 ". 63 ./.base 64 ./.base/$BASENAME 65 ./a" 66 67 test "ls files" "./tagger $FOLDER ls" "$BASENAME" 68 69 test "path file" "./tagger $FOLDER path $BASENAME" "$FOLDER/.base/$BASENAME" 70 71 test "remove file" "./tagger $FOLDER rm $BASENAME $LS_FOLDER" \ 72 ". 73 ./.base 74 ./a" 75 76 tmp_file 77 ./tagger "$FOLDER" add "$FILE" 78 ./tagger "$FOLDER" tag "$BASENAME" test 79 80 test "remove tagged file" "./tagger $FOLDER rm $BASENAME $LS_FOLDER" \ 81 ". 82 ./.base 83 ./a 84 ./test" 85 86 # clean up 87 rm -rf "$FOLDER"