|
@@ -20,24 +20,56 @@
|
20
|
20
|
[defenv.core :refer :all])
|
21
|
21
|
(:import (clojure.lang ExceptionInfo)))
|
22
|
22
|
|
23
|
|
-(defenv log-level "LOG_LEVEL" :doc "Global log level." :tfn keyword
|
24
|
|
- :default "info")
|
|
23
|
+;;Undefined vars
|
|
24
|
+(defenv log-level "LOG_LEVEL" :doc "Global log level."
|
|
25
|
+ :tfn keyword :default "info")
|
|
26
|
+(defenv should-log "SHOULD_LOG" :doc "Should I log? A boolean."
|
|
27
|
+ :tfn Boolean/parseBoolean :default "false")
|
|
28
|
+
|
|
29
|
+;; Testing we can remove the previous definition from the docstring
|
25
|
30
|
(defenv thing "THING" :default "go away")
|
26
|
31
|
(defenv thing "THING")
|
27
|
|
-(defenv amount "AMOUNT" :doc "An amount. A double." :tfn nilsafe-parse-double
|
28
|
|
- :default "1.5")
|
|
32
|
+
|
|
33
|
+(defenv amount "AMOUNT" :doc "An amount. A double."
|
|
34
|
+ :tfn Double/parseDouble :default "1.5")
|
|
35
|
+(defenv acount "COUNT" :doc "A count. An int."
|
|
36
|
+ :tfn Integer/parseInt :default "5")
|
29
|
37
|
(defenv another "ANOTHER" :doc "This is really important!")
|
30
|
38
|
|
|
39
|
+;;Vars defined in .env
|
|
40
|
+(defenv fun "FUN")
|
|
41
|
+(defenv apples "APPLES" :tfn Integer/parseInt :default "10")
|
|
42
|
+(defenv weight "WEIGHT" :tfn Float/parseFloat)
|
|
43
|
+(defenv eat "EAT" :tfn Boolean/parseBoolean :default "false"
|
|
44
|
+ :doc "Should we eat?")
|
|
45
|
+
|
31
|
46
|
(def expected-message
|
32
|
47
|
(str "One or more environment variables is missing:\n"
|
|
48
|
+ "AMOUNT = 1.5 ;; An amount. A double.\n"
|
|
49
|
+ "ANOTHER = *MISSING* ;; This is really important!\n"
|
|
50
|
+ "APPLES = 21\n"
|
|
51
|
+ "COUNT = 5 ;; A count. An int.\n"
|
|
52
|
+ "EAT = true ;; Should we eat?\n"
|
|
53
|
+ "FUN = good\n"
|
33
|
54
|
"LOG_LEVEL = info ;; Global log level.\n"
|
|
55
|
+ "SHOULD_LOG = false ;; Should I log? A boolean.\n"
|
34
|
56
|
"THING = *MISSING*\n"
|
35
|
|
- "AMOUNT = 1.5 ;; An amount. A double.\n"
|
36
|
|
- "ANOTHER = *MISSING* ;; This is really important!"))
|
|
57
|
+ "WEIGHT = 0.12"))
|
37
|
58
|
|
38
|
59
|
(deftest usage
|
39
|
|
- (is (= expected-message (make-usage-string)))
|
40
|
|
- (is (= 1.5 @amount))
|
41
|
|
- (is (thrown? ExceptionInfo @thing))
|
42
|
|
- (is (= expected-message
|
43
|
|
- (try @thing (catch ExceptionInfo e (.getMessage e))))))
|
|
60
|
+ (testing "message construction"
|
|
61
|
+ (is (= expected-message (make-usage-string))))
|
|
62
|
+
|
|
63
|
+ (testing "exception throwing"
|
|
64
|
+ (is (thrown? ExceptionInfo @thing))
|
|
65
|
+ (is (= expected-message
|
|
66
|
+ (try @thing (catch ExceptionInfo e (.getMessage e))))))
|
|
67
|
+
|
|
68
|
+ (testing "value extraction"
|
|
69
|
+ (is (= 1.5 @amount))
|
|
70
|
+ (is (= 5 @acount))
|
|
71
|
+ (is (not @should-log))
|
|
72
|
+ (is (= "good" @fun))
|
|
73
|
+ (is (= 21 @apples))
|
|
74
|
+ (is (= (float 0.12) @weight))
|
|
75
|
+ (is @eat)))
|