Skip to content

Commit 50a36ca

Browse files
committed
fixes #41 by deprecating implicit expect
Signed-off-by: Sean Corfield <[email protected]>
1 parent cc192ed commit 50a36ca

File tree

7 files changed

+22
-25
lines changed

7 files changed

+22
-25
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
.settings
2525
.socket-repl-port
2626
.sw*
27-
.vscode
2827
/checkouts
2928
/classes
3029
/cljs-test-runner-out

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
Only accretive/fixative changes will be made from now on.
88

9-
* 2.1.next in progress
9+
* 2.2.next in progress
10+
* Address [#41](https://github.com/clojure-expectations/clojure-test/issues/41) by deprecating the implicit `expect` form of `defexpect` and printing an obnoxious warning when it is used. This form of `defexpect` will be removed in a future release!
1011
* PR [#40](https://github.com/clojure-expectations/clojure-test/pull/40) [@NoahTheDuke](https://github.com/NoahTheDuke) reduces the amount of code generated for `?=` (and, in turn, for `more-of`), allowing for more complex tests.
1112

1213
* 2.1.208 -- 2024-11-21

README.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,20 @@ What follows is an example REPL session showing some of what this library provid
9393
(defexpect regex-1
9494
(expect #"foo" "It's foobar!"))
9595

96-
;; since that has only a single expectation, it can be written more succinctly:
97-
98-
(defexpect regex-2 #"foo" "It's foobar!")
99-
10096
;; the expected outcome can be an exception type:
10197

102-
(defexpect divide-by-zero ArithmeticException (/ 12 0))
98+
(defexpect divide-by-zero
99+
(expect ArithmeticException (/ 12 0)))
103100

104101
;; the expected outcome can be a predicate:
105102

106-
(defexpect no-elements empty? (list))
103+
(defexpect no-elements
104+
(expect empty? (list)))
107105

108106
;; the expected outcome can be a type:
109107

110-
(defexpect named String (name :foo))
108+
(defexpect named
109+
(expect String (name :foo)))
111110

112111
;; the expected outcome can be a Spec:
113112

@@ -151,7 +150,7 @@ nil
151150
If the test passes, nothing is printed, and `nil` is returned. Let's look at a failing test:
152151

153152
```clojure
154-
user=> (defexpect inequality (* 2 21) (+ 13 13 13))
153+
user=> (defexpect inequality (expect (* 2 21) (+ 13 13 13)))
155154
#'user/inequality
156155
user=> (inequality)
157156

@@ -167,7 +166,7 @@ that allows for Expectations style of predicate-or-equality testing (based on
167166
whether the "expected" expression resolves to a function or some other value):
168167

169168
```clojure
170-
user=> (defexpect not-at-all-odd odd? (+ 1 1))
169+
user=> (defexpect not-at-all-odd (expect odd? (+ 1 1)))
171170
#'user/not-at-all-odd
172171
user=> (not-at-all-odd)
173172

build.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
[deps-deploy.deps-deploy :as dd]))
2929

3030
(def lib 'com.github.seancorfield/expectations)
31-
(defn- the-version [patch] (format "2.1.%s" patch))
31+
(defn- the-version [patch] (format "2.2.%s" patch))
3232
(def version (the-version (b/git-count-revs nil)))
3333
(def snapshot (the-version "999-SNAPSHOT"))
3434
(def class-dir "target/classes")

doc/getting-started-cljs.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ Classes are all different in ClojureScript, and in some cases things
124124
that would be a class in Clojure are different in ClojureScript. For
125125
instance, lists are a class:
126126
```clojure
127-
(defexpect class-test cljs.core/List '(a b c))
127+
(defexpect class-test (expect cljs.core/List '(a b c)))
128128
```
129129
and this test passes. Strings, however, don't have an easily
130130
discoverable type or class, and are better handled with a predicate:
131131
```clojure
132-
(defexpect string-class-test string? "abc")
132+
(defexpect string-class-test (expect string? "abc"))
133133
```
134134
In general, the classes in ClojureScript will not be the same as
135135
the classes in Clojure. You can do this to write a test that
@@ -139,7 +139,7 @@ will work in both environments:
139139
```
140140
but you cannot write this:
141141
```
142-
(defexpect bad-both-class-test (type "abc") (type "def"))
142+
(defexpect bad-both-class-test (expect (type "abc") (type "def")))
143143
```
144144
because `(type "abc")` yields something that tests positive as a
145145
`fn?`, causing expectations to think it is a predicate. Which,
@@ -151,12 +151,12 @@ Exceptions are very different in ClojureScript from Clojure.
151151

152152
The Clojure example:
153153
```clojure
154-
(defexpect divide-by-zero ArithmeticException (/ 12 0))
154+
(defexpect divide-by-zero (expect ArithmeticException (/ 12 0)))
155155
```
156156
doesn't even throw an exception -- it returns `##Inf`.
157157
You can do this for that situation:
158158
```clojure
159-
(defexpect divide-by-zero ##Inf (/ 12 0))
159+
(defexpect divide-by-zero (expect ##Inf (/ 12 0)))
160160
```
161161
but be careful putting `##Inf` in a reader conditional, as some versions of
162162
Clojure don't handle that well. But all of this is a bit off-topic,
@@ -168,7 +168,7 @@ Clojurecript to distinguish things that can be thrown from anything
168168
else. The only exception supported in `expectations/clojure-test`
169169
in ClojureScript is where the exception is: `js/Error`. For example:
170170
```clojure
171-
(defexpect exception js/Error (count 5))
171+
(defexpect exception (expect js/Error (count 5)))
172172
```
173173
will pass, because `(count 5)` throws `js/Error`.
174174

src/expectations/clojure/test.cljc

+4-6
Original file line numberDiff line numberDiff line change
@@ -445,16 +445,14 @@
445445

446446
(defmacro defexpect
447447
"Given a name (a symbol that may include metadata) and a test body,
448-
produce a standard `clojure.test` test var (using `deftest`).
449-
450-
`(defexpect name expected actual)` is a special case shorthand for
451-
`(defexpect name (expect expected actual))` provided as an easy way to migrate
452-
legacy Expectation tests to the 'clojure.test' compatibility version."
448+
produce a standard `clojure.test` test var (using `deftest`)."
453449
[n & body]
454450
(if (and (= (count body) 2)
455451
(not (some contains-expect? body)))
456452
;; treat (defexpect my-name pred (expr)) as a special case
457-
`(t/deftest ~n (expect ~@body))
453+
`(t/deftest ~n (do
454+
(println "DEPRECATED: implicit 'expect' in defexpect" '~n)
455+
(expect ~@body)))
458456
;; #13 match deftest behavior starting in 2.0.0
459457
`(t/deftest ~n ~@body)))
460458

test/expectations/clojure/test_test.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191

192192
(def ^:private control (atom 0))
193193
;; this will succeed on its own
194-
(sut/defexpect control-test-1 zero? @control)
194+
(sut/defexpect control-test-1 (sut/expect zero? @control))
195195
;; then retest with a different control value
196196
(deftest control-test-2
197197
(try

0 commit comments

Comments
 (0)