From 2bceba4a7a2706cef8ef26e8071660fc2cd5829a Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 24 Nov 2024 19:14:18 -0600 Subject: [PATCH] Assertf with no arguments does not make sense. --- src/boot/boot.janet | 15 ++++++++++----- test/suite-boot.janet | 3 +-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 6b205625..8e306f8b 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -154,11 +154,6 @@ ,v (,error ,(if err err (string/format "assert failure in %j" x)))))) -(defmacro assertf - "Convenience macro that combines `assert` and `string/format`." - [x & args] - ~(as-macro ,assert ,x (,string/format ,;args))) - (defmacro defdyn ``Define an alias for a keyword that is used as a dynamic binding. The alias is a normal, lexically scoped binding that can be used instead of @@ -209,6 +204,16 @@ [fmt & args] (error (string/format fmt ;args))) +(defmacro assertf + "Convenience macro that combines `assert` and `string/format`." + [x fmt & args] + (def v (gensym)) + ~(do + (def ,v ,x) + (if ,v + ,v + (,errorf ,fmt ,;args)))) + (defmacro default ``Define a default value for an optional argument. Expands to `(def sym (if (= nil sym) val sym))`.`` diff --git a/test/suite-boot.janet b/test/suite-boot.janet index ab829107..98049ae6 100644 --- a/test/suite-boot.janet +++ b/test/suite-boot.janet @@ -987,11 +987,10 @@ (setdyn *debug* nil) # issue #1516 -(assert (assertf true) "assertf 1 argument") +(assert-error "assertf 1 argument" (macex '(assertf true))) (assert (assertf true "fun message") "assertf 2 arguments") (assert (assertf true "%s message" "mystery") "assertf 3 arguments") (assert (assertf (not nil) "%s message" "ordinary") "assertf not nil") -(assert-error "assertf error 1" (assertf false)) (assert-error "assertf error 2" (assertf false "fun message")) (assert-error "assertf error 3" (assertf false "%s message" "mystery")) (assert-error "assertf error 4" (assertf nil "%s %s" "alice" "bob"))