Skip to content

Commit 3d9d4eb

Browse files
committed
Default and schema tests
1 parent 5bd44ee commit 3d9d4eb

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

project.clj

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
:url "http://example.com/FIXME"
44
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
55
:url "https://www.eclipse.org/legal/epl-2.0/"}
6-
:dependencies [[org.clojure/clojure "1.10.3"]]
6+
:dependencies [
7+
[org.clojure/clojure "1.10.3"]
8+
[prismatic/schema "1.2.0"]
9+
]
710
:main ^:skip-aot clojure-noob.core
811
:target-path "target/%s"
912
:profiles {:uberjar {:aot :all
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(ns clojure-noob.under-test.functions
2+
(:require [schema.core :as s]
3+
[schema.test :as st]))
4+
5+
(defn my-sum [& numbers]
6+
(apply + (take 2 numbers)))
7+
8+
(my-sum 1 1)
9+
(my-sum 1 1 1)
10+
11+
(s/defn c->f
12+
"Celsius to Fahrenheit"
13+
[c :- s/Int]
14+
(int (+ 32 (/ (* c 9) 5))))
15+
16+
(s/defschema Something {:a s/Int
17+
:b s/Str})

test/clojure_noob/core_test.clj

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
11
(ns clojure-noob.core-test
2-
(:require [clojure.test :refer :all]
3-
[clojure-noob.core :refer :all]))
2+
(:require [clojure-noob.core :refer :all]
3+
[clojure-noob.under-test.functions :refer [my-sum, c->f]]
4+
[clojure.test :refer :all]
5+
[schema.core :as s]
6+
[schema.test :as st]))
7+
8+
(use-fixtures :once schema.test/validate-schemas)
49

510
(deftest a-test
611
(testing "FIXME, I fail."
712
(is (= 0 1))))
13+
14+
(deftest test-sum
15+
(testing "adds numbers"
16+
(is (= 3 (my-sum 1 2)))
17+
(is (= 6 (my-sum 1 2 3)))))
18+
19+
(test-sum)
20+
(test-vars [#'test-sum])
21+
(run-tests)
22+
23+
(deftest test-c->f
24+
(is (= 32 (c->f 0.0))))
25+
26+
; it doesn't fail even though we are passing a double
27+
(test-c->f)
28+
29+
(use-fixtures :once)
30+
31+
(deftest test-c->f-v2
32+
(s/with-fn-validation
33+
(is (= 32 (c->f 0.0)))))
34+
35+
; now the schema violation appears as [(named (not (integer? 0.0)) c)]
36+
(test-c->f-v2)

0 commit comments

Comments
 (0)