test.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. #!/bin/bash
  3. typeset -i tests=0
  4. function it {
  5. let tests+=1;
  6. description="$1";
  7. }
  8. function assert {
  9. if [[ "$1" == "$2" ]]; then
  10. printf "\033[32m.\033[0m";
  11. else
  12. printf "\033[31m\nFAIL: $description\033[0m: '$1' != '$2'\n";
  13. exit 1
  14. fi
  15. }
  16. it "Should accept a value"
  17. result=`./cli.js "direction"` 2> /dev/null
  18. assert $result "ltr"
  19. it "Should accept a right-to-left value"
  20. result=`./cli.js "لانجليزية"` 2> /dev/null
  21. assert $result "rtl"
  22. it "Should accept a neutral value"
  23. result=`./cli.js "@!"` 2> /dev/null
  24. assert $result "neutral"
  25. it "Should accept multiple values"
  26. result=`./cli.js "direction another"` 2> /dev/null
  27. assert $result "ltr"
  28. it "Should accept multiple arguments"
  29. result=`./cli.js "direction" "another"` 2> /dev/null
  30. assert $result "ltr"
  31. it "Should accept a value over stdin"
  32. result=`echo "direction" | ./cli.js` 2> /dev/null
  33. assert $result "ltr"
  34. it "Should accept multiple values over stdin"
  35. result=`echo "direction another" | ./cli.js` 2> /dev/null
  36. assert $result "ltr"
  37. it "Should accept \`--help\`"
  38. code=0
  39. ./cli.js --help > /dev/null 2>&1 || code=$?
  40. assert $code 0
  41. it "Should accept \`-h\`"
  42. code=0
  43. ./cli.js -h > /dev/null 2>&1 || code=$?
  44. assert $code 0
  45. it "Should accept \`--version\`"
  46. code=0
  47. ./cli.js --version > /dev/null 2>&1 || code=$?
  48. assert $code 0
  49. it "Should accept \`-v\`"
  50. code=0
  51. ./cli.js -v > /dev/null 2>&1 || code=$?
  52. assert $code 0
  53. printf "\033[32m\n(✓) Passed $tests assertions without errors\033[0m\n";
  54. exit 0