---
title: "17.7 Testing it"
url: https://una-lang.org/en/learn/information-flow/testing-it/
release: v0.4.0
edition: "0.2"
---

# 17.7 Testing it

## 17.7.1 Examples of the policy

The examples are those of [section 12.6](https://una-lang.org/en/learn/capabilities/testing-it/#s12-6), with one change: the first one expects the masked address, `r***@example.invalid`, which is what `notify` now returns. Two more examples, at the end of the file, test the policy itself:

```una include="day-to-day/src/notices.una#L152-L158" title="day-to-day/src/notices.una" caption="the policy's examples"
example "the log shows the first letter and the domain of an address"
  do masked_email("tomas@example.invalid")
  expect result == "t***@example.invalid"

example "an address the mask cannot read is hidden"
  do masked_email("no address")
  expect result == "(hidden)"
```

A policy can be called like a function, so its examples need no fakes. Test the release the way a reviewer would read it: what an ordinary value becomes, and what an unexpected one becomes. A mask that showed a whole malformed address would pass the type checker, since labels are not checked inside `via`, so this example is the check that it does not.

## 17.7.2 Examples can observe a secret

An `expect` line compares a value whatever its label, and a `do` line is checked like ordinary code: an example can observe a secret, but cannot send it anywhere the program itself could not ([Examples are not sinks](https://una-lang.org/en/learn/information-flow/sinks-where-labeled-data-may-go/#examples-are-not-sinks)). So chapter 12's example of `notice` still passes: its result is now a `secret[PII] Text`, and its `expect` line compares it with the text of the notice.

## 17.7.3 The failure paths and their fakes

The examples of the failure paths are chapter 12's, with its fakes: `directory_down` for the directory that does not answer, and `mail_down`. The examples of `UnknownCustomer`, `OptedOut` and `DirectoryDown` install `mail_down` on purpose, as [A failure that comes first](https://una-lang.org/en/learn/capabilities/testing-it/#a-failure-that-comes-first) explains: had `notify` sent any mail before it failed, the example would see `MailDown`. Labels do not alter which paths exist or how a fake reaches them. ([Chapter 14](https://una-lang.org/en/learn/testing/fakes-given-expect-performed-and-expect-not-performed/#s14-3) gives a more direct way to say that no mail went out, `expect not performed`; this chapter keeps chapter 12's examples, so that only the labels change.) The fakes `outbox` and `mail_down` are handlers of `Mailer`, which now accepts `secret[PII]`. They pass the check because they do nothing with what they receive. A fake mail service that printed each message, as `printed` in [chapter 12](https://una-lang.org/en/learn/capabilities/your-own-capabilities-and-handlers/#s12-3) did, would be U4003: what it prints could reveal the notice ([A handler is checked for its most sensitive caller](https://una-lang.org/en/learn/information-flow/sinks-where-labeled-data-may-go/#a-handler-is-checked-for-its-most-sensitive-caller)).

## 17.7.4 Running the examples

`una test .` prints:

```text include="day-to-day/expected/commands/test.txt#L2-L12"
example notices "a customer who wants notices gets one" ... ok
example notices "an unknown customer is rejected before any mail is sent" ... ok
example notices "a customer who asked for no notices is rejected before any mail is sent" ... ok
example notices "a directory that does not answer is DirectoryDown, before any mail is sent" ... ok
example notices "a mail service that does not answer is MailDown" ... ok
example notices "the notice names the customer, the order and the carrier" ... ok
example notices "a skipped shipment says why in the log" ... ok
example notices "the log shows the first letter and the domain of an address" ... ok
example notices "an address the mask cannot read is hidden" ... ok

9 examples: 9 passed, 0 failed
```
