Skip to content

report failed assertions in return value of run function #66

@dchelimsky

Description

@dchelimsky

When a match? assertion fails, the failure info is printed to the repl, and the return value of run doesn't include any information about it:

(run
  (flow "interact with db"
    [db (state/gets :db)]
    (state/wrap-fn #(register-user db {:name "Phillip"}))
    (match? "user got added"
            (state/wrap-fn #(fetch-users db))
            #{{:name "Philip"}})) ;; <- different spelling
  {:db (atom {:users #{}})})
;; => #<Pair [#{{:name "Phillip"}} {:db #atom[{:users #{{:name "Phillip"}}} 0x4c2a27a6]}]>

;; --- printed to repl ---
;; FAIL in () (form-init13207122878088623810.clj:256)
;; interact with db (line 253) -> user got added
;; expected: (match? #{{:name "Philip"}} actual__12555__auto__)
;; actual: #{{:name (mismatch "Philip" "Phillip")}}
;; --- /printed to repl ---

This is fine if you're typing in the repl, but if you're using an dev environment in which you type in source files and send expressions to a connected repl, things get a bit disconnected.

I'm not sure about the format yet, but I think we should report assertion failures in the state, e.g.

#<Pair [#{{:name "Phillip"}}
        {:db #atom[{:users #{{:name "Phillip"}}} 0x4c2a27a6]
         :failed-assertions
         [{:location "form-init13207122878088623810.clj:256"
            :name "interact with db (line 253) -> user got added"
            :expected (match? #{{:name "Philip"}} actual__12555__auto__)
            :actual #{{:name (mismatch "Philip" "Phillip")}}}]}]>

Then, perhaps, the run function could inspect state for failures and include them in the return - possibly wrapping them in a Failure object to align with runtime exceptions.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions