Cheer.Test (Cheer v0.3.0)

Copy Markdown View Source

In-process test runner for CLI commands.

Invokes a command capturing stdout, stderr, and the return value, without spawning a subprocess. output is what the call wrote to stdout. error_output is what cheer itself wrote as diagnostics: usage errors, suggestions, the help printed after an error, and deprecation warnings. It goes to a device private to the call, so it holds nothing from other processes and is safe to assert on in async: true tests. What a command's own run/2 writes to :stderr is not included; capture that with ExUnit.CaptureIO.capture_io(:stderr, ...).

Usage

result = Cheer.Test.run(MyCommand, ["--port", "8080"])
assert result.return == {:ok, %{port: 8080}}
assert result.output == ""

result = Cheer.Test.run(MyCommand, ["--bogus"])
assert result.error_output =~ "unknown option"

Summary

Functions

Run a command with the given argv, capturing output and return value.

Types

t()

@type t() :: %Cheer.Test{error_output: String.t(), output: String.t(), return: term()}

Functions

run(command, argv, opts \\ [])

@spec run(module(), [String.t()], keyword()) :: t()

Run a command with the given argv, capturing output and return value.