lazytest

2026-03-18T17:14:43.115379Z

i see that at least one person has written a custom reporter for lazytest, which means i now cannot change the format of the reporters system. this makes me nervous about hooks lol

2026-03-18T17:15:50.444479Z

let me bounce some ideas off y'all, see how it feels to write out

2026-03-18T17:16:09.808049Z

(taking a break from my $DAYJOB to think about this lol)

2026-03-18T17:19:30.724149Z

Currently, the runner takes in a single suite and then recurses over it with the run-tree multimethod. for each suite, it produces a suite-result, a map with :type :lazyteset.suite/suite-result, docs, and then :source and :children, where :source is the given suite that was run, and :children are the results of the recursive calls (other suite results or test case results). for each test case, it produces a test-case-result with :source (the given test case) and other relevant details

2026-03-18T17:21:29.900779Z

this creates a nice map of {:type :lazytest.suite/suite-result :source ... :children [...]} etc that can be iterated over to find all of the suites and test cases and other pieces

2026-03-18T17:22:27.984649Z

the pre and post hooks for each of these are keyed to the input suite/test case and then the suite/test case result object:

(defmethod run-tree :lazytest/ns
  run-test--lazytest-ns
  [suite config]
  (let [suite (hooks/run-hooks config suite :pre-test-suite)]
    (report config (assoc suite :type :begin-test-ns))
    (run-befores suite)
    (let [results (->suite-result suite config :lazytest/ns)]
      (report config (-> suite
                       (assoc :type :end-test-ns)
                       (assoc :results results)))
      (run-afters suite)
      (hooks/run-hooks config results :post-test-suite))))

2026-03-18T17:24:24.225109Z

comparatively, pre reporters take the base object, and then post reporters take the base object plus a :results key, holding the results (which also holds the :source and :children)

2026-03-18T17:24:53.284779Z

so the two objects are going to be different on output, which i find ugly, but i'm not sure there's a better way to do it?

2026-03-18T17:31:09.799129Z

if i'd thought ahead, i might have changed the post- reporters to take the results object with its :source and :children directly instead of nesting it

2026-03-18T17:31:58.378839Z

but the symmetry seemed worthwhile when i first wrote them (probably mirroring clojure.test)

seancorfield 2026-03-18T18:09:28.518879Z

Just so I'm understanding: run-hooks with :pre-test-suite gets a suite hash map, but run-hooks with :post-test-suite gets a results hash map where the suite is under :source? But report gets the suite hash map in both cases (`:begin-test-ns` and :end-test-ns), but in the second case, it also has :results with the results object in it?

2026-03-18T18:21:25.835689Z

lol yes 😵‍💫

2026-03-18T18:39:57.872099Z

with report, the results object is the same object that's passed to run-hooks (so it has suite under :source), it's just that extra layering that bothers me

2026-03-18T18:40:56.361109Z

maybe this is just how it is and we're stuck with it lol

2026-03-18T18:42:48.484509Z

i'd like for the post- hooks to take the result object and either modify or return it. it's the simplest, most obvious way for a hook function to operate: it takes a result and returns a result, no nesting or destructuring required, no docs that say "you must update the :result object, any other changes will be discarded"

2026-03-18T19:12:08.827739Z

one way to thread this needle would be to assoc results onto the results itself, lol: results (assoc results :results results). then existing custom reporters wouldn't need to change (they're most likely only using :results), and now the signature of both reporters and hooks would be the same: :pre-/`:before-` gets the source hashmap, :post-/`:after-` gets the results with source hashmap under :source.

seancorfield 2026-03-18T19:21:36.153139Z

Would assoc'ing results into itself likely to cause a usability problem for folks debugging hooks, since the whole of results is then duplicated into itself?

seancorfield 2026-03-18T19:22:50.032529Z

What is the suite hash map? What keys does that have?

2026-03-18T19:26:37.800039Z

yeah, the size of these objects is incredibly unwieldy already, the run and ns objects hold a lot of stuff

2026-03-18T19:41:22.001249Z

I've defined suite as a record with (defrecord Suite [type doc source children context ns file line var metadata]) but it of course can hold arbitrary data as well

2026-03-18T19:47:46.988409Z

i think i will have to stick with what i have. in changing the reporter to use results as a base, a number of tests broke in non-obvious ways, and i suspect that there are other users of the current format I'm not acocunting for

2026-03-18T19:48:10.784319Z

the messiness will just have to exist, until at some point i change to v2, maybe with a whole new library name lol

👍🏻 1