Skip to content

Making hegel-java usable as a library #12

Closed

Description

@aphyr

I'd like to write a Clojure client that uses this library, but there are some parts that make that hard.

  1. Hegel used to return a map that told you if the test passed, how many cases were executed, number of cases, how many were interesting, whether health checks failed, etc. I can't figure out how to get that information any more. Could we have a structure returned by Hegel.test()? Bonus points if it includes (e.g.) a map of labels to generated values for the minimal failing case(s).

  2. It's not clear what the Consumer passed to test() should do. I'm guessing that any non-exceptional return value is a valid test case. Is it OK to throw any exception? Any throwable (e.g. InterruptedException?) Do the exceptions specifically need to be JUnit ones? Is there special JUnit state that Hegel relies on, or is it OK to construct and throw the exceptions ourselves?

  3. Does Hegel do anything with the fields of the assertions thrown, or is it just a pass/fail signal?

  4. Hegel takes over printing to stderr/stdout, which fights with other logging/printing and does not play well with concurrency. Having a return value for TestCase might fix this, but you might also consider having a Reporter interface with callbacks for various Hegel events.

  5. It would be very helpful to have something like testCase.isFinal(), so you could do your own debugging/logging on the final cases.

  6. How should we signal spans?

Activity

  1. DRMacIver commented on Aug 13, 2026

    @DRMacIver
    Member

    Hi @aphyr! Sorry for the delay in getting back to you, was on holiday and somewhat overwhelmed with notifications when I got back and missed this until just now.

    Definitely agreed that hegel-java should be usable as a library. I think probably rather than trying to make the current hegel-java frontend usable in that way, we want a dev.hegel.lowlevel or something like that which exposes something closer to the libhegel C API (with whatever Java niceties are required) for people to use from other JVM libraries, as I think there's significant tension between providing a good frontend and providing a good library for people to build frontends. This should resolve (1), (4), (5), (6) for you.

    1. Yes right now any throwable is marked as interesting. There's nothing JUnit specific here, there's some optional JUnit integration, but Hegel works without it. Possibly we should be a bit more fine grained about this, but I'm not 100% sure what the right semantics are here.
    2. It looks at type and line number thrown by to distinguish exceptions that probably come from different types of bug.
  2. aphyr commented on Aug 13, 2026

    @aphyr
    Author

    Oh that's tremendously helpful, thank you. And no rush, this is on my back burner too.

    I don't know if you need to drop super far down--the generator library felt very nicely designed and was straightforward to adapt, (1) and (5) would be API compatible with the current Hegel.test(), and (4) could be provided as an option. I assume there's more cool stuff down in libhegel that might be nice, but those three things are, I think, the only blockers for hegel-clj. :-)

  3. Liam-DeVoe commented on Aug 14, 2026

    @Liam-DeVoe
    Member

    (added hegel-clj to the website! hegeldev/website#94)

  4. aphyr commented on Aug 17, 2026

    @aphyr
    Author

    Er, just to be clear, hegel-clj doesn't really work right now--I'll need at least 1 and 4 to get that working. Might want to hold off on linking to it.

  5. Liam-DeVoe commented on Aug 17, 2026

    @Liam-DeVoe
    Member

    ah ok! I'll remove it, happy to add it back whenever you feel it's ready

  6. aphyr commented on Aug 17, 2026

    @aphyr
    Author

    Yeah, just let me know when y'all have return values and an option to control the logging, and I'll get back to work on it. I think those are the big blockers.

  7. linked a pull request that will close this issueHegel lowlevel #21on Sep 16, 2026
  8. aphyr commented on Sep 17, 2026

    @aphyr
    Author

    Oh very cool, thank you! I've got a bunch of work to unwind at the moment, but I would like to come back to this and try it out soon. Keep hitting bugs where I think Hegel's shrinking would really help. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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