E81011: assertion is not reachable from any @Test program

Category: E81xxx-E83xxx Test configuration, execution and coverage · Reported in phase: PRE_IR_CHECKS · Classification: ORPHAN_ASSERTION · All error codes

What went wrong

An assertion (assert, assertThrows, assertDoesNotThrow) exists in code that is not reachable from any @Test program ("orphan assertion").

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 809 (How does EK9 enforce test quality at compile time?)

How to fix it

  1. Add a @Test that calls this code
  2. Or remove orphan assertions if code no longer tested
  3. Or convert to 'require' for production validation

Rationale

Orphan assertions create false confidence - they look like tests but never run. EK9 detects unreachable assertions at compile time.

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E81011: assertion is not reachable from any @Test program

bad/dev/pricingTests.ek9

#!ek9
defines module error.e81011.bad.tests

  references
    error.e81011.bad::discounted

  defines function

    checkNeverNegative()
      -> price as Integer
      assert discounted(price, 100) >= 0

  defines program

    @Test
    TenPercentOff()
      assert discounted(200, 10) == 180

bad/pricing.ek9

#!ek9
defines module error.e81011.bad

  defines function

    discounted() as pure
      ->
        price as Integer
        percentOff as Integer
      <- reduced as Integer: price - price * percentOff / 100

Fixed: A @Test program calls the helper, so its assertions run

good/pricing.ek9

#!ek9
defines module error.e81011.good

  defines function

    discounted() as pure
      ->
        price as Integer
        percentOff as Integer
      <- reduced as Integer: price - price * percentOff / 100

good/dev/pricingTests.ek9

#!ek9
defines module error.e81011.good.tests

  references
    error.e81011.good::discounted

  defines function

    checkNeverNegative()
      -> price as Integer
      assert discounted(price, 100) >= 0

  defines program

    @Test
    TenPercentOff()
      assert discounted(200, 10) == 180

    @Test
    FullDiscountIsNeverNegative()
      checkNeverNegative(200)

Questions and answers

These Q&A entries show E81011 and its fix: