forked from iloveponies/training-day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.grading_emitter.clj
41 lines (35 loc) · 1.64 KB
/
.grading_emitter.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(ns grading-emitter
(:require [midje.emission.plugins.util :as util]
[midje.data.fact :as fact]
[midje.emission.plugins.silence :as silence]
[midje.emission.plugins.default :as default]
[midje.emission.state :as state]))
(def failures (atom 0))
(def points-counter (atom 0))
(defn starting-to-check-top-level-fact [fact]
(swap! failures (constantly (state/output-counters:midje-failures))))
(defn finishing-top-level-fact [fact]
(let [points (:points (meta fact))
exercise (:exercise (meta fact))]
(if (= (state/output-counters:midje-failures) @failures)
(do (util/emit-one-line (format "%d point(s) from exercise %d"
points
exercise))
(swap! points-counter (partial + points)))
(util/emit-one-line (format "no points from exercise %d" exercise)))))
(defn starting-fact-stream []
(swap! points-counter (constantly 0)))
(defn finishing-fact-stream
([])
([_ _]
(util/emit-one-line (format "%d points in total" @points-counter))))
(state/install-emission-map (assoc silence/emission-map
:fail (:fail default/emission-map)
:starting-to-check-top-level-fact
starting-to-check-top-level-fact
:finishing-top-level-fact
finishing-top-level-fact
:starting-fact-stream
starting-fact-stream
:finishing-fact-stream
finishing-fact-stream))