Fishtape Documentation

repository·main·Indexed 18 days ago

https://github.com/jorgebucaran/fishtape

A pure Fish shell test runner compliant with the Test Anything Protocol (TAP). It allows developers to test Fish scripts, functions, and plugins using the @test function for expressions and @echo for TAP comments.

Tokens
489
Snippets
5
Records
5
Agent score
14%

What's inside Fishtape

  1. Use alternative reporters via TAP piping

    main

    Fishtape outputs the Test Anything Protocol (TAP) by default. You can pipe this output into other TAP-compliant reporters for fancier visualizations.

    Example (piping to tnyan):

    $ fishtape test/* | tnyan
    $ fishtape test/* | tnyan
  2. Handle multiline output in tests

    main

    When testing multiline output, you can either collapse newlines using echo or collect the input into a single argument using string collect.

    Using echo:

    @test "first six evens" (echo (seq 2 2 12)) = "2 4 6 8 10 12"

    Using string collect:

    @test "one two three" (seq 3 | string collect) = "1\n2\n3"
    @test "first six evens" (echo (seq 2 2 12)) = "2 4 6 8 10 12"
    
    @test "one two three" (seq 3 | string collect) = "1
    2
    3"
  3. Use @echo for TAP comments

    main

    If you need to write to stdout while tests are running without interfering with the TAP stream, use the @echo function. It is equivalent to echo "# $argv", which prints a valid TAP comment.

    @echo -- strings --
    @echo -- strings --
  4. Write tests using the @test function

    main

    Tests are defined using the @test function. Each test consists of a description followed by a standard Fish test expression.

    Syntax: @test <description> [<actual>] <operator> <expected>

    Important Notes:

    • Each test file runs in its own isolated shell environment.
    • Operators to combine expressions (like -a or -o) are not currently supported.
    • For testing command exit statuses, use command substitution and ensure you suppress stdout to avoid cluttering the expression.

    Example:

    @test "has a config.fish file" -e ~/.config/fish/config.fish
    
    @test "the ultimate question" (math "6 * 7") -eq 42
    
    @test "got root?" $USER = root
    
    @test "repo is clean" (git diff-index --quiet @) $status -eq 0
    @test <description> [<actual>] <operator> <expected