/collects/tests/macro-debugger/tests/syntax-errors.rkt

http://github.com/gmarceau/PLT · Racket · 320 lines · 312 code · 5 blank · 3 comment · 13 complexity · 2703ef52a1d3387c7ef6b349d4f31afe MD5 · raw file

  1. #lang scheme/base
  2. (require "../gentest-framework.rkt")
  3. (provide proto:errors)
  4. (define-tests proto:errors "Bad syntax"
  5. [#:suite
  6. "Atomic expressions"
  7. (testKE (#%top a b c)
  8. #:error-step)
  9. (testKE (#%top . 5)
  10. #:error-step)
  11. (testKE (quote)
  12. #:error-step)
  13. (testKE (quote a b)
  14. #:error-step)
  15. (testKE (#%require . x)
  16. #:error-step)
  17. (testKE (#%require 5)
  18. #:error-step)
  19. (testKE (#%require (prefix mzlib/list))
  20. #:error-step)
  21. (testKE (#%require (prefix 5 mzlib/list))
  22. #:error-step)]
  23. [#:suite
  24. "Definitions"
  25. (testKE (define-values x 'a)
  26. #:error-step)
  27. (testKE (define-values (x))
  28. #:error-step)
  29. (testKE (define-values (x) 'a 'b)
  30. #:error-step)
  31. (testKE (define-values (x) . 1)
  32. #:error-step)
  33. (testKE (define-values (x x) 1)
  34. #:error-step)
  35. (testKE (define-syntaxes x 1)
  36. #:error-step)
  37. (testKE (define-syntaxes (x))
  38. #:error-step)
  39. (testKE (define-syntaxes (x) 1 2)
  40. #:error-step)
  41. (testKE (define-syntaxes (x) . 3)
  42. #:error-step)
  43. (testKE (define-syntaxes (x x) 1)
  44. #:error-step)]
  45. ;; "Simple expressions"
  46. [#:suite
  47. "if misapplied"
  48. (testKE (if)
  49. #:error-step)
  50. (testKE (if 1)
  51. #:error-step)
  52. (testKE (if 'a 'b)
  53. #:error-step)
  54. (testKE (if 1 2 3 4)
  55. #:error-step)
  56. (testKE (if . x)
  57. #:error-step)
  58. (testKE (if 1 . x)
  59. #:error-step)
  60. (testKE (if 1 2 . x)
  61. #:error-step)
  62. (testKE (if 1 2 3 . x)
  63. #:error-step)]
  64. [#:suite
  65. "wcm misapplied"
  66. (testKE (with-continuation-mark)
  67. #:error-step)
  68. (testKE (with-continuation-mark 1)
  69. #:error-step)
  70. (testKE (with-continuation-mark 1 2 3 4)
  71. #:error-step)
  72. (testKE (with-continuation-mark . x)
  73. #:error-step)
  74. (testKE (with-continuation-mark 1 . x)
  75. #:error-step)
  76. (testKE (with-continuation-mark 1 2 . x)
  77. #:error-step)
  78. (testKE (with-continuation-mark 1 2 3 . x)
  79. #:error-step)]
  80. [#:suite
  81. "set! misapplied"
  82. (testKE (set!)
  83. #:error-step)
  84. (testKE (set! x)
  85. #:error-step)
  86. (testKE (set! x . 3)
  87. #:error-step)
  88. (testKE (set! x 1 2)
  89. #:error-step)
  90. (testKE (set! 1)
  91. #:error-step)
  92. (testKE (set! 1 2)
  93. #:error-step)]
  94. ;; "Sequence-containing expressions"
  95. [#:suite
  96. "begin misapplied"
  97. (testKE (#%expression (begin))
  98. #:error-step)
  99. (testKE (begin . 1)
  100. #:error-step)
  101. (testKE (begin 'a . 2)
  102. #:error-step)]
  103. [#:suite
  104. "begin0 misapplied"
  105. (testKE (begin0)
  106. #:error-step)
  107. (testKE (begin0 . 1)
  108. #:error-step)
  109. (testKE (begin0 'a . 2)
  110. #:error-step)
  111. (testKE (begin0 'a 'b . 3)
  112. #:error-step)]
  113. [#:suite
  114. "#%app (implicit) misapplied"
  115. (testKE (+ . 1)
  116. [#:steps (tag-app (#%app + . 1))
  117. error])
  118. (testKE (+ 1 . 2)
  119. [#:steps (tag-app (#%app + 1 . 2))
  120. error])
  121. (testKE (+ 1 2 . 3)
  122. [#:steps (tag-app (#%app + 1 2 . 3))
  123. error])]
  124. [#:suite
  125. "#%app (explicit) misapplied"
  126. (testKE (#%app . +)
  127. #:error-step)
  128. (testKE (#%app + . 1)
  129. #:error-step)
  130. (testKE (#%app + 1 . 2)
  131. #:error-step)
  132. (testKE (#%app + 1 2 . 3)
  133. #:error-step)]
  134. ;; "Binding forms"
  135. [#:suite
  136. "lambda misapplied"
  137. (testKE (lambda)
  138. #:error-step)
  139. (testKE (lambda args)
  140. #:error-step)
  141. (testKE (lambda #(a b) 1)
  142. #:error-step)
  143. (testKE (lambda args . 1)
  144. #:error-step)
  145. (testKE (lambda 1 2)
  146. #:error-step)
  147. (testKE (lambda (1) 2)
  148. #:error-step)
  149. (testKE (lambda (x . 1) 2)
  150. #:error-step)
  151. (testKE (lambda (x x) 1)
  152. #:error-step)
  153. (testKE (lambda (x y x) 1)
  154. #:error-step)]
  155. [#:suite
  156. "letrec-values misapplied"
  157. (testKE (letrec-values)
  158. #:error-step)
  159. (testKE (letrec-values x)
  160. #:error-step)
  161. (testKE (letrec-values x 1)
  162. #:error-step)
  163. (testKE (letrec-values (x) 2)
  164. #:error-step)
  165. (testKE (letrec-values (x 1) 2)
  166. #:error-step)
  167. (testKE (letrec-values ([x 1]) 2)
  168. #:error-step)
  169. (testKE (letrec-values ([(x . y) 1]) 2)
  170. #:error-step)
  171. (testKE (letrec-values ([(x) 1 2]) 2)
  172. #:error-step)
  173. (testKE (letrec-values ([(x) 1] x) 2)
  174. #:error-step)
  175. (testKE (letrec-values ([(x) 1] [y 2]) 3)
  176. #:error-step)
  177. (testKE (letrec-values ([(x x) 1]) 2)
  178. #:error-step)
  179. (testKE (letrec-values ([(x) 1] [(x) 2]) 3)
  180. #:error-step)]
  181. [#:suite
  182. "Internal definitions"
  183. [#:suite
  184. "Basic internal definitions"
  185. (testKE (lambda () . 1) ;; FIXME
  186. #:error-step)
  187. (testKE (lambda () (begin))
  188. [#:steps (rename-lambda (lambda () (begin)))
  189. (splice-block (lambda ()))
  190. error])
  191. (testKE (lambda () (define-values (x) 1))
  192. [#:rename+error-step rename-lambda])
  193. (testKE (lambda () (define-values (x) 1) . 2)
  194. [#:rename+error-step rename-lambda])
  195. (testKE (lambda () (begin (define-values (x) 1) . 2))
  196. [#:rename+error-step rename-lambda])
  197. (testKE (lambda () (begin (define-values (x) 1) . 2) 3)
  198. [#:rename+error-step rename-lambda])
  199. (testKE (lambda ()
  200. (define-values (x) 1)
  201. (define-values (x) 2)
  202. 3)
  203. [#:rename+error-step rename-lambda])]
  204. [#:suite
  205. "#%stratified-body"
  206. (testKE (#%stratified-body
  207. (define-values (x) 'a)
  208. 'b
  209. (define-values (y) 'c)
  210. 'd)
  211. [#:steps (block->letrec (#%stratified-body
  212. (letrec-values ([(x) 'a])
  213. (#%stratified-body
  214. 'b
  215. (define-values (y) 'c)
  216. 'd))))
  217. (rename-letrec-values (#%stratified-body
  218. (letrec-values ([(x) 'a])
  219. (#%stratified-body
  220. 'b
  221. (define-values (y) 'c)
  222. 'd))))
  223. error])
  224. (testKE (#%stratified-body (define-values (x) 'a))
  225. [#:steps error])]
  226. [#:suite
  227. "bad internal begin"
  228. (testKE (lambda () (begin . 1))
  229. [#:rename+error-step rename-lambda])
  230. (testKE (lambda () (begin 1 . 2))
  231. [#:rename+error-step rename-lambda])
  232. (testKE (lambda () (define-values (x) 1) (begin . 2))
  233. [#:rename+error-step rename-lambda])
  234. (testKE (lambda () (define-values (x) 1) (begin 1 . 2))
  235. [#:rename+error-step rename-lambda])
  236. (testKE (lambda () (define-values (x) 1) (begin . 2) 3)
  237. [#:rename+error-step rename-lambda])]
  238. [#:suite
  239. "bad definition forms"
  240. (testKE (lambda () (define-values))
  241. [#:rename+error-step rename-lambda])
  242. (testKE (lambda () (define-values x))
  243. [#:rename+error-step rename-lambda])
  244. (testKE (lambda () (define-values x 1))
  245. [#:rename+error-step rename-lambda])
  246. (testKE (lambda () (define-values (x . y) 1))
  247. [#:rename+error-step rename-lambda])
  248. (testKE (lambda () (define-values (x) . 1))
  249. [#:rename+error-step rename-lambda])
  250. (testKE (lambda () (define-values (x) 1 2))
  251. [#:rename+error-step rename-lambda])
  252. (testKE (lambda () (define-values (x x) 1))
  253. [#:rename+error-step rename-lambda])]]
  254. [#:suite
  255. "Errors in primitive contexts"
  256. [#:suite
  257. "Definitions"
  258. (testKE (define-syntaxes (x) (lambda))
  259. #:error-step)
  260. (testKE (define-values (x) (wrong))
  261. #:error-step)]
  262. [#:suite
  263. "Simple expressions"
  264. (testKE (if (wrong) 'b 'c)
  265. #:error-step)
  266. (testKE (if 'a (wrong) 'c)
  267. #:error-step)
  268. (testKE (if 'a 'b (wrong))
  269. #:error-step)
  270. (testKE (if (wrong) 'b)
  271. #:error-step)
  272. (testKE (if 'a (wrong))
  273. #:error-step)
  274. (testKE (with-continuation-mark (wrong) 'b 'c)
  275. #:error-step)
  276. (testKE (with-continuation-mark 'a (wrong) 'c)
  277. #:error-step)
  278. (testKE (with-continuation-mark 'a 'b (wrong))
  279. #:error-step)
  280. (testKE (set! x (wrong))
  281. #:error-step)]
  282. [#:suite
  283. "Sequence-containing expressions"
  284. (testKE (begin (wrong))
  285. #:error-step)
  286. (testKE (begin 'a (wrong))
  287. #:error-step)
  288. (testKE (begin0 (wrong))
  289. #:error-step)
  290. (testKE (begin0 'a (wrong))
  291. #:error-step)
  292. (testKE (#%app (wrong))
  293. #:error-step)
  294. (testKE (#%app + (wrong))
  295. #:error-step)]
  296. [#:suite
  297. "Binding forms"
  298. (testKE (lambda (x) (begin0 (wrong)))
  299. [#:rename+error-step rename-lambda])
  300. (testKE (letrec-values ([(x) (wrong)]) 1)
  301. [#:rename+error-step rename-letrec-values])
  302. (testKE (letrec-values ([(x) 'a]) (begin0 (wrong)))
  303. [#:rename+error-step rename-letrec-values])]
  304. [#:suite
  305. "Internal definitions"
  306. (testKE (lambda () (wrong))
  307. [#:rename+error-step rename-lambda])
  308. (testKE (lambda () (define-values () (wrong)) 1)
  309. [#:steps
  310. (rename-lambda (lambda () (define-values () (wrong)) 1))
  311. (block->letrec (lambda () (letrec-values ([() (wrong)]) 1)))
  312. (rename-letrec-values (lambda () (letrec-values ([() (wrong)]) 1)))
  313. error])
  314. (testKE (lambda () (define-values (x) 1) (wrong))
  315. [#:rename+error-step rename-lambda])]])