---
title: "U3015: `std.testing` used outside a handler or example"
url: https://una-lang.org/en/docs/errors/U3015/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U3015.md
---

# U3015: `std.testing` used outside a handler or example

A function of `std.testing` is used outside handler operation bodies and the lines of a test.

## Why Una rejects it

The functions of `std.testing`, such as `fake_hash`, produce fake values for tests. They are usable only inside handler operation bodies and the lines of a test, an `example` in editions 0.1 and 0.2 and a `test` in edition 0.3 (`spec/14 §4`, ADR 0105), so production code never depends on them.

- Importing `std.testing` is allowed. U3015 reports a call of, or a reference to, one of its functions elsewhere.
- A handler that uses `std.testing` is installed only by `given` lines of examples: installing it with a `with` binding is U3015 at the binding.
- A function of `std.testing` used as a value, not called, is U3015 everywhere (ADR 0043).

## How to fix it

Move the fake into a handler, and install the handler in the example.

## The repair at a glance

```diff
  module demo

  import std.testing (fake_hash)

- pub digest(seed: Int) -> internal Hashed = fake_hash(seed)
+ capability Hasher
+   op hash(seed: Int) -> internal Hashed
+
+ handler fake() for Hasher
+   op hash(seed) = fake_hash(seed)
+
+ pub digest(seed: Int) -> internal Hashed
+   uses @hasher: Hasher[hash]
+ =
+   @hasher.hash(seed)
+
+ example "a digest"
+   given @hasher = fake()
+   do digest(1)
+   expect result == fake_hash(1)
```

## Failing example

```una
module demo

import std.testing (fake_hash)

pub digest(seed: Int) -> internal Hashed = fake_hash(seed)
```

## Fixed example

```una
module demo

import std.testing (fake_hash)

capability Hasher
  op hash(seed: Int) -> internal Hashed

handler fake() for Hasher
  op hash(seed) = fake_hash(seed)

pub digest(seed: Int) -> internal Hashed
  uses @hasher: Hasher[hash]
=
  @hasher.hash(seed)

example "a digest"
  given @hasher = fake()
  do digest(1)
  expect result == fake_hash(1)
```
