Skip to content

Commit

Permalink
Merge pull request #412 from jjdiazgarcia/fix/missing_function_pretty…
Browse files Browse the repository at this point in the history
…_formatter

Fix missing function in pretty formatter
  • Loading branch information
martin-schulze-vireso committed Mar 15, 2021
2 parents d038e67 + f5854d0 commit c076098
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ The format is based on [Keep a Changelog][kac] and this project adheres to

## [Unreleased]

### Fixed

* fix `bats_tap_stream_unknown: command not found` with pretty formatter, when
writing non compliant extended output (#412)

## [1.3.0] - 2021-03-08

### Added
Expand Down
10 changes: 5 additions & 5 deletions docs/source/docker-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ Receiving objects: 100% (1222/1222), 327.28 KiB | 1.70 MiB/s, done.
Resolving deltas: 100% (661/661), done.

$ cd bats-core/
$ docker build --tag bats:latest .
$ docker build --tag bats/bats:latest .
...
$ docker run -it bats:latest --formatter tap /opt/bats/test
$ docker run -it bats/bats:latest --formatter tap /opt/bats/test
```

To mount your tests into the container, first build the image as above. Then, for example with `bats`:
```bash
$ docker run -it -v "$PWD:/opt/bats" bats:latest /opt/bats/test
$ docker run -it -v "$PWD:/opt/bats" bats/bats:latest /opt/bats/test
```
This runs the `test/` directory from the bats-core repository inside the bats Docker container.

For test suites that are intended to run in isolation from the project (i.e. the tests do not depend on project files outside of the test directory), you can mount the test directory by itself and execute the tests like so:

```bash
$ docker run -it -v "$PWD/test:/test" bats:latest /test
$ docker run -it -v "$PWD/test:/test" bats/bats:latest /test
```

## Docker Gotchas
Expand All @@ -46,7 +46,7 @@ Relying on functionality provided by your environment (ssh keys or agent, instal
Docker operates on a principle of isolation, and bundles all dependencies required into the Docker image. These can be mounted in at runtime (for test files, configuration, etc). For binary dependencies it may be better to extend the base Docker image with further tools and files.

```dockerfile
FROM bats
FROM bats/bats

RUN \
apk \
Expand Down
6 changes: 5 additions & 1 deletion libexec/bats-core/bats-format-pretty
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ bats_tap_stream_begin() {
begin
flush
}

bats_tap_stream_ok() {
index="$1"
((++passed))
Expand Down Expand Up @@ -230,6 +230,10 @@ bats_tap_stream_suite() {
: #test_file="$1"
}

bats_tap_stream_unknown() { # <full line>
printf "%s\n" "$1"
}

bats_parse_internal_extended_tap

summary
26 changes: 26 additions & 0 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -734,4 +734,30 @@ END_OF_ERR_MSG

# should also find preprocessed files!
[ $(find "$TEST_TMPDIR" -name '*.src' | wc -l) -eq 1 ]
}

@test "All formatters (except cat) implement the callback interface" {
cd "$BATS_ROOT/libexec/bats-core/"
for formatter in bats-format-*; do
# the cat formatter is not expected to implement this interface
if [[ "$formatter" == *"bats-format-cat" ]]; then
continue
fi
tested_at_least_one_formatter=1
echo "Formatter: ${formatter}"
# the replay should be possible without errors
"$formatter" >/dev/null <<EOF
1..1
suite "$BATS_FIXTURE_ROOT/failing.bats"
begin 1 test_a_failing_test
not ok 1 a failing test
# (in test file test/fixtures/bats/failing.bats, line 4)
# \`eval "( exit ${STATUS:-1} )"' failed
begin 2 test_a_successful_test
ok 2 a succesful test
unknown line
EOF
done

[[ -n "$tested_at_least_one_formatter" ]]
}

0 comments on commit c076098

Please sign in to comment.