Skip to content

Commit

Permalink
Merge pull request #277 from vito/refute
Browse files Browse the repository at this point in the history
add `(refute)`; opposite of `(assert)`
  • Loading branch information
vito authored Apr 15, 2023
2 parents 7cfa05d + 5b96084 commit e5e50c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bass/bass.lock
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ memos: {
}
repository: "hello-world"
tag: "latest"
digest: "sha256:ffb13da98453e0f04d33a6eee5bb8e46ee50d08ebe17735fc0779d0349e889e9"
digest: "sha256:4e83453afed1b4fa1a3500525091dbfca6ce1e66903fd4c01ff015dbcb1ba33e"
}
}
}
Expand Down Expand Up @@ -500,7 +500,7 @@ memos: {
}
output: {
string: {
value: "6ca3f15d70b739a7929886e20b61dbc4cbdc4e22"
value: "cbcb3f550f1208f8804c9f4e52921bd868856cd5"
}
}
}
Expand All @@ -521,7 +521,7 @@ memos: {
}
output: {
string: {
value: "a6c8ee8f81531c08c5136feca23cc6cca0be3b24"
value: "a18944bec00bd72341909da8cf0147a1e59884d5"
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions std/root.bass
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,18 @@
(if (apply pred args)
null
(error (str "assertion failed: " [predicate & args])))))

; applies the predicate to its arguments and errors if it returns true
;
; By convention, the expected value should be passed as the first argument.
;
; => (refute = 4 (+ 2 2))
;
; => (refute = 5 (+ 2 2))
^:indent
(defop refute [predicate & args] scope
(let [pred (eval predicate scope)
args (map (fn [a] (eval a scope)) args)]
(if (apply pred args)
(error (str "refutation failed: " [predicate & args]))
null)))

0 comments on commit e5e50c9

Please sign in to comment.