srfi-64-test.scm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. ;;;
  2. ;;; This is a test suite written in the notation of
  3. ;;; SRFI-64, A Scheme API for test suites
  4. ;;;
  5. (test-begin "SRFI 64 - Meta-Test Suite")
  6. ;;;
  7. ;;; Ironically, in order to set up the meta-test environment,
  8. ;;; we have to invoke one of the most sophisticated features:
  9. ;;; custom test runners
  10. ;;;
  11. ;;; The `prop-runner' invokes `thunk' in the context of a new
  12. ;;; test runner, and returns the indicated properties of the
  13. ;;; last-executed test result.
  14. (define (prop-runner props thunk)
  15. (let ((r (test-runner-null))
  16. (plist '()))
  17. ;;
  18. (test-runner-on-test-end!
  19. r
  20. (lambda (runner)
  21. (set! plist (test-result-alist runner))))
  22. ;;
  23. (test-with-runner r (thunk))
  24. ;; reorder the properties so they are in the order
  25. ;; given by `props'. Note that any property listed in `props'
  26. ;; that is not in the property alist will occur as #f
  27. (map (lambda (k)
  28. (assq k plist))
  29. props)))
  30. ;;; `on-test-runner' creates a null test runner and then
  31. ;;; arranged for `visit' to be called with the runner
  32. ;;; whenever a test is run. The results of the calls to
  33. ;;; `visit' are returned in a list
  34. (define (on-test-runner thunk visit)
  35. (let ((r (test-runner-null))
  36. (results '()))
  37. ;;
  38. (test-runner-on-test-end!
  39. r
  40. (lambda (runner)
  41. (set! results (cons (visit r) results))))
  42. ;;
  43. (test-with-runner r (thunk))
  44. (reverse results)))
  45. ;;;
  46. ;;; The `triv-runner' invokes `thunk'
  47. ;;; and returns a list of 6 lists, the first 5 of which
  48. ;;; are a list of the names of the tests that, respectively,
  49. ;;; PASS, FAIL, XFAIL, XPASS, and SKIP.
  50. ;;; The last item is a list of counts.
  51. ;;;
  52. (define (triv-runner thunk)
  53. (let ((r (test-runner-null))
  54. (accum-pass '())
  55. (accum-fail '())
  56. (accum-xfail '())
  57. (accum-xpass '())
  58. (accum-skip '()))
  59. ;;
  60. (test-runner-on-bad-count!
  61. r
  62. (lambda (runner count expected-count)
  63. (error (string-append "bad count " (number->string count)
  64. " but expected "
  65. (number->string expected-count)))))
  66. (test-runner-on-bad-end-name!
  67. r
  68. (lambda (runner begin end)
  69. (error (string-append "bad end group name " end
  70. " but expected " begin))))
  71. (test-runner-on-test-end!
  72. r
  73. (lambda (runner)
  74. (let ((n (test-runner-test-name runner)))
  75. (case (test-result-kind runner)
  76. ((pass) (set! accum-pass (cons n accum-pass)))
  77. ((fail) (set! accum-fail (cons n accum-fail)))
  78. ((xpass) (set! accum-xpass (cons n accum-xpass)))
  79. ((xfail) (set! accum-xfail (cons n accum-xfail)))
  80. ((skip) (set! accum-skip (cons n accum-skip)))))))
  81. ;;
  82. (test-with-runner r (thunk))
  83. (list (reverse accum-pass) ; passed as expected
  84. (reverse accum-fail) ; failed, but was expected to pass
  85. (reverse accum-xfail) ; failed as expected
  86. (reverse accum-xpass) ; passed, but was expected to fail
  87. (reverse accum-skip) ; was not executed
  88. (list (test-runner-pass-count r)
  89. (test-runner-fail-count r)
  90. (test-runner-xfail-count r)
  91. (test-runner-xpass-count r)
  92. (test-runner-skip-count r)))))
  93. (define (path-revealing-runner thunk)
  94. (let ((r (test-runner-null))
  95. (seq '()))
  96. ;;
  97. (test-runner-on-test-end!
  98. r
  99. (lambda (runner)
  100. (set! seq (cons (list (test-runner-group-path runner)
  101. (test-runner-test-name runner))
  102. seq))))
  103. (test-with-runner r (thunk))
  104. (reverse seq)))
  105. ;;;
  106. ;;; Now we can start testing compliance with SRFI-64
  107. ;;;
  108. (test-begin "1. Simple test-cases")
  109. (test-begin "1.1. test-assert")
  110. (define (t)
  111. (triv-runner
  112. (lambda ()
  113. (test-assert "a" #t)
  114. (test-assert "b" #f))))
  115. (test-equal
  116. "1.1.1. Very simple"
  117. '(("a") ("b") () () () (1 1 0 0 0))
  118. (t))
  119. (test-equal
  120. "1.1.2. A test with no name"
  121. '(("a") ("") () () () (1 1 0 0 0))
  122. (triv-runner (lambda () (test-assert "a" #t) (test-assert #f))))
  123. (test-equal
  124. "1.1.3. Tests can have the same name"
  125. '(("a" "a") () () () () (2 0 0 0 0))
  126. (triv-runner (lambda () (test-assert "a" #t) (test-assert "a" #t))))
  127. (define (choke)
  128. (vector-ref '#(1 2) 3))
  129. (test-equal
  130. "1.1.4. One way to FAIL is to throw an error"
  131. '(() ("a") () () () (0 1 0 0 0))
  132. (triv-runner (lambda () (test-assert "a" (choke)))))
  133. (test-end);1.1
  134. (test-begin "1.2. test-eqv")
  135. (define (mean x y)
  136. (/ (+ x y) 2.0))
  137. (test-equal
  138. "1.2.1. Simple numerical equivalence"
  139. '(("c") ("a" "b") () () () (1 2 0 0 0))
  140. (triv-runner
  141. (lambda ()
  142. (test-eqv "a" (mean 3 5) 4)
  143. (test-eqv "b" (mean 3 5) 4.5)
  144. (test-eqv "c" (mean 3 5) 4.0))))
  145. (test-end);1.2
  146. (test-end "1. Simple test-cases")
  147. ;;;
  148. ;;;
  149. ;;;
  150. (test-begin "2. Tests for catching errors")
  151. (test-begin "2.1. test-error")
  152. (test-equal
  153. "2.1.1. Baseline test; PASS with no optional args"
  154. '(("") () () () () (1 0 0 0 0))
  155. (triv-runner
  156. (lambda ()
  157. ;; PASS
  158. (test-error (vector-ref '#(1 2) 9)))))
  159. (test-equal
  160. "2.1.2. Baseline test; FAIL with no optional args"
  161. '(() ("") () () () (0 1 0 0 0))
  162. (triv-runner
  163. (lambda ()
  164. ;; FAIL: the expr does not raise an error and `test-error' is
  165. ;; claiming that it will, so this test should FAIL
  166. (test-error (vector-ref '#(1 2) 0)))))
  167. (test-equal
  168. "2.1.3. PASS with a test name and error type"
  169. '(("a") () () () () (1 0 0 0 0))
  170. (triv-runner
  171. (lambda ()
  172. ;; PASS
  173. (test-error "a" #t (vector-ref '#(1 2) 9)))))
  174. (test-end "2.1. test-error")
  175. (test-end "2. Tests for catching errors")
  176. ;;;
  177. ;;;
  178. ;;;
  179. (test-begin "3. Test groups and paths")
  180. (test-equal
  181. "3.1. test-begin with unspecific test-end"
  182. '(("b") () () () () (1 0 0 0 0))
  183. (triv-runner
  184. (lambda ()
  185. (test-begin "a")
  186. (test-assert "b" #t)
  187. (test-end))))
  188. (test-equal
  189. "3.2. test-begin with name-matching test-end"
  190. '(("b") () () () () (1 0 0 0 0))
  191. (triv-runner
  192. (lambda ()
  193. (test-begin "a")
  194. (test-assert "b" #t)
  195. (test-end "a"))))
  196. ;;; since the error raised by `test-end' on a mismatch is not a test
  197. ;;; error, we actually expect the triv-runner itself to fail
  198. (test-error
  199. "3.3. test-begin with mismatched test-end"
  200. #t
  201. (triv-runner
  202. (lambda ()
  203. (test-begin "a")
  204. (test-assert "b" #t)
  205. (test-end "x"))))
  206. (test-equal
  207. "3.4. test-begin with name and count"
  208. '(("b" "c") () () () () (2 0 0 0 0))
  209. (triv-runner
  210. (lambda ()
  211. (test-begin "a" 2)
  212. (test-assert "b" #t)
  213. (test-assert "c" #t)
  214. (test-end "a"))))
  215. ;; similarly here, a mismatched count is a lexical error
  216. ;; and not a test failure...
  217. (test-error
  218. "3.5. test-begin with mismatched count"
  219. #t
  220. (triv-runner
  221. (lambda ()
  222. (test-begin "a" 99)
  223. (test-assert "b" #t)
  224. (test-end "a"))))
  225. (test-equal
  226. "3.6. introspecting on the group path"
  227. '((() "w")
  228. (("a" "b") "x")
  229. (("a" "b") "y")
  230. (("a") "z"))
  231. ;;
  232. ;; `path-revealing-runner' is designed to return a list
  233. ;; of the tests executed, in order. Each entry is a list
  234. ;; (GROUP-PATH TEST-NAME), and each GROUP-PATH is a list
  235. ;; of test groups starting from the topmost
  236. ;;
  237. (path-revealing-runner
  238. (lambda ()
  239. (test-assert "w" #t)
  240. (test-begin "a")
  241. (test-begin "b")
  242. (test-assert "x" #t)
  243. (test-assert "y" #t)
  244. (test-end)
  245. (test-assert "z" #t))))
  246. (test-end "3. Test groups and paths")
  247. ;;;
  248. ;;;
  249. ;;;
  250. (test-begin "4. Handling set-up and cleanup")
  251. (test-equal "4.1. Normal exit path"
  252. '(in 1 2 out)
  253. (let ((ex '()))
  254. (define (do s)
  255. (set! ex (cons s ex)))
  256. ;;
  257. (triv-runner
  258. (lambda ()
  259. (test-group-with-cleanup
  260. "foo"
  261. (do 'in)
  262. (do 1)
  263. (do 2)
  264. (do 'out))))
  265. (reverse ex)))
  266. (test-equal "4.2. Exception exit path"
  267. '(in 1 out)
  268. (let ((ex '()))
  269. (define (do s)
  270. (set! ex (cons s ex)))
  271. ;;
  272. ;; the outer runner is to run the `test-error' in, to
  273. ;; catch the exception raised in the inner runner,
  274. ;; since we don't want to depend on any other
  275. ;; exception-catching support
  276. ;;
  277. (triv-runner
  278. (lambda ()
  279. (test-error
  280. (triv-runner
  281. (lambda ()
  282. (test-group-with-cleanup
  283. "foo"
  284. (do 'in) (test-assert #t)
  285. (do 1) (test-assert #t)
  286. (choke) (test-assert #t)
  287. (do 2) (test-assert #t)
  288. (do 'out)))))))
  289. (reverse ex)))
  290. (test-end "4. Handling set-up and cleanup")
  291. ;;;
  292. ;;;
  293. ;;;
  294. (test-begin "5. Test specifiers")
  295. (test-begin "5.1. test-match-named")
  296. (test-equal "5.1.1. match test names"
  297. '(("y") () () () ("x") (1 0 0 0 1))
  298. (triv-runner
  299. (lambda ()
  300. (test-skip (test-match-name "x"))
  301. (test-assert "x" #t)
  302. (test-assert "y" #t))))
  303. (test-equal "5.1.2. but not group names"
  304. '(("z") () () () () (1 0 0 0 0))
  305. (triv-runner
  306. (lambda ()
  307. (test-skip (test-match-name "x"))
  308. (test-begin "x")
  309. (test-assert "z" #t)
  310. (test-end))))
  311. (test-end)
  312. (test-begin "5.2. test-match-nth")
  313. ;; See also: [6.4. Short-circuit evaluation]
  314. (test-equal "5.2.1. skip the nth one after"
  315. '(("v" "w" "y" "z") () () () ("x") (4 0 0 0 1))
  316. (triv-runner
  317. (lambda ()
  318. (test-assert "v" #t)
  319. (test-skip (test-match-nth 2))
  320. (test-assert "w" #t) ; 1
  321. (test-assert "x" #t) ; 2 SKIP
  322. (test-assert "y" #t) ; 3
  323. (test-assert "z" #t)))) ; 4
  324. (test-equal "5.2.2. skip m, starting at n"
  325. '(("v" "w" "z") () () () ("x" "y") (3 0 0 0 2))
  326. (triv-runner
  327. (lambda ()
  328. (test-assert "v" #t)
  329. (test-skip (test-match-nth 2 2))
  330. (test-assert "w" #t) ; 1
  331. (test-assert "x" #t) ; 2 SKIP
  332. (test-assert "y" #t) ; 3 SKIP
  333. (test-assert "z" #t)))) ; 4
  334. (test-end)
  335. (test-begin "5.3. test-match-any")
  336. (test-equal "5.3.1. basic disjunction"
  337. '(("v" "w" "z") () () () ("x" "y") (3 0 0 0 2))
  338. (triv-runner
  339. (lambda ()
  340. (test-assert "v" #t)
  341. (test-skip (test-match-any (test-match-nth 3)
  342. (test-match-name "x")))
  343. (test-assert "w" #t) ; 1
  344. (test-assert "x" #t) ; 2 SKIP(NAME)
  345. (test-assert "y" #t) ; 3 SKIP(COUNT)
  346. (test-assert "z" #t)))) ; 4
  347. (test-equal "5.3.2. disjunction is commutative"
  348. '(("v" "w" "z") () () () ("x" "y") (3 0 0 0 2))
  349. (triv-runner
  350. (lambda ()
  351. (test-assert "v" #t)
  352. (test-skip (test-match-any (test-match-name "x")
  353. (test-match-nth 3)))
  354. (test-assert "w" #t) ; 1
  355. (test-assert "x" #t) ; 2 SKIP(NAME)
  356. (test-assert "y" #t) ; 3 SKIP(COUNT)
  357. (test-assert "z" #t)))) ; 4
  358. (test-end)
  359. (test-begin "5.4. test-match-all")
  360. (test-equal "5.4.1. basic conjunction"
  361. '(("v" "w" "y" "z") () () () ("x") (4 0 0 0 1))
  362. (triv-runner
  363. (lambda ()
  364. (test-assert "v" #t)
  365. (test-skip (test-match-all (test-match-nth 2 2)
  366. (test-match-name "x")))
  367. (test-assert "w" #t) ; 1
  368. (test-assert "x" #t) ; 2 SKIP(NAME) & SKIP(COUNT)
  369. (test-assert "y" #t) ; 3 SKIP(COUNT)
  370. (test-assert "z" #t)))) ; 4
  371. (test-equal "5.4.2. conjunction is commutative"
  372. '(("v" "w" "y" "z") () () () ("x") (4 0 0 0 1))
  373. (triv-runner
  374. (lambda ()
  375. (test-assert "v" #t)
  376. (test-skip (test-match-all (test-match-name "x")
  377. (test-match-nth 2 2)))
  378. (test-assert "w" #t) ; 1
  379. (test-assert "x" #t) ; 2 SKIP(NAME) & SKIP(COUNT)
  380. (test-assert "y" #t) ; 3 SKIP(COUNT)
  381. (test-assert "z" #t)))) ; 4
  382. (test-end)
  383. (test-end "5. Test specifiers")
  384. ;;;
  385. ;;;
  386. ;;;
  387. (test-begin "6. Skipping selected tests")
  388. (test-equal
  389. "6.1. Skip by specifier - match-name"
  390. '(("x") () () () ("y") (1 0 0 0 1))
  391. (triv-runner
  392. (lambda ()
  393. (test-begin "a")
  394. (test-skip (test-match-name "y"))
  395. (test-assert "x" #t) ; PASS
  396. (test-assert "y" #f) ; SKIP
  397. (test-end))))
  398. (test-equal
  399. "6.2. Shorthand specifiers"
  400. '(("x") () () () ("y") (1 0 0 0 1))
  401. (triv-runner
  402. (lambda ()
  403. (test-begin "a")
  404. (test-skip "y")
  405. (test-assert "x" #t) ; PASS
  406. (test-assert "y" #f) ; SKIP
  407. (test-end))))
  408. (test-begin "6.3. Specifier Stack")
  409. (test-equal
  410. "6.3.1. Clearing the Specifier Stack"
  411. '(("x" "x") ("y") () () ("y") (2 1 0 0 1))
  412. (triv-runner
  413. (lambda ()
  414. (test-begin "a")
  415. (test-skip "y")
  416. (test-assert "x" #t) ; PASS
  417. (test-assert "y" #f) ; SKIP
  418. (test-end)
  419. (test-begin "b")
  420. (test-assert "x" #t) ; PASS
  421. (test-assert "y" #f) ; FAIL
  422. (test-end))))
  423. (test-equal
  424. "6.3.2. Inheriting the Specifier Stack"
  425. '(("x" "x") () () () ("y" "y") (2 0 0 0 2))
  426. (triv-runner
  427. (lambda ()
  428. (test-skip "y")
  429. (test-begin "a")
  430. (test-assert "x" #t) ; PASS
  431. (test-assert "y" #f) ; SKIP
  432. (test-end)
  433. (test-begin "b")
  434. (test-assert "x" #t) ; PASS
  435. (test-assert "y" #f) ; SKIP
  436. (test-end))))
  437. (test-end);6.3
  438. (test-begin "6.4. Short-circuit evaluation")
  439. (test-equal
  440. "6.4.1. In test-match-all"
  441. '(("x") ("y" "x" "z") () () ("y") (1 3 0 0 1))
  442. (triv-runner
  443. (lambda ()
  444. (test-begin "a")
  445. (test-skip (test-match-all "y" (test-match-nth 2)))
  446. ;; let's label the substructure forms so we can
  447. ;; see which one `test-match-nth' is going to skip
  448. ;; ; # "y" 2 result
  449. (test-assert "x" #t) ; 1 - #f #f PASS
  450. (test-assert "y" #f) ; 2 - #t #t SKIP
  451. (test-assert "y" #f) ; 3 - #t #f FAIL
  452. (test-assert "x" #f) ; 4 - #f #f FAIL
  453. (test-assert "z" #f) ; 5 - #f #f FAIL
  454. (test-end))))
  455. (test-equal
  456. "6.4.2. In separate skip-list entries"
  457. '(("x") ("x" "z") () () ("y" "y") (1 2 0 0 2))
  458. (triv-runner
  459. (lambda ()
  460. (test-begin "a")
  461. (test-skip "y")
  462. (test-skip (test-match-nth 2))
  463. ;; let's label the substructure forms so we can
  464. ;; see which one `test-match-nth' is going to skip
  465. ;; ; # "y" 2 result
  466. (test-assert "x" #t) ; 1 - #f #f PASS
  467. (test-assert "y" #f) ; 2 - #t #t SKIP
  468. (test-assert "y" #f) ; 3 - #t #f SKIP
  469. (test-assert "x" #f) ; 4 - #f #f FAIL
  470. (test-assert "z" #f) ; 5 - #f #f FAIL
  471. (test-end))))
  472. (test-begin "6.4.3. Skipping test suites")
  473. (test-equal
  474. "6.4.3.1. Introduced using 'test-begin'"
  475. '(("x") () () () () (1 0 0 0 0))
  476. (triv-runner
  477. (lambda ()
  478. (test-begin "a")
  479. (test-skip "b")
  480. (test-begin "b") ; not skipped
  481. (test-assert "x" #t)
  482. (test-end "b")
  483. (test-end "a"))))
  484. (test-expect-fail 1) ;; ???
  485. (test-equal
  486. "6.4.3.2. Introduced using 'test-group'"
  487. '(() () () () () (0 0 0 0 1))
  488. (triv-runner
  489. (lambda ()
  490. (test-begin "a")
  491. (test-skip "b")
  492. (test-group
  493. "b" ; skipped
  494. (test-assert "x" #t))
  495. (test-end "a"))))
  496. (test-equal
  497. "6.4.3.3. Non-skipped 'test-group'"
  498. '(("x") () () () () (1 0 0 0 0))
  499. (triv-runner
  500. (lambda ()
  501. (test-begin "a")
  502. (test-skip "c")
  503. (test-group "b" (test-assert "x" #t))
  504. (test-end "a"))))
  505. (test-end) ; 6.4.3
  506. (test-end);6.4
  507. (test-end "6. Skipping selected tests")
  508. ;;;
  509. ;;;
  510. ;;;
  511. (test-begin "7. Expected failures")
  512. (test-equal "7.1. Simple example"
  513. '(() ("x") ("z") () () (0 1 1 0 0))
  514. (triv-runner
  515. (lambda ()
  516. (test-assert "x" #f)
  517. (test-expect-fail "z")
  518. (test-assert "z" #f))))
  519. (test-equal "7.2. Expected exception"
  520. '(() ("x") ("z") () () (0 1 1 0 0))
  521. (triv-runner
  522. (lambda ()
  523. (test-assert "x" #f)
  524. (test-expect-fail "z")
  525. (test-assert "z" (choke)))))
  526. (test-equal "7.3. Unexpectedly PASS"
  527. '(() () ("y") ("x") () (0 0 1 1 0))
  528. (triv-runner
  529. (lambda ()
  530. (test-expect-fail "x")
  531. (test-expect-fail "y")
  532. (test-assert "x" #t)
  533. (test-assert "y" #f))))
  534. (test-end "7. Expected failures")
  535. ;;;
  536. ;;;
  537. ;;;
  538. (test-begin "8. Test-runner")
  539. ;;;
  540. ;;; Because we want this test suite to be accurate even
  541. ;;; when the underlying implementation chooses to use, e.g.,
  542. ;;; a global variable to implement what could be thread variables
  543. ;;; or SRFI-39 parameter objects, we really need to save and restore
  544. ;;; their state ourselves
  545. ;;;
  546. (define (with-factory-saved thunk)
  547. (let* ((saved (test-runner-factory))
  548. (result (thunk)))
  549. (test-runner-factory saved)
  550. result))
  551. (test-begin "8.1. test-runner-current")
  552. (test-assert "8.1.1. automatically restored"
  553. (let ((a 0)
  554. (b 1)
  555. (c 2))
  556. ;
  557. (triv-runner
  558. (lambda ()
  559. (set! a (test-runner-current))
  560. ;;
  561. (triv-runner
  562. (lambda ()
  563. (set! b (test-runner-current))))
  564. ;;
  565. (set! c (test-runner-current))))
  566. ;;
  567. (and (eq? a c)
  568. (not (eq? a b)))))
  569. (test-end)
  570. (test-begin "8.2. test-runner-simple")
  571. (test-assert "8.2.1. default on-test hook"
  572. (eq? (test-runner-on-test-end (test-runner-simple))
  573. test-on-test-end-simple))
  574. (test-assert "8.2.2. default on-final hook"
  575. (eq? (test-runner-on-final (test-runner-simple))
  576. test-on-final-simple))
  577. (test-end)
  578. (test-begin "8.3. test-runner-factory")
  579. (test-assert "8.3.1. default factory"
  580. (eq? (test-runner-factory) test-runner-simple))
  581. (test-assert "8.3.2. settable factory"
  582. (with-factory-saved
  583. (lambda ()
  584. (test-runner-factory test-runner-null)
  585. ;; we have no way, without bringing in other SRFIs,
  586. ;; to make sure the following doesn't print anything,
  587. ;; but it shouldn't:
  588. (test-with-runner
  589. (test-runner-create)
  590. (lambda ()
  591. (test-begin "a")
  592. (test-assert #t) ; pass
  593. (test-assert #f) ; fail
  594. (test-assert (vector-ref '#(3) 10)) ; fail with error
  595. (test-end "a")))
  596. (eq? (test-runner-factory) test-runner-null))))
  597. (test-end)
  598. ;;; This got tested about as well as it could in 8.3.2
  599. (test-begin "8.4. test-runner-create")
  600. (test-end)
  601. ;;; This got tested about as well as it could in 8.3.2
  602. (test-begin "8.5. test-runner-factory")
  603. (test-end)
  604. (test-begin "8.6. test-apply")
  605. (test-equal "8.6.1. Simple (form 1) test-apply"
  606. '(("w" "p" "v") () () () ("x") (3 0 0 0 1))
  607. (triv-runner
  608. (lambda ()
  609. (test-begin "a")
  610. (test-assert "w" #t)
  611. (test-apply
  612. (test-match-name "p")
  613. (lambda ()
  614. (test-begin "p")
  615. (test-assert "x" #t)
  616. (test-end)
  617. (test-begin "z")
  618. (test-assert "p" #t) ; only this one should execute in here
  619. (test-end)))
  620. (test-assert "v" #t))))
  621. (test-equal "8.6.2. Simple (form 2) test-apply"
  622. '(("w" "p" "v") () () () ("x") (3 0 0 0 1))
  623. (triv-runner
  624. (lambda ()
  625. (test-begin "a")
  626. (test-assert "w" #t)
  627. (test-apply
  628. (test-runner-current)
  629. (test-match-name "p")
  630. (lambda ()
  631. (test-begin "p")
  632. (test-assert "x" #t)
  633. (test-end)
  634. (test-begin "z")
  635. (test-assert "p" #t) ; only this one should execute in here
  636. (test-end)))
  637. (test-assert "v" #t))))
  638. (test-expect-fail 1) ;; depends on all test-match-nth being called.
  639. (test-equal "8.6.3. test-apply with skips"
  640. '(("w" "q" "v") () () () ("x" "p" "x") (3 0 0 0 3))
  641. (triv-runner
  642. (lambda ()
  643. (test-begin "a")
  644. (test-assert "w" #t)
  645. (test-skip (test-match-nth 2))
  646. (test-skip (test-match-nth 4))
  647. (test-apply
  648. (test-runner-current)
  649. (test-match-name "p")
  650. (test-match-name "q")
  651. (lambda ()
  652. ; only execute if SKIP=no and APPLY=yes
  653. (test-assert "x" #t) ; # 1 SKIP=no APPLY=no
  654. (test-assert "p" #t) ; # 2 SKIP=yes APPLY=yes
  655. (test-assert "q" #t) ; # 3 SKIP=no APPLY=yes
  656. (test-assert "x" #f) ; # 4 SKIP=yes APPLY=no
  657. 0))
  658. (test-assert "v" #t))))
  659. ;;; Unfortunately, since there is no way to UNBIND the current test runner,
  660. ;;; there is no way to test the behavior of `test-apply' in the absence
  661. ;;; of a current runner within our little meta-test framework.
  662. ;;;
  663. ;;; To test the behavior manually, you should be able to invoke:
  664. ;;;
  665. ;;; (test-apply "a" (lambda () (test-assert "a" #t)))
  666. ;;;
  667. ;;; from the top level (with SRFI 64 available) and it should create a
  668. ;;; new, default (simple) test runner.
  669. (test-end)
  670. ;;; This entire suite depends heavily on 'test-with-runner'. If it didn't
  671. ;;; work, this suite would probably go down in flames
  672. (test-begin "8.7. test-with-runner")
  673. (test-end)
  674. ;;; Again, this suite depends heavily on many of the test-runner
  675. ;;; components. We'll just test those that aren't being exercised
  676. ;;; by the meta-test framework
  677. (test-begin "8.8. test-runner components")
  678. (define (auxtrack-runner thunk)
  679. (let ((r (test-runner-null)))
  680. (test-runner-aux-value! r '())
  681. (test-runner-on-test-end! r (lambda (r)
  682. (test-runner-aux-value!
  683. r
  684. (cons (test-runner-test-name r)
  685. (test-runner-aux-value r)))))
  686. (test-with-runner r (thunk))
  687. (reverse (test-runner-aux-value r))))
  688. (test-equal "8.8.1. test-runner-aux-value"
  689. '("x" "" "y")
  690. (auxtrack-runner
  691. (lambda ()
  692. (test-assert "x" #t)
  693. (test-begin "a")
  694. (test-assert #t)
  695. (test-end)
  696. (test-assert "y" #f))))
  697. (test-end) ; 8.8
  698. (test-end "8. Test-runner")
  699. (test-begin "9. Test Result Properties")
  700. (test-begin "9.1. test-result-alist")
  701. (define (symbol-alist? l)
  702. (if (null? l)
  703. #t
  704. (and (pair? l)
  705. (pair? (car l))
  706. (symbol? (caar l))
  707. (symbol-alist? (cdr l)))))
  708. ;;; check the various syntactic forms
  709. (test-assert (symbol-alist?
  710. (car (on-test-runner
  711. (lambda ()
  712. (test-assert #t))
  713. (lambda (r)
  714. (test-result-alist r))))))
  715. (test-assert (symbol-alist?
  716. (car (on-test-runner
  717. (lambda ()
  718. (test-assert #t))
  719. (lambda (r)
  720. (test-result-alist r))))))
  721. ;;; check to make sure the required properties are returned
  722. (test-equal '((result-kind . pass))
  723. (prop-runner
  724. '(result-kind)
  725. (lambda ()
  726. (test-assert #t)))
  727. )
  728. (test-equal
  729. '((result-kind . fail)
  730. (expected-value . 2)
  731. (actual-value . 3))
  732. (prop-runner
  733. '(result-kind expected-value actual-value)
  734. (lambda ()
  735. (test-equal 2 (+ 1 2)))))
  736. (test-end "9.1. test-result-alist")
  737. (test-begin "9.2. test-result-ref")
  738. (test-equal '(pass)
  739. (on-test-runner
  740. (lambda ()
  741. (test-assert #t))
  742. (lambda (r)
  743. (test-result-ref r 'result-kind))))
  744. (test-equal '(pass)
  745. (on-test-runner
  746. (lambda ()
  747. (test-assert #t))
  748. (lambda (r)
  749. (test-result-ref r 'result-kind))))
  750. (test-equal '(fail pass)
  751. (on-test-runner
  752. (lambda ()
  753. (test-assert (= 1 2))
  754. (test-assert (= 1 1)))
  755. (lambda (r)
  756. (test-result-ref r 'result-kind))))
  757. (test-end "9.2. test-result-ref")
  758. (test-begin "9.3. test-result-set!")
  759. (test-equal '(100 100)
  760. (on-test-runner
  761. (lambda ()
  762. (test-assert (= 1 2))
  763. (test-assert (= 1 1)))
  764. (lambda (r)
  765. (test-result-set! r 'foo 100)
  766. (test-result-ref r 'foo))))
  767. (test-end "9.3. test-result-set!")
  768. (test-end "9. Test Result Properties")
  769. ;;;
  770. ;;;
  771. ;;;
  772. #| Time to stop having fun...
  773. (test-begin "9. For fun, some meta-test errors")
  774. (test-equal
  775. "9.1. Really PASSes, but test like it should FAIL"
  776. '(() ("b") () () ())
  777. (triv-runner
  778. (lambda ()
  779. (test-assert "b" #t))))
  780. (test-expect-fail "9.2. Expect to FAIL and do so")
  781. (test-expect-fail "9.3. Expect to FAIL but PASS")
  782. (test-skip "9.4. SKIP this one")
  783. (test-assert "9.2. Expect to FAIL and do so" #f)
  784. (test-assert "9.3. Expect to FAIL but PASS" #t)
  785. (test-assert "9.4. SKIP this one" #t)
  786. (test-end)
  787. |#
  788. (test-end "SRFI 64 - Meta-Test Suite")
  789. ;;;