• Stars
    star
    340
  • Rank 119,989 (Top 3 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

100% pure-Fish test runner

Fishtape

100% pure-Fish test runner.

Fishtape is a Test Anything Protocol compliant test runner for Fish. Use it to test anything: scripts, functions, plugins without ever leaving your favorite shell. Here's the first example to get you started:

@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

Now put that in a fish file and run it with fishtape installed. Behold, the TAP stream!

$ fishtape example.fish
TAP version 13
ok 1 has a config.fish file
ok 2 the ultimate question
not ok 3 got root?
  ---
    operator: =
    expected: root
    actual: jb
    at: ~/fishtape/tests/example.fish:5
  ...

1..3
# pass 2
# fail 1

See reporting options for alternatives to TAP output.

Each test file runs inside its own shell, so you can modify the global environment without cluttering your session or breaking other tests. If all the tests pass, fishtape exits with 0 or 1 otherwise.

Installation

Install with Fisher:

fisher install jorgebucaran/fishtape

Writing Tests

Tests are defined with the @test function. Each test begins with a description, followed by a typical test expression. Refer to the test builtin documentation for operators and usage details.

@test description [actual] operator expected

Operators to combine expressions are not currently supported: -a, -o.

Sometimes you need to test the exit status of running one or more commands and for that, you use command substitutions. Just make sure to suppress stdout to avoid cluttering your test expression.

@test "repo is clean" (git diff-index --quiet @) $status -eq 0

Often you have work that needs to happen before and after tests run like preparing the environment and cleaning up after you're done. The best way to do this is directly in your test file.

set temp (mktemp -d)

cd $temp

@test "a regular file" (touch file) -f file
@test "nothing to see here" -z (read < file)

rm -rf $temp

When comparing multiline output you usually have two options, collapse newlines using echo or collect your input into a single argument with string collect. It's your call.

@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"

If you want to write to stdout while tests are running, use the @echo function. It's equivalent to echo "# $argv", which prints a TAP comment.

@echo -- strings --

Reporting Options

If you're looking for something fancier than plaintext, here's a list of reporters that you can pipe TAP into.

$ fishtape test/* | tnyan
 8   -_-_-_-__,------,
 0   -_-_-_-__|  /\_/\
 0   -_-_-_-_~|_( ^ .^)
     -_-_-_-_ ""  ""
  Pass!

License

MIT

More Repositories

1

hyperapp

1kB-ish JavaScript framework for building hypertext applications
JavaScript
19,021
star
2

fisher

A plugin manager for Fish
Shell
7,219
star
3

awsm.fish

A curation of prompts, plugins & other Fish treasures πŸšπŸ’Ž
3,819
star
4

cookbook.fish

From Shell to Plate: Savor the Zest of Fish 🦞
1,933
star
5

nvm.fish

The Node.js version manager you'll adore, crafted just for Fish
Shell
1,890
star
6

colorette

🌈Easily set your terminal text color & styles
JavaScript
1,573
star
7

superfine

Absolutely minimal view layer for building web interfaces
JavaScript
1,562
star
8

classcat

Build a class attribute string quickly
JavaScript
901
star
9

getopts

Node.js CLI options parser
JavaScript
634
star
10

hydro

Ultra-pure, lag-free prompt with async Git statusβ€”just for Fish
Shell
559
star
11

hyperawesome

A curated list of awesome projects built with Hyperapp + more
490
star
12

twist

Declarative JavaScript Testing
JavaScript
378
star
13

replay.fish

Run Bash commands, replay changes in Fish 🍀
Shell
370
star
14

spark.fish

β–β–‚β–„β–†β–‡β–ˆβ–‡β–†β–„β–‚β–
Shell
322
star
15

autopair.fish

Auto-complete matching pairs in the Fish command line
Shell
316
star
16

hyperapp-router

Declarative routing for Hyperapp V1 using the History API.
JavaScript
257
star
17

getopts.fish

Parse CLI options in Fish
Shell
214
star
18

gitio.fish

Create a custom git.io URL
Shell
88
star
19

hyperapp-html

Html helper functions for Hyperapp V1
JavaScript
81
star
20

pyenv

Pyenv support plugin for fish-shell
Shell
62
star
21

humantime.fish

Turn milliseconds into a human-readable string in Fish
Shell
20
star
22

.github

My health files
1
star
23

jorgebucaran.github.io

HTML
1
star