|
433 | 433 | ;; =============================================================================
|
434 | 434 | ;; Low-level functions
|
435 | 435 |
|
| 436 | +(defn- test-var-block* |
| 437 | + [v t] |
| 438 | + {:pre [(instance? Var v)]} |
| 439 | + [(fn [] |
| 440 | + (update-current-env! [:testing-vars] conj v) |
| 441 | + (update-current-env! [:report-counters :test] inc) |
| 442 | + (do-report {:type :begin-test-var :var v}) |
| 443 | + (try |
| 444 | + (t) |
| 445 | + (catch :default e |
| 446 | + (case e |
| 447 | + ::async-disabled (throw "Async tests require fixtures to be specified as maps. Testing aborted.") |
| 448 | + (do-report |
| 449 | + {:type :error |
| 450 | + :message "Uncaught exception, not in assertion." |
| 451 | + :expected nil |
| 452 | + :actual e}))))) |
| 453 | + (fn [] |
| 454 | + (do-report {:type :end-test-var :var v}) |
| 455 | + (update-current-env! [:testing-vars] rest))]) |
| 456 | + |
436 | 457 | (defn test-var-block
|
437 | 458 | "Like test-var, but returns a block for further composition and
|
438 | 459 | later execution."
|
439 | 460 | [v]
|
440 |
| - {:pre [(instance? Var v)]} |
441 | 461 | (if-let [t (:test (meta v))]
|
442 |
| - [(fn [] |
443 |
| - (update-current-env! [:testing-vars] conj v) |
444 |
| - (update-current-env! [:report-counters :test] inc) |
445 |
| - (do-report {:type :begin-test-var :var v}) |
446 |
| - (try |
447 |
| - (t) |
448 |
| - (catch :default e |
449 |
| - (do-report |
450 |
| - {:type :error |
451 |
| - :message "Uncaught exception, not in assertion." |
452 |
| - :expected nil |
453 |
| - :actual e})))) |
454 |
| - (fn [] |
455 |
| - (do-report {:type :end-test-var :var v}) |
456 |
| - (update-current-env! [:testing-vars] rest))])) |
| 462 | + (test-var-block* v t))) |
457 | 463 |
|
458 | 464 | (defn test-var
|
459 | 465 | "If v has a function in its :test metadata, calls that function,
|
|
506 | 512 | "Fixtures may not be of mixed types")
|
507 | 513 | (assert (> 2 (count types))
|
508 | 514 | "fixtures specified in :once and :each must be of the same type")
|
509 |
| - ({:map :async :fn :sync} type :sync)))) |
| 515 | + ({:map :async :fn :sync} type :async)))) |
| 516 | + |
| 517 | +(defn- disable-async [f] |
| 518 | + (fn [] |
| 519 | + (let [obj (f)] |
| 520 | + (when (async? obj) |
| 521 | + (throw ::async-disabled)) |
| 522 | + obj))) |
510 | 523 |
|
511 | 524 | (defn test-vars-block
|
512 | 525 | "Like test-vars, but returns a block for further composition and
|
|
527 | 540 | test-var-block))
|
528 | 541 | (wrap-map-fixtures once-fixtures))
|
529 | 542 | :sync
|
530 |
| - (do |
531 |
| - (let [each-fixture-fn (join-fixtures each-fixtures)] |
532 |
| - [(fn [] |
533 |
| - ((join-fixtures once-fixtures) |
534 |
| - (fn [] |
535 |
| - (doseq [v vars] |
536 |
| - (when (:test (meta v)) |
537 |
| - (each-fixture-fn |
538 |
| - (fn [] |
539 |
| - (test-var v))))))))]))))))) |
| 543 | + (let [each-fixture-fn (join-fixtures each-fixtures)] |
| 544 | + [(fn [] |
| 545 | + ((join-fixtures once-fixtures) |
| 546 | + (fn [] |
| 547 | + (doseq [v vars] |
| 548 | + (when-let [t (:test (meta v))] |
| 549 | + ;; (alter-meta! v update :test disable-async) |
| 550 | + (each-fixture-fn |
| 551 | + (fn [] |
| 552 | + ;; (test-var v) |
| 553 | + (run-block |
| 554 | + (test-var-block* v (disable-async t))))))))))])))))) |
540 | 555 | (group-by (comp :ns meta) vars)))
|
541 | 556 |
|
542 | 557 | (defn test-vars
|
|
0 commit comments