if.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. source $(dirname "$0")/test-commons.inc
  3. setopt --verbose
  4. if test 1 -eq 1 {
  5. # Are comments ok?
  6. # Basic 'if' structure, empty block.
  7. if true {
  8. } else {
  9. fail "if true runs false branch"
  10. }
  11. if false {
  12. fail "if false runs true branch"
  13. } else {
  14. }
  15. # Can we put `else` on a new line?
  16. if false {
  17. echo "if false runs true branch"
  18. exit 2
  19. }
  20. else {
  21. }
  22. # Basic 'if' structure, without 'else'
  23. if false {
  24. fail "'if false' runs the branch"
  25. }
  26. # Extended 'cond' form.
  27. if false {
  28. fail "'if false' with 'else if' runs first branch"
  29. } else if true {
  30. } else {
  31. fail "'if false' with 'else if' runs last branch"
  32. }
  33. # FIXME: Some form of 'not' would be nice
  34. # &&/|| in condition
  35. if true || false {
  36. } else {
  37. fail "'if true || false' runs false branch"
  38. }
  39. if true && false {
  40. fail "'if true && false' runs true branch"
  41. }
  42. } else {
  43. fail "'if test 1 -eq 1' runs false branch"
  44. }
  45. echo PASS