Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yugui authored Jul 21, 2017
1 parent 619be21 commit aafc707
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Jsonnetunit is a unit test framework for [Jsonnet](http://jsonnet.org/).

`example_test.jsonnet`:
```jsonnet
local test = import "path/to/jsonnetunit/test.jsonnet";
local test = import "jsonnetunit/test.libsonnet";
test.suite({
testIdentity: {actual: 1, expect: 1},
Expand All @@ -24,14 +24,26 @@ test.suite({
})
```

Then, just evaluate your test file with `jsonnet`.
```console
$ jsonnet example_test.jsonnet
$ jsonnet -J path/to/jsonnetunit example_test.libsonnet
{
"verify": "Passed 3 test cases"
}
```

See `std_matchers_test.jsonnet` for more examples of other matchers.
On failure, it emits an error report and exits with non-zero status.
```console
$ jsonnet -J path/to/jsonnetunit example_test.jsonnet
RUNTIME ERROR: Failed 11/11 test cases:
testFoo: Expected 1 to be 2
testBar: Expected 1 to satisfy the function
testBaz: Expected 1 to satisfy the condition that the value is between 1 and 2
./jsonnetunit/test.libsonnet:40:13-25 object <anonymous>
During manifestation
```

See `jsonnet/test/std_matchers_test.jsonnet` for more examples of other matchers.

## How to install

Expand All @@ -50,7 +62,7 @@ $ git clone https://github.com/yugui/jsonnetunit.git
Test files must be `.jsonnet` files which manifestize a result of `test.suite` function.

```jsonnet
local test = import "path/to/jsonnetunit/test.jsonnet";
local test = import "path/to/jsonnetunit/test.libsonnet";
test.suite({
})
```
Expand Down Expand Up @@ -130,7 +142,7 @@ You can also define your own expectation matcher.

e.g.
```jsonnet
local setMatcher(actual, expected) = import "path/to/matcher.jsonnet" {
local setMatcher(actual, expected) = import "jsonnetunit/matcher.libsonnet" {
satisfied: std.set(actual) == std.set(expected),
positiveMessage: "Expected " + actual + " to be equal to " + expected + " as a set",
negativeMessage: "Expected " + actual + " not to be equal to " + expected + " as a set",
Expand Down Expand Up @@ -164,6 +176,30 @@ You can also define your own expectation matcher.
},
}
```
### Running with [Bazel](https://bazel.build/)
Use `jsonnet_test` rule.
* `WORKSPACE`:
```bzl
...
git_repository(
name = "com_github_yugui_jsonnetunit",
remote = "https://github.com/yugui/jsonnetunit.git",
tag = "0.0.2",
)
```

* `BUILD`:

```bzl
load("@com_github_yugui_jsonnetunit//jsonnetunit:jsonnetunit.bzl", "jsonnet_test")

jsonnet_test(
name = "your_test",
src = "your_test.jsonnet",
)
```

# Copyright

Expand Down

0 comments on commit aafc707

Please sign in to comment.