basic.attl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/usr/bin/env attl
  2. #
  3. # Basic test of attl. All prints should produce PASS. Comments should be ignored.
  4. let tc 1
  5. let tn "Test: basic printing and command calling"
  6. print "PASS $tc $tn $tn\n"
  7. inc tc
  8. set tn "Test: string interpolation"
  9. print "${1}${2} $tc $tn\n" "PA" "SS"
  10. inc tc
  11. set tn "Test: variable setting, evaluations, and if"
  12. let a 10
  13. if [ilt $a 20] {
  14. print "PASS $tc $tn\n"
  15. } else {
  16. print "FAIL $tc $tn\n"
  17. }
  18. inc tc
  19. set tn "Test: if with block condition"
  20. let b 12
  21. if {ilt $b 20} {
  22. print "PASS $tc $tn\n"
  23. } else {
  24. print "FAIL $tc $tn\n"
  25. }
  26. inc tc
  27. set tn "Test: else block"
  28. if [ige $a 20] {
  29. print "FAIL $tc $tn\n"
  30. } else {
  31. print "PASS $tc $tn\n"
  32. }
  33. inc tc
  34. set tn "Test: command definition"
  35. to test_ok {
  36. print "PASS $tc $tn\n"
  37. return 0
  38. }
  39. test_ok
  40. inc tc
  41. set tn "Test: break in block"
  42. {
  43. # break should only break the block
  44. break
  45. }
  46. print "PASS $tc $tn\n"
  47. inc tc
  48. set tn "Test: break in block function"
  49. to break_block {
  50. break [expand "PASS $tc $tn"]
  51. print "FAIL $tc $tn went too far \n"
  52. expand "FAIL $tc $tn"
  53. }
  54. print "$1\n" [break_block]
  55. inc tc
  56. set tn "Test: return values"
  57. to return_ok {
  58. return [expand "PASS $tc $tn"]
  59. print "FAIL $tc $tn went too far \n"
  60. }
  61. print "$1\n" [return_ok]
  62. inc tc
  63. set tn "Test: multiple return values"
  64. to return_multi_ok {
  65. return "PA" "AS" [expand "$tc $tn"]
  66. print "FAIL $tc $tn went too far \n"
  67. }
  68. print "$1\n" [return_multi_ok]
  69. set tn "Test: fail/rescue catching"
  70. to fail_ok {
  71. fail "FAIL $tc $tn"
  72. }
  73. inc tc
  74. to test_rescue {
  75. rescue {
  76. let var [expand "PASS $tc $tn\n"]
  77. return "PASS $tc $tn\n"
  78. }
  79. fail_ok
  80. print "FAIL $tc $tn went too far\n"
  81. return 0
  82. }
  83. print [test_rescue]
  84. set tn "Test: top level block evaluation and stack"
  85. inc tc
  86. let var "FAIL $tc $tn"
  87. {
  88. let var "FAIL $tc $tn 2"
  89. {
  90. let var [expand "PASS $tc $tn\n"]
  91. print $var
  92. }
  93. print $var
  94. }
  95. print $var
  96. let rec 0
  97. set tn "Test: no recursion from fail in rescue blocks"
  98. inc tc
  99. to test_fail_in_rescue {
  100. rescue {
  101. inc rec
  102. if [igt $rec 1] {
  103. return "FAIL $tc $tn: recursion detected: $rec\n"
  104. } else {
  105. fail "PASS $tc $tn: $rec\n"
  106. }
  107. }
  108. fail_ok
  109. print "FAIL $tc $tn went too far\n"
  110. return 0
  111. }
  112. print [test_fail_in_rescue]
  113. # This test does stop the recursion but it fails
  114. # in the sense thet the error cannot be caught
  115. # because somehow the rescue block isn't set up
  116. # correctly.
  117. # set rec 0
  118. # set tn "Test: recursion limit"
  119. # inc tc
  120. # rescue {
  121. # print "PASS $tc $tn: limited\n"
  122. # }
  123. # to test_recursion_limit {
  124. # rescue {
  125. # return "PASS $tc $tn: limited\n"
  126. # }
  127. # inc rec
  128. # print "$rec "
  129. # if [igt $rec 38] {
  130. # print "FAIL $tc $tn: not limited\n"
  131. # return 0
  132. # }
  133. # test_recursion_limit
  134. # }
  135. # nop
  136. # print [test_recursion_limit]
  137. # return "PASS $tc $tn: returned\n"