Skip to content

Commit 2bceba4

Browse files
committed
Assertf with no arguments does not make sense.
1 parent e3159bb commit 2bceba4

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/boot/boot.janet

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@
154154
,v
155155
(,error ,(if err err (string/format "assert failure in %j" x))))))
156156

157-
(defmacro assertf
158-
"Convenience macro that combines `assert` and `string/format`."
159-
[x & args]
160-
~(as-macro ,assert ,x (,string/format ,;args)))
161-
162157
(defmacro defdyn
163158
``Define an alias for a keyword that is used as a dynamic binding. The
164159
alias is a normal, lexically scoped binding that can be used instead of
@@ -209,6 +204,16 @@
209204
[fmt & args]
210205
(error (string/format fmt ;args)))
211206

207+
(defmacro assertf
208+
"Convenience macro that combines `assert` and `string/format`."
209+
[x fmt & args]
210+
(def v (gensym))
211+
~(do
212+
(def ,v ,x)
213+
(if ,v
214+
,v
215+
(,errorf ,fmt ,;args))))
216+
212217
(defmacro default
213218
``Define a default value for an optional argument.
214219
Expands to `(def sym (if (= nil sym) val sym))`.``

test/suite-boot.janet

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,10 @@
987987
(setdyn *debug* nil)
988988

989989
# issue #1516
990-
(assert (assertf true) "assertf 1 argument")
990+
(assert-error "assertf 1 argument" (macex '(assertf true)))
991991
(assert (assertf true "fun message") "assertf 2 arguments")
992992
(assert (assertf true "%s message" "mystery") "assertf 3 arguments")
993993
(assert (assertf (not nil) "%s message" "ordinary") "assertf not nil")
994-
(assert-error "assertf error 1" (assertf false))
995994
(assert-error "assertf error 2" (assertf false "fun message"))
996995
(assert-error "assertf error 3" (assertf false "%s message" "mystery"))
997996
(assert-error "assertf error 4" (assertf nil "%s %s" "alice" "bob"))

0 commit comments

Comments
 (0)