tree-il.test 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  1. ;;;; tree-il.test --- test suite for compiling tree-il -*- scheme -*-
  2. ;;;; Andy Wingo <wingo@pobox.com> --- May 2009
  3. ;;;;
  4. ;;;; Copyright (C) 2009-2014 Free Software Foundation, Inc.
  5. ;;;;
  6. ;;;; This library is free software; you can redistribute it and/or
  7. ;;;; modify it under the terms of the GNU Lesser General Public
  8. ;;;; License as published by the Free Software Foundation; either
  9. ;;;; version 3 of the License, or (at your option) any later version.
  10. ;;;;
  11. ;;;; This library is distributed in the hope that it will be useful,
  12. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ;;;; Lesser General Public License for more details.
  15. ;;;;
  16. ;;;; You should have received a copy of the GNU Lesser General Public
  17. ;;;; License along with this library; if not, write to the Free Software
  18. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. (define-module (test-suite tree-il)
  20. #:use-module (test-suite lib)
  21. #:use-module (system base compile)
  22. #:use-module (system base pmatch)
  23. #:use-module (system base message)
  24. #:use-module (language tree-il)
  25. #:use-module (language tree-il primitives)
  26. #:use-module (srfi srfi-13))
  27. (define-syntax-rule (pass-if-primitives-resolved in expected)
  28. (pass-if (format #f "primitives-resolved in ~s" 'in)
  29. (let* ((module (let ((m (make-module)))
  30. (beautify-user-module! m)
  31. m))
  32. (orig (parse-tree-il 'in))
  33. (resolved (expand-primitives (resolve-primitives orig module))))
  34. (or (equal? (unparse-tree-il resolved) 'expected)
  35. (begin
  36. (format (current-error-port)
  37. "primitive test failed: got ~s, expected ~s"
  38. resolved 'expected)
  39. #f)))))
  40. (define-syntax pass-if-tree-il->scheme
  41. (syntax-rules ()
  42. ((_ in pat)
  43. (assert-scheme->tree-il->scheme in pat #t))
  44. ((_ in pat guard-exp)
  45. (pass-if 'in
  46. (pmatch (tree-il->scheme
  47. (compile 'in #:from 'scheme #:to 'tree-il))
  48. (pat (guard guard-exp) #t)
  49. (_ #f))))))
  50. (with-test-prefix "primitives"
  51. (with-test-prefix "eqv?"
  52. (pass-if-primitives-resolved
  53. (primcall eqv? (toplevel x) (const #f))
  54. (primcall eq? (const #f) (toplevel x)))
  55. (pass-if-primitives-resolved
  56. (primcall eqv? (toplevel x) (const ()))
  57. (primcall eq? (const ()) (toplevel x)))
  58. (pass-if-primitives-resolved
  59. (primcall eqv? (const #t) (lexical x y))
  60. (primcall eq? (const #t) (lexical x y)))
  61. (pass-if-primitives-resolved
  62. (primcall eqv? (const this-is-a-symbol) (toplevel x))
  63. (primcall eq? (const this-is-a-symbol) (toplevel x)))
  64. (pass-if-primitives-resolved
  65. (primcall eqv? (const 42) (toplevel x))
  66. (primcall eq? (const 42) (toplevel x)))
  67. (pass-if-primitives-resolved
  68. (primcall eqv? (const 42.0) (toplevel x))
  69. (primcall eqv? (const 42.0) (toplevel x)))
  70. (pass-if-primitives-resolved
  71. (primcall eqv? (const #nil) (toplevel x))
  72. (primcall eq? (const #nil) (toplevel x))))
  73. (with-test-prefix "equal?"
  74. (pass-if-primitives-resolved
  75. (primcall equal? (toplevel x) (const #f))
  76. (primcall eq? (const #f) (toplevel x)))
  77. (pass-if-primitives-resolved
  78. (primcall equal? (toplevel x) (const ()))
  79. (primcall eq? (const ()) (toplevel x)))
  80. (pass-if-primitives-resolved
  81. (primcall equal? (const #t) (lexical x y))
  82. (primcall eq? (const #t) (lexical x y)))
  83. (pass-if-primitives-resolved
  84. (primcall equal? (const this-is-a-symbol) (toplevel x))
  85. (primcall eq? (const this-is-a-symbol) (toplevel x)))
  86. (pass-if-primitives-resolved
  87. (primcall equal? (const 42) (toplevel x))
  88. (primcall eq? (const 42) (toplevel x)))
  89. (pass-if-primitives-resolved
  90. (primcall equal? (const 42.0) (toplevel x))
  91. (primcall equal? (const 42.0) (toplevel x)))
  92. (pass-if-primitives-resolved
  93. (primcall equal? (const #nil) (toplevel x))
  94. (primcall eq? (const #nil) (toplevel x)))))
  95. (with-test-prefix "tree-il->scheme"
  96. (pass-if-tree-il->scheme
  97. (case-lambda ((a) a) ((b c) (list b c)))
  98. (case-lambda ((,a) ,a1) ((,b ,c) (list ,b1 ,c1)))
  99. (and (eq? a a1) (eq? b b1) (eq? c c1))))
  100. (with-test-prefix "contification"
  101. (pass-if "http://debbugs.gnu.org/9769"
  102. ((compile '(lambda ()
  103. (let ((fail (lambda () #f)))
  104. (let ((test (lambda () (fail))))
  105. (test))
  106. #t))
  107. ;; Prevent inlining. We're testing contificatoin here,
  108. ;; and inlining it will reduce the entire thing to #t.
  109. #:opts '(#:partial-eval? #f)))))
  110. (define (sum . args)
  111. (apply + args))
  112. (with-test-prefix "many args"
  113. (pass-if "call with > 256 args"
  114. (equal? (compile `(1+ (sum ,@(iota 1000)))
  115. #:env (current-module))
  116. (1+ (apply sum (iota 1000)))))
  117. (pass-if "tail call with > 256 args"
  118. (equal? (compile `(sum ,@(iota 1000))
  119. #:env (current-module))
  120. (apply sum (iota 1000)))))
  121. (with-test-prefix "tree-il-fold"
  122. (pass-if "void"
  123. (let ((up 0) (down 0) (mark (list 'mark)))
  124. (and (eq? mark
  125. (tree-il-fold (lambda (x y) (set! down (1+ down)) y)
  126. (lambda (x y) (set! up (1+ up)) y)
  127. mark
  128. (make-void #f)))
  129. (= up 1)
  130. (= down 1))))
  131. (pass-if "lambda and application"
  132. (let* ((ups '()) (downs '())
  133. (result (tree-il-fold (lambda (x y)
  134. (set! downs (cons x downs))
  135. (1+ y))
  136. (lambda (x y)
  137. (set! ups (cons x ups))
  138. (1+ y))
  139. 0
  140. (parse-tree-il
  141. '(lambda ()
  142. (lambda-case
  143. (((x y) #f #f #f () (x1 y1))
  144. (call (toplevel +)
  145. (lexical x x1)
  146. (lexical y y1)))
  147. #f))))))
  148. (define (strip-source x)
  149. (post-order (lambda (x)
  150. (set! (tree-il-src x) #f)
  151. x)
  152. x))
  153. (and (= result 12)
  154. (equal? (map strip-source (list-head (reverse ups) 3))
  155. (list (make-toplevel-ref #f '+)
  156. (make-lexical-ref #f 'x 'x1)
  157. (make-lexical-ref #f 'y 'y1)))
  158. (equal? (map strip-source (reverse (list-head downs 3)))
  159. (list (make-toplevel-ref #f '+)
  160. (make-lexical-ref #f 'x 'x1)
  161. (make-lexical-ref #f 'y 'y1)))))))
  162. ;;;
  163. ;;; Warnings.
  164. ;;;
  165. ;; Make sure we get English messages.
  166. (when (defined? 'setlocale)
  167. (setlocale LC_ALL "C"))
  168. (define (call-with-warnings thunk)
  169. (let ((port (open-output-string)))
  170. (with-fluids ((*current-warning-port* port)
  171. (*current-warning-prefix* ""))
  172. (thunk))
  173. (let ((warnings (get-output-string port)))
  174. (string-tokenize warnings
  175. (char-set-complement (char-set #\newline))))))
  176. (define %opts-w-unused
  177. '(#:warnings (unused-variable)))
  178. (define %opts-w-unused-toplevel
  179. '(#:warnings (unused-toplevel)))
  180. (define %opts-w-unbound
  181. '(#:warnings (unbound-variable)))
  182. (define %opts-w-arity
  183. '(#:warnings (arity-mismatch)))
  184. (define %opts-w-format
  185. '(#:warnings (format)))
  186. (define %opts-w-duplicate-case-datum
  187. '(#:warnings (duplicate-case-datum)))
  188. (define %opts-w-bad-case-datum
  189. '(#:warnings (bad-case-datum)))
  190. (with-test-prefix "warnings"
  191. (pass-if "unknown warning type"
  192. (let ((w (call-with-warnings
  193. (lambda ()
  194. (compile #t #:opts '(#:warnings (does-not-exist)))))))
  195. (and (= (length w) 1)
  196. (number? (string-contains (car w) "unknown warning")))))
  197. (with-test-prefix "unused-variable"
  198. (pass-if "quiet"
  199. (null? (call-with-warnings
  200. (lambda ()
  201. (compile '(lambda (x y) (+ x y))
  202. #:opts %opts-w-unused)))))
  203. (pass-if "let/unused"
  204. (let ((w (call-with-warnings
  205. (lambda ()
  206. (compile '(lambda (x)
  207. (let ((y (+ x 2)))
  208. x))
  209. #:opts %opts-w-unused)))))
  210. (and (= (length w) 1)
  211. (number? (string-contains (car w) "unused variable `y'")))))
  212. (pass-if "shadowed variable"
  213. (let ((w (call-with-warnings
  214. (lambda ()
  215. (compile '(lambda (x)
  216. (let ((y x))
  217. (let ((y (+ x 2)))
  218. (+ x y))))
  219. #:opts %opts-w-unused)))))
  220. (and (= (length w) 1)
  221. (number? (string-contains (car w) "unused variable `y'")))))
  222. (pass-if "letrec"
  223. (null? (call-with-warnings
  224. (lambda ()
  225. (compile '(lambda ()
  226. (letrec ((x (lambda () (y)))
  227. (y (lambda () (x))))
  228. y))
  229. #:opts %opts-w-unused)))))
  230. (pass-if "unused argument"
  231. ;; Unused arguments should not be reported.
  232. (null? (call-with-warnings
  233. (lambda ()
  234. (compile '(lambda (x y z) #t)
  235. #:opts %opts-w-unused)))))
  236. (pass-if "special variable names"
  237. (null? (call-with-warnings
  238. (lambda ()
  239. (compile '(lambda ()
  240. (let ((_ 'underscore)
  241. (#{gensym name}# 'ignore-me))
  242. #t))
  243. #:to 'cps
  244. #:opts %opts-w-unused))))))
  245. (with-test-prefix "unused-toplevel"
  246. (pass-if "used after definition"
  247. (null? (call-with-warnings
  248. (lambda ()
  249. (let ((in (open-input-string
  250. "(define foo 2) foo")))
  251. (read-and-compile in
  252. #:to 'cps
  253. #:opts %opts-w-unused-toplevel))))))
  254. (pass-if "used before definition"
  255. (null? (call-with-warnings
  256. (lambda ()
  257. (let ((in (open-input-string
  258. "(define (bar) foo) (define foo 2) (bar)")))
  259. (read-and-compile in
  260. #:to 'cps
  261. #:opts %opts-w-unused-toplevel))))))
  262. (pass-if "unused but public"
  263. (let ((in (open-input-string
  264. "(define-module (test-suite tree-il x) #:export (bar))
  265. (define (bar) #t)")))
  266. (null? (call-with-warnings
  267. (lambda ()
  268. (read-and-compile in
  269. #:to 'cps
  270. #:opts %opts-w-unused-toplevel))))))
  271. (pass-if "unused but public (more)"
  272. (let ((in (open-input-string
  273. "(define-module (test-suite tree-il x) #:export (bar))
  274. (define (bar) (baz))
  275. (define (baz) (foo))
  276. (define (foo) #t)")))
  277. (null? (call-with-warnings
  278. (lambda ()
  279. (read-and-compile in
  280. #:to 'cps
  281. #:opts %opts-w-unused-toplevel))))))
  282. (pass-if "unused but define-public"
  283. (null? (call-with-warnings
  284. (lambda ()
  285. (compile '(define-public foo 2)
  286. #:to 'cps
  287. #:opts %opts-w-unused-toplevel)))))
  288. (pass-if "used by macro"
  289. ;; FIXME: See comment about macros at `unused-toplevel-analysis'.
  290. (throw 'unresolved)
  291. (null? (call-with-warnings
  292. (lambda ()
  293. (let ((in (open-input-string
  294. "(define (bar) 'foo)
  295. (define-syntax baz
  296. (syntax-rules () ((_) (bar))))")))
  297. (read-and-compile in
  298. #:to 'cps
  299. #:opts %opts-w-unused-toplevel))))))
  300. (pass-if "unused"
  301. (let ((w (call-with-warnings
  302. (lambda ()
  303. (compile '(define foo 2)
  304. #:to 'cps
  305. #:opts %opts-w-unused-toplevel)))))
  306. (and (= (length w) 1)
  307. (number? (string-contains (car w)
  308. (format #f "top-level variable `~A'"
  309. 'foo))))))
  310. (pass-if "unused recursive"
  311. (let ((w (call-with-warnings
  312. (lambda ()
  313. (compile '(define (foo) (foo))
  314. #:to 'cps
  315. #:opts %opts-w-unused-toplevel)))))
  316. (and (= (length w) 1)
  317. (number? (string-contains (car w)
  318. (format #f "top-level variable `~A'"
  319. 'foo))))))
  320. (pass-if "unused mutually recursive"
  321. (let* ((in (open-input-string
  322. "(define (foo) (bar)) (define (bar) (foo))"))
  323. (w (call-with-warnings
  324. (lambda ()
  325. (read-and-compile in
  326. #:to 'cps
  327. #:opts %opts-w-unused-toplevel)))))
  328. (and (= (length w) 2)
  329. (number? (string-contains (car w)
  330. (format #f "top-level variable `~A'"
  331. 'foo)))
  332. (number? (string-contains (cadr w)
  333. (format #f "top-level variable `~A'"
  334. 'bar))))))
  335. (pass-if "special variable names"
  336. (null? (call-with-warnings
  337. (lambda ()
  338. (compile '(define #{gensym name}# 'ignore-me)
  339. #:to 'cps
  340. #:opts %opts-w-unused-toplevel))))))
  341. (with-test-prefix "unbound variable"
  342. (pass-if "quiet"
  343. (null? (call-with-warnings
  344. (lambda ()
  345. (compile '+ #:opts %opts-w-unbound)))))
  346. (pass-if "ref"
  347. (let* ((v (gensym))
  348. (w (call-with-warnings
  349. (lambda ()
  350. (compile v
  351. #:to 'cps
  352. #:opts %opts-w-unbound)))))
  353. (and (= (length w) 1)
  354. (number? (string-contains (car w)
  355. (format #f "unbound variable `~A'"
  356. v))))))
  357. (pass-if "set!"
  358. (let* ((v (gensym))
  359. (w (call-with-warnings
  360. (lambda ()
  361. (compile `(set! ,v 7)
  362. #:to 'cps
  363. #:opts %opts-w-unbound)))))
  364. (and (= (length w) 1)
  365. (number? (string-contains (car w)
  366. (format #f "unbound variable `~A'"
  367. v))))))
  368. (pass-if "module-local top-level is visible"
  369. (let ((m (make-module))
  370. (v (gensym)))
  371. (beautify-user-module! m)
  372. (compile `(define ,v 123)
  373. #:env m #:opts %opts-w-unbound)
  374. (null? (call-with-warnings
  375. (lambda ()
  376. (compile v
  377. #:env m
  378. #:to 'cps
  379. #:opts %opts-w-unbound))))))
  380. (pass-if "module-local top-level is visible after"
  381. (let ((m (make-module))
  382. (v (gensym)))
  383. (beautify-user-module! m)
  384. (null? (call-with-warnings
  385. (lambda ()
  386. (let ((in (open-input-string
  387. "(define (f)
  388. (set! chbouib 3))
  389. (define chbouib 5)")))
  390. (read-and-compile in
  391. #:env m
  392. #:opts %opts-w-unbound)))))))
  393. (pass-if "optional arguments are visible"
  394. (null? (call-with-warnings
  395. (lambda ()
  396. (compile '(lambda* (x #:optional y z) (list x y z))
  397. #:opts %opts-w-unbound
  398. #:to 'cps)))))
  399. (pass-if "keyword arguments are visible"
  400. (null? (call-with-warnings
  401. (lambda ()
  402. (compile '(lambda* (x #:key y z) (list x y z))
  403. #:opts %opts-w-unbound
  404. #:to 'cps)))))
  405. (pass-if "GOOPS definitions are visible"
  406. (let ((m (make-module))
  407. (v (gensym)))
  408. (beautify-user-module! m)
  409. (module-use! m (resolve-interface '(oop goops)))
  410. (null? (call-with-warnings
  411. (lambda ()
  412. (let ((in (open-input-string
  413. "(define-class <foo> ()
  414. (bar #:getter foo-bar))
  415. (define z (foo-bar (make <foo>)))")))
  416. (read-and-compile in
  417. #:env m
  418. #:opts %opts-w-unbound))))))))
  419. (with-test-prefix "arity mismatch"
  420. (pass-if "quiet"
  421. (null? (call-with-warnings
  422. (lambda ()
  423. (compile '(cons 'a 'b) #:opts %opts-w-arity)))))
  424. (pass-if "direct application"
  425. (let ((w (call-with-warnings
  426. (lambda ()
  427. (compile '((lambda (x y) (or x y)) 1 2 3 4 5)
  428. #:opts %opts-w-arity
  429. #:to 'cps)))))
  430. (and (= (length w) 1)
  431. (number? (string-contains (car w)
  432. "wrong number of arguments to")))))
  433. (pass-if "local"
  434. (let ((w (call-with-warnings
  435. (lambda ()
  436. (compile '(let ((f (lambda (x y) (+ x y))))
  437. (f 2))
  438. #:opts %opts-w-arity
  439. #:to 'cps)))))
  440. (and (= (length w) 1)
  441. (number? (string-contains (car w)
  442. "wrong number of arguments to")))))
  443. (pass-if "global"
  444. (let ((w (call-with-warnings
  445. (lambda ()
  446. (compile '(cons 1 2 3 4)
  447. #:opts %opts-w-arity
  448. #:to 'cps)))))
  449. (and (= (length w) 1)
  450. (number? (string-contains (car w)
  451. "wrong number of arguments to")))))
  452. (pass-if "alias to global"
  453. (let ((w (call-with-warnings
  454. (lambda ()
  455. (compile '(let ((f cons)) (f 1 2 3 4))
  456. #:opts %opts-w-arity
  457. #:to 'cps)))))
  458. (and (= (length w) 1)
  459. (number? (string-contains (car w)
  460. "wrong number of arguments to")))))
  461. (pass-if "alias to lexical to global"
  462. (let ((w (call-with-warnings
  463. (lambda ()
  464. (compile '(let ((f number?))
  465. (let ((g f))
  466. (f 1 2 3 4)))
  467. #:opts %opts-w-arity
  468. #:to 'cps)))))
  469. (and (= (length w) 1)
  470. (number? (string-contains (car w)
  471. "wrong number of arguments to")))))
  472. (pass-if "alias to lexical"
  473. (let ((w (call-with-warnings
  474. (lambda ()
  475. (compile '(let ((f (lambda (x y z) (+ x y z))))
  476. (let ((g f))
  477. (g 1)))
  478. #:opts %opts-w-arity
  479. #:to 'cps)))))
  480. (and (= (length w) 1)
  481. (number? (string-contains (car w)
  482. "wrong number of arguments to")))))
  483. (pass-if "letrec"
  484. (let ((w (call-with-warnings
  485. (lambda ()
  486. (compile '(letrec ((odd? (lambda (x) (even? (1- x))))
  487. (even? (lambda (x)
  488. (or (= 0 x)
  489. (odd?)))))
  490. (odd? 1))
  491. #:opts %opts-w-arity
  492. #:to 'cps)))))
  493. (and (= (length w) 1)
  494. (number? (string-contains (car w)
  495. "wrong number of arguments to")))))
  496. (pass-if "case-lambda"
  497. (null? (call-with-warnings
  498. (lambda ()
  499. (compile '(let ((f (case-lambda
  500. ((x) 1)
  501. ((x y) 2)
  502. ((x y z) 3))))
  503. (list (f 1)
  504. (f 1 2)
  505. (f 1 2 3)))
  506. #:opts %opts-w-arity
  507. #:to 'cps)))))
  508. (pass-if "case-lambda with wrong number of arguments"
  509. (let ((w (call-with-warnings
  510. (lambda ()
  511. (compile '(let ((f (case-lambda
  512. ((x) 1)
  513. ((x y) 2))))
  514. (f 1 2 3))
  515. #:opts %opts-w-arity
  516. #:to 'cps)))))
  517. (and (= (length w) 1)
  518. (number? (string-contains (car w)
  519. "wrong number of arguments to")))))
  520. (pass-if "case-lambda*"
  521. (null? (call-with-warnings
  522. (lambda ()
  523. (compile '(let ((f (case-lambda*
  524. ((x #:optional y) 1)
  525. ((x #:key y) 2)
  526. ((x y #:key z) 3))))
  527. (list (f 1)
  528. (f 1 2)
  529. (f #:y 2)
  530. (f 1 2 #:z 3)))
  531. #:opts %opts-w-arity
  532. #:to 'cps)))))
  533. (pass-if "case-lambda* with wrong arguments"
  534. (let ((w (call-with-warnings
  535. (lambda ()
  536. (compile '(let ((f (case-lambda*
  537. ((x #:optional y) 1)
  538. ((x #:key y) 2)
  539. ((x y #:key z) 3))))
  540. (list (f)
  541. (f 1 #:z 3)))
  542. #:opts %opts-w-arity
  543. #:to 'cps)))))
  544. (and (= (length w) 2)
  545. (null? (filter (lambda (w)
  546. (not
  547. (number?
  548. (string-contains
  549. w "wrong number of arguments to"))))
  550. w)))))
  551. (pass-if "top-level applicable struct"
  552. (null? (call-with-warnings
  553. (lambda ()
  554. (compile '(let ((p current-warning-port))
  555. (p (+ (p) 1))
  556. (p))
  557. #:opts %opts-w-arity
  558. #:to 'cps)))))
  559. (pass-if "top-level applicable struct with wrong arguments"
  560. (let ((w (call-with-warnings
  561. (lambda ()
  562. (compile '(let ((p current-warning-port))
  563. (p 1 2 3))
  564. #:opts %opts-w-arity
  565. #:to 'cps)))))
  566. (and (= (length w) 1)
  567. (number? (string-contains (car w)
  568. "wrong number of arguments to")))))
  569. (pass-if "local toplevel-defines"
  570. (let ((w (call-with-warnings
  571. (lambda ()
  572. (let ((in (open-input-string "
  573. (define (g x) (f x))
  574. (define (f) 1)")))
  575. (read-and-compile in
  576. #:opts %opts-w-arity
  577. #:to 'cps))))))
  578. (and (= (length w) 1)
  579. (number? (string-contains (car w)
  580. "wrong number of arguments to")))))
  581. (pass-if "global toplevel alias"
  582. (let ((w (call-with-warnings
  583. (lambda ()
  584. (let ((in (open-input-string "
  585. (define f cons)
  586. (define (g) (f))")))
  587. (read-and-compile in
  588. #:opts %opts-w-arity
  589. #:to 'cps))))))
  590. (and (= (length w) 1)
  591. (number? (string-contains (car w)
  592. "wrong number of arguments to")))))
  593. (pass-if "local toplevel overrides global"
  594. (null? (call-with-warnings
  595. (lambda ()
  596. (let ((in (open-input-string "
  597. (define (cons) 0)
  598. (define (foo x) (cons))")))
  599. (read-and-compile in
  600. #:opts %opts-w-arity
  601. #:to 'cps))))))
  602. (pass-if "keyword not passed and quiet"
  603. (null? (call-with-warnings
  604. (lambda ()
  605. (compile '(let ((f (lambda* (x #:key y) y)))
  606. (f 2))
  607. #:opts %opts-w-arity
  608. #:to 'cps)))))
  609. (pass-if "keyword passed and quiet"
  610. (null? (call-with-warnings
  611. (lambda ()
  612. (compile '(let ((f (lambda* (x #:key y) y)))
  613. (f 2 #:y 3))
  614. #:opts %opts-w-arity
  615. #:to 'cps)))))
  616. (pass-if "keyword passed to global and quiet"
  617. (null? (call-with-warnings
  618. (lambda ()
  619. (let ((in (open-input-string "
  620. (use-modules (system base compile))
  621. (compile '(+ 2 3) #:env (current-module))")))
  622. (read-and-compile in
  623. #:opts %opts-w-arity
  624. #:to 'cps))))))
  625. (pass-if "extra keyword"
  626. (let ((w (call-with-warnings
  627. (lambda ()
  628. (compile '(let ((f (lambda* (x #:key y) y)))
  629. (f 2 #:Z 3))
  630. #:opts %opts-w-arity
  631. #:to 'cps)))))
  632. (and (= (length w) 1)
  633. (number? (string-contains (car w)
  634. "wrong number of arguments to")))))
  635. (pass-if "extra keywords allowed"
  636. (null? (call-with-warnings
  637. (lambda ()
  638. (compile '(let ((f (lambda* (x #:key y #:allow-other-keys)
  639. y)))
  640. (f 2 #:Z 3))
  641. #:opts %opts-w-arity
  642. #:to 'cps))))))
  643. (with-test-prefix "format"
  644. (pass-if "quiet (no args)"
  645. (null? (call-with-warnings
  646. (lambda ()
  647. (compile '(format #t "hey!")
  648. #:opts %opts-w-format
  649. #:to 'cps)))))
  650. (pass-if "quiet (1 arg)"
  651. (null? (call-with-warnings
  652. (lambda ()
  653. (compile '(format #t "hey ~A!" "you")
  654. #:opts %opts-w-format
  655. #:to 'cps)))))
  656. (pass-if "quiet (2 args)"
  657. (null? (call-with-warnings
  658. (lambda ()
  659. (compile '(format #t "~A ~A!" "hello" "world")
  660. #:opts %opts-w-format
  661. #:to 'cps)))))
  662. (pass-if "wrong port arg"
  663. (let ((w (call-with-warnings
  664. (lambda ()
  665. (compile '(format 10 "foo")
  666. #:opts %opts-w-format
  667. #:to 'cps)))))
  668. (and (= (length w) 1)
  669. (number? (string-contains (car w)
  670. "wrong port argument")))))
  671. (pass-if "non-literal format string"
  672. (let ((w (call-with-warnings
  673. (lambda ()
  674. (compile '(format #f fmt)
  675. #:opts %opts-w-format
  676. #:to 'cps)))))
  677. (and (= (length w) 1)
  678. (number? (string-contains (car w)
  679. "non-literal format string")))))
  680. (pass-if "non-literal format string using gettext"
  681. (null? (call-with-warnings
  682. (lambda ()
  683. (compile '(format #t (gettext "~A ~A!") "hello" "world")
  684. #:opts %opts-w-format
  685. #:to 'cps)))))
  686. (pass-if "non-literal format string using gettext as _"
  687. (null? (call-with-warnings
  688. (lambda ()
  689. (compile '(format #t (_ "~A ~A!") "hello" "world")
  690. #:opts %opts-w-format
  691. #:to 'cps)))))
  692. (pass-if "non-literal format string using gettext as top-level _"
  693. (null? (call-with-warnings
  694. (lambda ()
  695. (compile '(begin
  696. (define (_ s) (gettext s "my-domain"))
  697. (format #t (_ "~A ~A!") "hello" "world"))
  698. #:opts %opts-w-format
  699. #:to 'cps)))))
  700. (pass-if "non-literal format string using gettext as module-ref _"
  701. (null? (call-with-warnings
  702. (lambda ()
  703. (compile '(format #t ((@@ (foo) _) "~A ~A!") "hello" "world")
  704. #:opts %opts-w-format
  705. #:to 'cps)))))
  706. (pass-if "non-literal format string using gettext as lexical _"
  707. (null? (call-with-warnings
  708. (lambda ()
  709. (compile '(let ((_ (lambda (s)
  710. (gettext s "my-domain"))))
  711. (format #t (_ "~A ~A!") "hello" "world"))
  712. #:opts %opts-w-format
  713. #:to 'cps)))))
  714. (pass-if "non-literal format string using ngettext"
  715. (null? (call-with-warnings
  716. (lambda ()
  717. (compile '(format #t
  718. (ngettext "~a thing" "~a things" n "dom") n)
  719. #:opts %opts-w-format
  720. #:to 'cps)))))
  721. (pass-if "non-literal format string using ngettext as N_"
  722. (null? (call-with-warnings
  723. (lambda ()
  724. (compile '(format #t (N_ "~a thing" "~a things" n) n)
  725. #:opts %opts-w-format
  726. #:to 'cps)))))
  727. (pass-if "non-literal format string with (define _ gettext)"
  728. (null? (call-with-warnings
  729. (lambda ()
  730. (compile '(begin
  731. (define _ gettext)
  732. (define (foo)
  733. (format #t (_ "~A ~A!") "hello" "world")))
  734. #:opts %opts-w-format
  735. #:to 'cps)))))
  736. (pass-if "wrong format string"
  737. (let ((w (call-with-warnings
  738. (lambda ()
  739. (compile '(format #f 'not-a-string)
  740. #:opts %opts-w-format
  741. #:to 'cps)))))
  742. (and (= (length w) 1)
  743. (number? (string-contains (car w)
  744. "wrong format string")))))
  745. (pass-if "wrong number of args"
  746. (let ((w (call-with-warnings
  747. (lambda ()
  748. (compile '(format "shbweeb")
  749. #:opts %opts-w-format
  750. #:to 'cps)))))
  751. (and (= (length w) 1)
  752. (number? (string-contains (car w)
  753. "wrong number of arguments")))))
  754. (pass-if "~%, ~~, ~&, ~t, ~_, ~!, ~|, ~/, ~q and ~\\n"
  755. (null? (call-with-warnings
  756. (lambda ()
  757. (compile '((@ (ice-9 format) format) some-port
  758. "~&~3_~~ ~\n~12they~% ~!~|~/~q")
  759. #:opts %opts-w-format
  760. #:to 'cps)))))
  761. (pass-if "one missing argument"
  762. (let ((w (call-with-warnings
  763. (lambda ()
  764. (compile '(format some-port "foo ~A~%")
  765. #:opts %opts-w-format
  766. #:to 'cps)))))
  767. (and (= (length w) 1)
  768. (number? (string-contains (car w)
  769. "expected 1, got 0")))))
  770. (pass-if "one missing argument, gettext"
  771. (let ((w (call-with-warnings
  772. (lambda ()
  773. (compile '(format some-port (gettext "foo ~A~%"))
  774. #:opts %opts-w-format
  775. #:to 'cps)))))
  776. (and (= (length w) 1)
  777. (number? (string-contains (car w)
  778. "expected 1, got 0")))))
  779. (pass-if "two missing arguments"
  780. (let ((w (call-with-warnings
  781. (lambda ()
  782. (compile '((@ (ice-9 format) format) #f
  783. "foo ~10,2f and bar ~S~%")
  784. #:opts %opts-w-format
  785. #:to 'cps)))))
  786. (and (= (length w) 1)
  787. (number? (string-contains (car w)
  788. "expected 2, got 0")))))
  789. (pass-if "one given, one missing argument"
  790. (let ((w (call-with-warnings
  791. (lambda ()
  792. (compile '(format #t "foo ~A and ~S~%" hey)
  793. #:opts %opts-w-format
  794. #:to 'cps)))))
  795. (and (= (length w) 1)
  796. (number? (string-contains (car w)
  797. "expected 2, got 1")))))
  798. (pass-if "too many arguments"
  799. (let ((w (call-with-warnings
  800. (lambda ()
  801. (compile '(format #t "foo ~A~%" 1 2)
  802. #:opts %opts-w-format
  803. #:to 'cps)))))
  804. (and (= (length w) 1)
  805. (number? (string-contains (car w)
  806. "expected 1, got 2")))))
  807. (pass-if "~h"
  808. (null? (call-with-warnings
  809. (lambda ()
  810. (compile '((@ (ice-9 format) format) #t
  811. "foo ~h ~a~%" 123.4 'bar)
  812. #:opts %opts-w-format
  813. #:to 'cps)))))
  814. (pass-if "~:h with locale object"
  815. (null? (call-with-warnings
  816. (lambda ()
  817. (compile '((@ (ice-9 format) format) #t
  818. "foo ~:h~%" 123.4 %global-locale)
  819. #:opts %opts-w-format
  820. #:to 'cps)))))
  821. (pass-if "~:h without locale object"
  822. (let ((w (call-with-warnings
  823. (lambda ()
  824. (compile '((@ (ice-9 format) format) #t "foo ~,2:h" 123.4)
  825. #:opts %opts-w-format
  826. #:to 'cps)))))
  827. (and (= (length w) 1)
  828. (number? (string-contains (car w)
  829. "expected 2, got 1")))))
  830. (with-test-prefix "conditionals"
  831. (pass-if "literals"
  832. (null? (call-with-warnings
  833. (lambda ()
  834. (compile '((@ (ice-9 format) format) #f "~A ~[foo~;bar~;baz~;~] ~10,2f"
  835. 'a 1 3.14)
  836. #:opts %opts-w-format
  837. #:to 'cps)))))
  838. (pass-if "literals with selector"
  839. (let ((w (call-with-warnings
  840. (lambda ()
  841. (compile '((@ (ice-9 format) format) #f "~2[foo~;bar~;baz~;~] ~A"
  842. 1 'dont-ignore-me)
  843. #:opts %opts-w-format
  844. #:to 'cps)))))
  845. (and (= (length w) 1)
  846. (number? (string-contains (car w)
  847. "expected 1, got 2")))))
  848. (pass-if "escapes (exact count)"
  849. (let ((w (call-with-warnings
  850. (lambda ()
  851. (compile '((@ (ice-9 format) format) #f "~[~a~;~a~]")
  852. #:opts %opts-w-format
  853. #:to 'cps)))))
  854. (and (= (length w) 1)
  855. (number? (string-contains (car w)
  856. "expected 2, got 0")))))
  857. (pass-if "escapes with selector"
  858. (let ((w (call-with-warnings
  859. (lambda ()
  860. (compile '((@ (ice-9 format) format) #f "~1[chbouib~;~a~]")
  861. #:opts %opts-w-format
  862. #:to 'cps)))))
  863. (and (= (length w) 1)
  864. (number? (string-contains (car w)
  865. "expected 1, got 0")))))
  866. (pass-if "escapes, range"
  867. (let ((w (call-with-warnings
  868. (lambda ()
  869. (compile '((@ (ice-9 format) format) #f "~[chbouib~;~a~;~2*~a~]")
  870. #:opts %opts-w-format
  871. #:to 'cps)))))
  872. (and (= (length w) 1)
  873. (number? (string-contains (car w)
  874. "expected 1 to 4, got 0")))))
  875. (pass-if "@"
  876. (let ((w (call-with-warnings
  877. (lambda ()
  878. (compile '((@ (ice-9 format) format) #f "~@[temperature=~d~]")
  879. #:opts %opts-w-format
  880. #:to 'cps)))))
  881. (and (= (length w) 1)
  882. (number? (string-contains (car w)
  883. "expected 1, got 0")))))
  884. (pass-if "nested"
  885. (let ((w (call-with-warnings
  886. (lambda ()
  887. (compile '((@ (ice-9 format) format) #f "~:[~[hey~;~a~;~va~]~;~3*~]")
  888. #:opts %opts-w-format
  889. #:to 'cps)))))
  890. (and (= (length w) 1)
  891. (number? (string-contains (car w)
  892. "expected 2 to 4, got 0")))))
  893. (pass-if "unterminated"
  894. (let ((w (call-with-warnings
  895. (lambda ()
  896. (compile '((@ (ice-9 format) format) #f "~[unterminated")
  897. #:opts %opts-w-format
  898. #:to 'cps)))))
  899. (and (= (length w) 1)
  900. (number? (string-contains (car w)
  901. "unterminated conditional")))))
  902. (pass-if "unexpected ~;"
  903. (let ((w (call-with-warnings
  904. (lambda ()
  905. (compile '((@ (ice-9 format) format) #f "foo~;bar")
  906. #:opts %opts-w-format
  907. #:to 'cps)))))
  908. (and (= (length w) 1)
  909. (number? (string-contains (car w)
  910. "unexpected")))))
  911. (pass-if "unexpected ~]"
  912. (let ((w (call-with-warnings
  913. (lambda ()
  914. (compile '((@ (ice-9 format) format) #f "foo~]")
  915. #:opts %opts-w-format
  916. #:to 'cps)))))
  917. (and (= (length w) 1)
  918. (number? (string-contains (car w)
  919. "unexpected"))))))
  920. (pass-if "~{...~}"
  921. (null? (call-with-warnings
  922. (lambda ()
  923. (compile '((@ (ice-9 format) format) #f "~A ~{~S~} ~A"
  924. 'hello '("ladies" "and")
  925. 'gentlemen)
  926. #:opts %opts-w-format
  927. #:to 'cps)))))
  928. (pass-if "~{...~}, too many args"
  929. (let ((w (call-with-warnings
  930. (lambda ()
  931. (compile '((@ (ice-9 format) format) #f "~{~S~}" 1 2 3)
  932. #:opts %opts-w-format
  933. #:to 'cps)))))
  934. (and (= (length w) 1)
  935. (number? (string-contains (car w)
  936. "expected 1, got 3")))))
  937. (pass-if "~@{...~}"
  938. (null? (call-with-warnings
  939. (lambda ()
  940. (compile '((@ (ice-9 format) format) #f "~@{~S~}" 1 2 3)
  941. #:opts %opts-w-format
  942. #:to 'cps)))))
  943. (pass-if "~@{...~}, too few args"
  944. (let ((w (call-with-warnings
  945. (lambda ()
  946. (compile '((@ (ice-9 format) format) #f "~A ~@{~S~}")
  947. #:opts %opts-w-format
  948. #:to 'cps)))))
  949. (and (= (length w) 1)
  950. (number? (string-contains (car w)
  951. "expected at least 1, got 0")))))
  952. (pass-if "unterminated ~{...~}"
  953. (let ((w (call-with-warnings
  954. (lambda ()
  955. (compile '((@ (ice-9 format) format) #f "~{")
  956. #:opts %opts-w-format
  957. #:to 'cps)))))
  958. (and (= (length w) 1)
  959. (number? (string-contains (car w)
  960. "unterminated")))))
  961. (pass-if "~(...~)"
  962. (null? (call-with-warnings
  963. (lambda ()
  964. (compile '((@ (ice-9 format) format) #f "~:@(~A ~A~)" 'foo 'bar)
  965. #:opts %opts-w-format
  966. #:to 'cps)))))
  967. (pass-if "~v"
  968. (let ((w (call-with-warnings
  969. (lambda ()
  970. (compile '((@ (ice-9 format) format) #f "~v_foo")
  971. #:opts %opts-w-format
  972. #:to 'cps)))))
  973. (and (= (length w) 1)
  974. (number? (string-contains (car w)
  975. "expected 1, got 0")))))
  976. (pass-if "~v:@y"
  977. (null? (call-with-warnings
  978. (lambda ()
  979. (compile '((@ (ice-9 format) format) #f "~v:@y" 1 123)
  980. #:opts %opts-w-format
  981. #:to 'cps)))))
  982. (pass-if "~*"
  983. (let ((w (call-with-warnings
  984. (lambda ()
  985. (compile '((@ (ice-9 format) format) #f "~2*~a" 'a 'b)
  986. #:opts %opts-w-format
  987. #:to 'cps)))))
  988. (and (= (length w) 1)
  989. (number? (string-contains (car w)
  990. "expected 3, got 2")))))
  991. (pass-if "~p"
  992. (null? (call-with-warnings
  993. (lambda ()
  994. (compile '(((@ (ice-9 format) format) #f "thing~p" 2))
  995. #:opts %opts-w-format
  996. #:to 'cps)))))
  997. (pass-if "~p, too few arguments"
  998. (let ((w (call-with-warnings
  999. (lambda ()
  1000. (compile '((@ (ice-9 format) format) #f "~p")
  1001. #:opts %opts-w-format
  1002. #:to 'cps)))))
  1003. (and (= (length w) 1)
  1004. (number? (string-contains (car w)
  1005. "expected 1, got 0")))))
  1006. (pass-if "~:p"
  1007. (null? (call-with-warnings
  1008. (lambda ()
  1009. (compile '(((@ (ice-9 format) format) #f "~d thing~:p" 2))
  1010. #:opts %opts-w-format
  1011. #:to 'cps)))))
  1012. (pass-if "~:@p, too many arguments"
  1013. (let ((w (call-with-warnings
  1014. (lambda ()
  1015. (compile '((@ (ice-9 format) format) #f "~d pupp~:@p" 5 5)
  1016. #:opts %opts-w-format
  1017. #:to 'cps)))))
  1018. (and (= (length w) 1)
  1019. (number? (string-contains (car w)
  1020. "expected 1, got 2")))))
  1021. (pass-if "~:@p, too few arguments"
  1022. (let ((w (call-with-warnings
  1023. (lambda ()
  1024. (compile '((@ (ice-9 format) format) #f "pupp~:@p")
  1025. #:opts %opts-w-format
  1026. #:to 'cps)))))
  1027. (and (= (length w) 1)
  1028. (number? (string-contains (car w)
  1029. "expected 1, got 0")))))
  1030. (pass-if "~?"
  1031. (null? (call-with-warnings
  1032. (lambda ()
  1033. (compile '((@ (ice-9 format) format) #f "~?" "~d ~d" '(1 2))
  1034. #:opts %opts-w-format
  1035. #:to 'cps)))))
  1036. (pass-if "~^"
  1037. (null? (call-with-warnings
  1038. (lambda ()
  1039. (compile '((@ (ice-9 format) format) #f "~a ~^ ~a" 0 1)
  1040. #:opts %opts-w-format
  1041. #:to 'cps)))))
  1042. (pass-if "~^, too few args"
  1043. (let ((w (call-with-warnings
  1044. (lambda ()
  1045. (compile '((@ (ice-9 format) format) #f "~a ~^ ~a")
  1046. #:opts %opts-w-format
  1047. #:to 'cps)))))
  1048. (and (= (length w) 1)
  1049. (number? (string-contains (car w)
  1050. "expected at least 1, got 0")))))
  1051. (pass-if "parameters: +,-,#, and '"
  1052. (null? (call-with-warnings
  1053. (lambda ()
  1054. (compile '((@ (ice-9 format) format) some-port
  1055. "~#~ ~,,-2f ~,,+2f ~'A~" 1234 1234)
  1056. #:opts %opts-w-format
  1057. #:to 'cps)))))
  1058. (pass-if "complex 1"
  1059. (let ((w (call-with-warnings
  1060. (lambda ()
  1061. (compile '((@ (ice-9 format) format) #f
  1062. "~4@S ~32S~@[;; ~1{~@?~}~]~@[~61t at ~a~]\n"
  1063. 1 2 3 4 5 6)
  1064. #:opts %opts-w-format
  1065. #:to 'cps)))))
  1066. (and (= (length w) 1)
  1067. (number? (string-contains (car w)
  1068. "expected 4, got 6")))))
  1069. (pass-if "complex 2"
  1070. (let ((w (call-with-warnings
  1071. (lambda ()
  1072. (compile '((@ (ice-9 format) format) #f
  1073. "~:(~A~) Commands~:[~; [abbrev]~]:~2%"
  1074. 1 2 3 4)
  1075. #:opts %opts-w-format
  1076. #:to 'cps)))))
  1077. (and (= (length w) 1)
  1078. (number? (string-contains (car w)
  1079. "expected 2, got 4")))))
  1080. (pass-if "complex 3"
  1081. (let ((w (call-with-warnings
  1082. (lambda ()
  1083. (compile '((@ (ice-9 format) format) #f "~9@a~:[~*~3_~;~3d~] ~v:@y~%")
  1084. #:opts %opts-w-format
  1085. #:to 'cps)))))
  1086. (and (= (length w) 1)
  1087. (number? (string-contains (car w)
  1088. "expected 5, got 0")))))
  1089. (pass-if "ice-9 format"
  1090. (let ((w (call-with-warnings
  1091. (lambda ()
  1092. (let ((in (open-input-string
  1093. "(use-modules ((ice-9 format) #:prefix i9-))
  1094. (i9-format #t \"yo! ~A\" 1 2)")))
  1095. (read-and-compile in
  1096. #:opts %opts-w-format
  1097. #:to 'cps))))))
  1098. (and (= (length w) 1)
  1099. (number? (string-contains (car w)
  1100. "expected 1, got 2")))))
  1101. (pass-if "not format"
  1102. (null? (call-with-warnings
  1103. (lambda ()
  1104. (compile '(let ((format chbouib))
  1105. (format #t "not ~A a format string"))
  1106. #:opts %opts-w-format
  1107. #:to 'cps)))))
  1108. (with-test-prefix "simple-format"
  1109. (pass-if "good"
  1110. (null? (call-with-warnings
  1111. (lambda ()
  1112. (compile '(simple-format #t "foo ~a bar ~s ~%~~" 1 2)
  1113. #:opts %opts-w-format
  1114. #:to 'cps)))))
  1115. (pass-if "wrong number of args"
  1116. (let ((w (call-with-warnings
  1117. (lambda ()
  1118. (compile '(simple-format #t "foo ~a ~s~%" 'one-missing)
  1119. #:opts %opts-w-format
  1120. #:to 'cps)))))
  1121. (and (= (length w) 1)
  1122. (number? (string-contains (car w) "wrong number")))))
  1123. (pass-if "unsupported"
  1124. (let ((w (call-with-warnings
  1125. (lambda ()
  1126. (compile '(simple-format #t "foo ~x~%" 16)
  1127. #:opts %opts-w-format
  1128. #:to 'cps)))))
  1129. (and (= (length w) 1)
  1130. (number? (string-contains (car w) "unsupported format option")))))
  1131. (pass-if "unsupported, gettext"
  1132. (let ((w (call-with-warnings
  1133. (lambda ()
  1134. (compile '(simple-format #t (gettext "foo ~2f~%") 3.14)
  1135. #:opts %opts-w-format
  1136. #:to 'cps)))))
  1137. (and (= (length w) 1)
  1138. (number? (string-contains (car w) "unsupported format option")))))
  1139. (pass-if "unsupported, ngettext"
  1140. (let ((w (call-with-warnings
  1141. (lambda ()
  1142. (compile '(simple-format #t (ngettext "s ~x" "p ~x" x) x)
  1143. #:opts %opts-w-format
  1144. #:to 'cps)))))
  1145. (and (= (length w) 1)
  1146. (number? (string-contains (car w) "unsupported format option")))))))
  1147. (with-test-prefix "duplicate-case-datum"
  1148. (pass-if "quiet"
  1149. (null? (call-with-warnings
  1150. (lambda ()
  1151. (compile '(case x ((1) 'one) ((2) 'two))
  1152. #:opts %opts-w-duplicate-case-datum
  1153. #:to 'cps)))))
  1154. (pass-if "one duplicate"
  1155. (let ((w (call-with-warnings
  1156. (lambda ()
  1157. (compile '(case x
  1158. ((1) 'one)
  1159. ((2) 'two)
  1160. ((1) 'one-again))
  1161. #:opts %opts-w-duplicate-case-datum
  1162. #:to 'cps)))))
  1163. (and (= (length w) 1)
  1164. (number? (string-contains (car w) "duplicate")))))
  1165. (pass-if "one duplicate"
  1166. (let ((w (call-with-warnings
  1167. (lambda ()
  1168. (compile '(case x
  1169. ((1 2 3) 'a)
  1170. ((1) 'one))
  1171. #:opts %opts-w-duplicate-case-datum
  1172. #:to 'cps)))))
  1173. (and (= (length w) 1)
  1174. (number? (string-contains (car w) "duplicate"))))))
  1175. (with-test-prefix "bad-case-datum"
  1176. (pass-if "quiet"
  1177. (null? (call-with-warnings
  1178. (lambda ()
  1179. (compile '(case x ((1) 'one) ((2) 'two))
  1180. #:opts %opts-w-bad-case-datum
  1181. #:to 'cps)))))
  1182. (pass-if "not eqv?"
  1183. (let ((w (call-with-warnings
  1184. (lambda ()
  1185. (compile '(case x
  1186. ((1) 'one)
  1187. (("bad") 'bad))
  1188. #:opts %opts-w-bad-case-datum
  1189. #:to 'cps)))))
  1190. (and (= (length w) 1)
  1191. (number? (string-contains (car w)
  1192. "cannot be meaningfully compared")))))
  1193. (pass-if "one clause element not eqv?"
  1194. (let ((w (call-with-warnings
  1195. (lambda ()
  1196. (compile '(case x
  1197. ((1 (2) 3) 'a))
  1198. #:opts %opts-w-duplicate-case-datum
  1199. #:to 'cps)))))
  1200. (and (= (length w) 1)
  1201. (number? (string-contains (car w)
  1202. "cannot be meaningfully compared")))))))
  1203. ;; Local Variables:
  1204. ;; eval: (put 'pass-if-primitives-resolved 'scheme-indent-function 1)
  1205. ;; eval: (put 'pass-if-tree-il->scheme 'scheme-indent-function 1)
  1206. ;; End: