Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
Beginnings of a readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Dec 29, 2011
1 parent 382c540 commit 20b54ec
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Bats: the Bash Automated Testing System

Bats is a [TAP](http://testanything.org/)-compliant testing framework
for Bash. It provides a simple way to verify that the UNIX programs
you write behave as expected.

A Bats test file is a Bash script with special syntax for defining

This comment has been minimized.

Copy link
@sstephenson

sstephenson Dec 11, 2015

Author Owner

This doesn’t say it’s a Bash script, full stop. It says it’s a Bash script with special syntax for defining test cases.

This comment has been minimized.

Copy link
@sstephenson

sstephenson Dec 12, 2015

Author Owner

@svnpenn Of course you wouldn't call a Perl script "a Bash script with special syntax," because Perl isn't a superset of Bash.

This isn't the right place to debate semantics, and I don't believe this paragraph is confusing or inaccurate. But please feel free to rewrite it according to your standards and open an issue or pull request for further discussion.

This comment has been minimized.

Copy link
@ztombol

ztombol Dec 12, 2015

@svnpenn The Bats syntax extends the Bash syntax with the @test keyword. You can do anything in Bats that Bash allows. On the other hand, Perl and Bash has nothing in common.

This comment has been minimized.

Copy link
@ztombol

ztombol Dec 13, 2015

@svnpenn I don't think contributing to Bats is a waste of time. It's widely used and there are many exciting pull request in the works, e.g. #128, #123, #122, #110 just to mention a few. Just take a look!

test cases. Under the hood, each test case is just a function with a
description.

```bash
#!/usr/bin/env bats

@test "addition using bc" {
result="$(echo 2+2 | bc)"
[ "$result" -eq 4 ]
}

@test "addition using dc" {
result="$(echo 2 2+p | dc)"
[ "$result" -eq 4 ]
}
```

Test cases consist of standard shell commands. Bats makes use of
Bash's `errexit` (`set -e`) option when running test cases. If every
command in the test case exits with a `0` status code (success), the
test passes. In this way, each line is an assertion of truth.

To run your tests, invoke the `bats` interpreter with a path to a test
file. The file's test cases are run sequentially and in isolation, and
the results are written to standard output in human-readable TAP
format. If all the test cases pass, `bats` exits with a `0` status
code. If there is a failure, `bats` exits with a `1` status code.

$ bats addition.bats
1..2
ok 1 addition using bc
ok 2 addition using dc
$ echo $?
0

You can also define special `setup` and `teardown` functions which run
before and after each test case, respectively. Use these to load
fixtures, set up your environment, and clean up when you're done.

Bats is most useful when testing software written in Bash, but you can
use it to test any UNIX program.

0 comments on commit 20b54ec

Please sign in to comment.