Skip to content

Commit

Permalink
Fishtape 2 (#31)
Browse files Browse the repository at this point in the history
* Make test syntax compatible with fish_indent; #34 #27
* Run test files in parallel (not assertions, but files)
* Remove `--pipe` in favor of any userland solution like:
  `"fish -c "fishtape *.fish | tap-nyan"`
* Remove the built-in `test` array extensions
  • Loading branch information
jorgebucaran committed Feb 7, 2019
1 parent 29959e4 commit 1012452
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 950 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
examples
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
dist: trusty
sudo: required
before_install:
- sudo add-apt-repository -y ppa:fish-shell/release-2
- sudo add-apt-repository -y ppa:fish-shell/nightly-master
- sudo apt-get update
- sudo apt-get -y install fish
script:
- curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
- fish -c "fisher add jorgebucaran/fishtape .; fishtape test/*.fish"
- curl git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
- fish -c "fisher add . && fishtape test/*.fish"
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright © Jorge Bucaran <<https://jorgebucaran.com>>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
151 changes: 73 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,129 +1,124 @@
> ✋ Psst! Migrating from V1 to V2? Check the [migration guide](https://github.com/fisherman/fishtape/issues/36) and happy upgrading!
# Fishtape

[![Build Status][travis-badge]][travis-link]
[![Build Status](https://img.shields.io/travis/jorgebucaran/fishtape.svg)](https://travis-ci.org/jorgebucaran/fishtape)
[![Releases](https://img.shields.io/github/release/jorgebucaran/fishtape.svg?label=latest)](https://github.com/jorgebucaran/fishtape/releases)

Fishtape is a <a href=https://testanything.org title="Test Anything Protocol">TAP</a>-based test runner for the [fish shell](https://fishshell.com).

> ✋ Psst! Fishtape is currently being rewritten. Follow [this issue](https://github.com/fisherman/fishtape/issues/31) for updates and check back soon!
## Features

Fishtape is a [TAP] producing test runner for [fish]. It scans one or more *.fish* files and evaluates test blocks producing a TAP stream.
- Clean syntax derived from the [`test`](https://fishshell.com/docs/current/commands.html#test) builtin
- <a href=https://testanything.org title="Test Anything Protocol">TAP</a> output—easy to parse & human readable (see [reporting options](#reporting-options))
- Isolated test environment—tests run concurrently in their own sub-shells

## Install

With [fisher]:
With [Fisher](https://github.com/jorgebucaran/fisher) (recommended):

```fish
fisher add jorgebucaran/fishtape
```

## Usage
<details>
<summary>Not using a package manager?</summary>

### Writing Tests
---

Test files are *.fish* files with one or more test blocks. A test block consists of an optional description and any test expression supported by test(1).
Copy [`fishtape.fish`](fishtape.fish) to any directory on your function path.

```fish
test "current directory is home"
$HOME = $DIRNAME
end
set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
curl https://git.io/fishtape.fish --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/fishtape.fish
```

test "math still works"
42 -eq (math 41 + 1)
end
To uninstall, remove the file.

test "test is a builtin"
"test" = (builtin -n)
end
</details>

test "no odds are evens"
1 3 5 7 != (
for i in (seq $n)
if test (math $i%2) = 0
echo $i
end
end
)
end
```
### System Requirements

### Running Tests
- [fish](https://github.com/fish-shell/fish-shell) 2.0+

Fishtape reads any given files, or the standard input if no files are given, and converts test blocks into valid Fish syntax which is then evaluated, producing a TAP stream.
## Usage

```fish
fishtape path/to/tests/*.fish
```
Test files are `.fish` files with `@test` definitions. A test definition (or test case) consists of an optional description, followed by one or more operators and their arguments. You can use any operator supported by the [`test`](https://fishshell.com/docs/current/commands.html#test) builtin except for the `-a` and `-o` conditional operators.

## Setup and Teardown
```fish
@test "math works" (math 41 + 1) -eq 42
Include a setup and teardown method in your test file with code that must be run before and after every test.
@test "extract basename" (
string split -rm1 / /usr/local/bin/fish
)[-1] = "fish"
### `setup`
@test "test is a builtin" (
contains -- test (builtin -n)
) $status -eq 0
```

Run before each test in the current file. Use setup to load fixtures and/or set up your environment.
Run `fishtape` with one or more test files to run your tests.

```fish
set path $DIRNAME/$TESTNAME
fishtape tests/*.fish
```

function setup
mkdir -p $path
end
```diff
TAP version 13
ok 1 - math works
ok 2 - extract basename
ok 3 - test is a builtin

1..3
# pass 3
# ok
```

### `teardown`
Test files run in the background in a sub-shell while individual test cases run sequentially. Test output is buffered (delivered in batches) until all jobs are complete. If all the test cases pass, `fishtape` exits with status `0`—else, it exits with status `1`.

Run after each test in the current file. Use teardown to clean up loaded resources, etc.
Buffered output means we can't write to stdout or stderr without running into race conditions. To print a TAP message use the special `@mesg` function.

```fish
function teardown
rm -rf $path
end
@mesg "This message is approved by fish—the friendly interactive shell"
```

## Variables
### Setup and Teardown

The following variables are available inside a test file:
You can define special `setup` and `teardown` functions, which run before and after each test case, respectively. Use them to load fixtures, set up your environment, and clean up when you're done.

### `$FILENAME`

Path to the running script.

### `$DIRNAME`
```fish
function setup
set -g tmp (command mktemp -d /tmp/foo.XXXXX)
command mkdir -p $tmp
end
Directory name of the running script.
function teardown
command rm -rf $tmp
end
### `$TESTNAME`
@test "directory is empty" -z (
pushd $tmp
command ls -1 | command awk '{ ++i } END { print i }'
popd
)
```

Name of the running script.
### Special Variables

### `$TAP_VERSION`
The following variables are globally available for all test files:

TAP protocol version.
- `$filename` the name of the currently running test file

## Notes
## Reporting Options

### Line Buffered Output
TAP output is easy to parse for machines and still readable for humans. If you are looking for a more sophisticated reporting option, you can pipe `fishtape` to any TAP-compliant reporter, e.g. [tapjs/tap-mocha-reporter](https://github.com/tapjs/tap-mocha-reporter).

According to [fish-shell/#1396], redirections and pipes involving blocks are run serially, not in parallel. This causes fishtape to block the pipeline and buffer all of its output. To emit a line buffered stream use --pipe=*program*.
Redirections and pipes involving blocks are run serially in fish ([fish-shell/#1396](https://github.com/fish-shell/fish-shell/issues/1396)). This means we must run `fishtape` in a subshell for streaming support.

```fish
fishtape test.fish --pipe=tap-nyan
fish -c "fishtape test/*.fish" | tap-mocha-reporter nyan
```

### Tests

* Only one expression per test block is allowed. Use command substitutions to create complex test expressions.

* Each test file is wrapped in `begin; end` blocks under the hood to protect your local scope. In addition, global and universal variables are restored before each test.

* See [Awesome TAP] for a list of consumers / reporters, tools and other TAP resources.

[travis-link]: https://travis-ci.org/fisherman/fishtape
[travis-badge]: https://img.shields.io/travis/fisherman/fishtape.svg
[slack-link]: https://fisherman-wharf.herokuapp.com/
[slack-badge]: https://fisherman-wharf.herokuapp.com/badge.svg
## License

[TAP]: http://testanything.org/
[fish]: https://github.com/fish-shell/fish-shell
[Awesome TAP]: https://github.com/sindresorhus/awesome-tap
[fisherman]: http://github.com/fisherman/fisherman
[issues]: https://github.com/fisherman/fishtape/issues
[fish-shell/#1396]: https://github.com/fish-shell/fish-shell/issues/1396
[MIT](LICENSE.md)
5 changes: 0 additions & 5 deletions completions/fishtape.fish

This file was deleted.

Loading

0 comments on commit 1012452

Please sign in to comment.