Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Outcome

mattt edited this page Jan 8, 2021 · 2 revisions

Outcome

The outcome of running a test.

public struct Outcome

Properties

ok

Whether the test passed or failed.

let ok: Bool

From the TAP v13 specification:

• ok or not ok

This tells whether the test point passed or failed. It must be at the beginning of the line. /^not ok/ indicates a failed test point. /^ok/ is a successful test point. This is the only mandatory part of the line. Note that unlike the Directives below, ok and not ok are case-sensitive.

description

A description of the tested behavior.

let description: String?

From the TAP v13 specification:

• Description

Any text after the test number but before a # is the description of the test point.

ok 42 this is the description of the test

Descriptions should not begin with a digit so that they are not confused with the test point number. The harness may do whatever it wants with the description.

directive

A directive for how to interpret a test outcome.

let directive: Directive?

From the TAP v13 specification:

• Directive

The test point may include a directive, following a hash on the test line. There are currently two directives allowed: TODO and SKIP.

metadata

Additional information about a test, such as its source location (file / line) or the actual and expected results.

let metadata: [String: Any]?

Test outcome metadata is encoded as YAML.

From the TAP v13 specification:

YAML blocks

If the test line is immediately followed by an indented block beginning with /^\s+---/ and ending with /^\s+.../ that block will be interpreted as an inline YAML document. The YAML encodes a data structure that provides more detailed information about the preceding test. The YAML document is indented to make it visually distinct from the surrounding test results and to make it easier for the parser to recover if the trailing ‘…’ terminator is missing. For example:

not ok 3 Resolve address

message: "Failed with error 'hostname peebles.example.com not found'" severity: fail data: got: hostname: 'peebles.example.com' address: ~ expected: hostname: 'peebles.example.com' address: '85.193.201.85' ...

Methods

success(_:directive:metadata:)

Creates a successful test outcome.

public static func success(_ description: String? = nil, directive: Directive? = nil, metadata: [String: Any]? = nil) -> Outcome

Parameters

  • description: A description of the tested behavior. nil by default.
  • directive: A directive for how to interpret a test outcome. nil by default.
  • metadata: Additional information about a test. nil by default.

Returns

A successful test outcome.

failure(_:directive:metadata:)

Creates an unsuccessful test outcome.

public static func failure(_ description: String? = nil, directive: Directive? = nil, metadata: [String: Any]? = nil) -> Outcome

Parameters

  • description: A description of the tested behavior. nil by default.
  • directive: A directive for how to interpret a test outcome. nil by default.
  • metadata: Additional information about a test. nil by default.

Returns

An unsuccessful test outcome.