Class OrphanAssertionDetector

java.lang.Object
org.ek9lang.compiler.phase5.callgraph.OrphanAssertionDetector

public final class OrphanAssertionDetector extends Object
Detects assertion statements that are not reachable from any @Test program.

E81011: Orphan assertion - assertion not reachable from any @Test

Assertions (assert, assertThrows, assertDoesNotThrow) are meant for testing. An assertion that isn't reachable from any @Test program will never execute as part of a test, creating false confidence that the code is tested.

Common causes:

  • Forgot to write a @Test that calls the function with assertions
  • Refactored tests and left assertions behind
  • Helper function was removed from test call chain
  • Constructor Details

    • OrphanAssertionDetector

      public OrphanAssertionDetector(CallGraph callGraph, CallableErrorListenerLookup errorListenerLookup)
      Create a detector for orphan assertions.
      Parameters:
      callGraph - The call graph with assertion and reachability information
      errorListenerLookup - Function to get ErrorListener for emitting errors
  • Method Details

    • detectAndReport

      public List<String> detectAndReport()
      Detect all orphan assertions and emit E81011 errors.
      Returns:
      List of callable names containing orphan assertions (for reporting/testing)
    • detect

      public void detect(Consumer<CallableInfo> consumer)
      Alternative API for just detection without error emission. Useful for testing and analysis.
      Parameters:
      consumer - Callback for each orphan assertion callable found
    • getOrphanAssertions

      public Set<String> getOrphanAssertions()
      Get the set of orphan assertion callables. Delegates to CallGraph.getOrphanAssertions().
      Returns:
      Set of fully qualified names of callables with unreachable assertions