Skip to content

Commit c9bf3f4

Browse files
lgrapenthinswannodette
authored andcommitted
fix cljs-1198
1 parent 11113ce commit c9bf3f4

File tree

1 file changed

+42
-27
lines changed

1 file changed

+42
-27
lines changed

src/cljs/cljs/test.cljs

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -433,27 +433,33 @@
433433
;; =============================================================================
434434
;; Low-level functions
435435

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+
436457
(defn test-var-block
437458
"Like test-var, but returns a block for further composition and
438459
later execution."
439460
[v]
440-
{:pre [(instance? Var v)]}
441461
(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)))
457463

458464
(defn test-var
459465
"If v has a function in its :test metadata, calls that function,
@@ -506,7 +512,14 @@
506512
"Fixtures may not be of mixed types")
507513
(assert (> 2 (count types))
508514
"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)))
510523

511524
(defn test-vars-block
512525
"Like test-vars, but returns a block for further composition and
@@ -527,16 +540,18 @@
527540
test-var-block))
528541
(wrap-map-fixtures once-fixtures))
529542
: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))))))))))]))))))
540555
(group-by (comp :ns meta) vars)))
541556

542557
(defn test-vars

0 commit comments

Comments
 (0)