Configure failure reporting

Capture size and captureAll()

0.0.1

By default, CLI Assured captures the first 16 and last 16 lines of each output stream in memory. These are used in assertion failure messages to help diagnose problems.

Use capture(int maxHeadLines, int maxTailLines) to customize the number of head and tail lines to capture:

import org.assertj.core.api.Assertions;
import org.cliassured.CliAssured;
import org.cliassured.CommandResult;

CommandResult result = CliAssured
    .command("echo", "Line 1\nLine 2\nLine 3")
    .then()
        .stdout()
            // Capture at most 2 head and 2 tail lines
            .capture(2, 2)
    .execute()
    .assertSuccess();

Assertions.assertThat(result.stdout().lineCount()).isEqualTo(3);

Use captureAll() to capture the entire output in memory. This enables CommandResult.stdout().lines() and CommandResult.stdout().bytes() for post-execution access:

import org.assertj.core.api.Assertions;
import org.cliassured.CliAssured;
import org.cliassured.CommandResult;

CommandResult result = CliAssured
    .command("echo", "Line 1\nLine 2\nLine 3")
    .then()
        .stdout()
            // Capture all lines in memory
            .captureAll()
    .execute()
    .assertSuccess();

// All lines are available via lines()
Assertions.assertThat(result.stdout().lines())
    .containsExactly("Line 1", "Line 2", "Line 3");

captureAll() stores the entire output in memory. For commands producing large amounts of data, consider using redirect(OutputStream) instead.