Home / Docs / Diagnostics

U3014: Host capability used in an example

Release v0.4.0

Examples, the tests written test from edition 0.3 and example in editions 0.1 and 0.2 (ADR 0105), are deterministic, so they never reach the host: every capability that the do line needs comes from a given line (spec/08 §2 rule 1). U3014 reports a do line that needs a host capability (Console, Clock, Env, Files or Keys, from edition 0.2 also Http, and from edition 0.4 HttpServer, spec/14 §3) that no given line binds. User code may write a handler for a host capability and install it with given.

The repair at a glance

diff
  module demo

+ handler quiet() for Console
+   op print(line) = unit
+
  pub greet(name: Text) -> Unit
    uses @console: Console[print]
  =
    @console.print("hello {name}")

  example "a greeting"
+   given @console = quiet()
    do greet("Ana")
-   expect true
+   expect performed @console.print

Failing example

una
module demo

pub greet(name: Text) -> Unit
  uses @console: Console[print]
=
  @console.print("hello {name}")

example "a greeting"
  do greet("Ana")
  expect true

Fixed example

una
module demo

handler quiet() for Console
  op print(line) = unit

pub greet(name: Text) -> Unit
  uses @console: Console[print]
=
  @console.print("hello {name}")

example "a greeting"
  given @console = quiet()
  do greet("Ana")
  expect performed @console.print