Skip to content

Commit

Permalink
Merge pull request #63 from maxatome/fix-T
Browse files Browse the repository at this point in the history
Fix *T
  • Loading branch information
maxatome committed Jul 7, 2019
2 parents a7d9a8e + f6dec38 commit ff0ad83
Show file tree
Hide file tree
Showing 40 changed files with 954 additions and 142 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go-testdeep

- [Latest news](#latest-news)
- [Synopsis](#synopsis)
- [Godoc table of contents](doc/toc.md#godoc-table-of-contents)
- [Installation](#installation)
- [Presentation](#presentation)
- [Available operators](#available-operators)
Expand All @@ -28,6 +29,15 @@ go-testdeep

## Latest news

- 2019/07/07: multiple changes occurred:
- `*T` type now implements `TestingFT`,
- add [`UseEqual` feature](https://godoc.org/github.com/maxatome/go-testdeep#T.UseEqual)
aka. delegates comparison to `Equal()` method of object,
- [`tdhttp.NewRequest()`](https://godoc.org/github.com/maxatome/go-testdeep/helpers/tdhttp#NewRequest),
[`tdhttp.NewJSONRequest()`](https://godoc.org/github.com/maxatome/go-testdeep/helpers/tdhttp#NewJSONRequest)
and
[`tdhttp.NewXMLRequest()`](https://godoc.org/github.com/maxatome/go-testdeep/helpers/tdhttp#NewXMLRequest)
now accept headers definition,
- 2019/05/01: new [`Keys`] & [`Values`] operators (and their friends
[`CmpKeys`](https://godoc.org/github.com/maxatome/go-testdeep#CmpKeys),
[`CmpValues`](https://godoc.org/github.com/maxatome/go-testdeep#CmpValues),
Expand All @@ -41,8 +51,6 @@ go-testdeep
and [`T.CmpDeeply`](https://godoc.org/github.com/maxatome/go-testdeep#T.CmpDeeply);
- 2019/01/13: test failures output is now colored by default. See
[Environment variables](#environment-variables) to configure it;
- 2019/01/07: introducing TestDeep helpers. First one is
[`tdhttp` or HTTP API testing helper](#tdhttp-or-http-api-testing-helper);
- see [commits history](https://github.com/maxatome/go-testdeep/commits/master)
for other/older changes.

Expand Down Expand Up @@ -201,6 +209,8 @@ func TestCreateRecord(tt *testing.T) {
}
```

See [godoc table of contents](doc/toc.md#godoc-table-of-contents) for details.


## Installation

Expand Down Expand Up @@ -369,6 +379,8 @@ func TestCreateRecord(tt *testing.T) {
}
```

See [godoc table of contents](doc/toc.md#godoc-table-of-contents) for details.


## Available operators

Expand Down
18 changes: 15 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ type ContextConfig struct {
// will be dumped.
MaxErrors int
// FailureIsFatal allows to Fatal() (instead of Error()) when a test
// fails. Using *testing.T instance as
// t.TestingFT value, FailNow() is called behind the scenes when
// Fatal() is called. See testing documentation for details.
// fails. Using *testing.T instance as t.TestingFT value, FailNow()
// is called behind the scenes when Fatal() is called. See testing
// documentation for details.
FailureIsFatal bool
// UseEqual allows to use the Equal method on got (if it exists) or
// on any of its component to compare got and expected values.
//
// The signature of the Equal method should be:
// (A) Equal(B) bool
// with B assignable to A.
//
// See time.Time as an example of accepted Equal() method.
UseEqual bool
}

const (
Expand All @@ -66,6 +75,7 @@ var DefaultContextConfig = ContextConfig{
RootName: contextDefaultRootName,
MaxErrors: getMaxErrorsFromEnv(),
FailureIsFatal: false,
UseEqual: false,
}

func (c *ContextConfig) sanitize() {
Expand Down Expand Up @@ -93,6 +103,7 @@ func newContextWithConfig(config ContextConfig) (ctx ctxerr.Context) {
Visited: visited.NewVisited(),
MaxErrors: config.MaxErrors,
FailureIsFatal: config.FailureIsFatal,
UseEqual: config.UseEqual,
}

ctx.InitErrors()
Expand All @@ -104,5 +115,6 @@ func newBooleanContext() ctxerr.Context {
return ctxerr.Context{
Visited: visited.NewVisited(),
BooleanError: true,
UseEqual: DefaultContextConfig.UseEqual,
}
}
13 changes: 13 additions & 0 deletions doc/FAQ.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# FAQ

- [Table of contents for all these functions/methods?](#table-of-contents-for-all-these-functionsmethods)
- [How to mix strict requirements and simple assertions?](#how-to-mix-strict-requirements-and-simple-assertions)
- [How to test `io.Reader` contents, like `http.Response.Body` for example?](#how-to-test-ioreader-contents-like-httpresponsebody-for-example)
- [OK, but I prefer comparing `string`s instead of `byte`s](#ok-but-I-prefer-comparing-strings-instead-of-bytes)
Expand All @@ -10,6 +11,11 @@
- [How to add a new operator?](#how-to-add-a-new-operator)


## Table of contents for all these functions/methods?

Of course! See the [Godoc table of contents](toc.md#godoc-table-of-contents).


## How to mix strict requirements and simple assertions?

```golang
Expand Down Expand Up @@ -323,6 +329,13 @@ You want to add a new `FooBar` operator.
small description, respecting the alphabetical order;
- in the [Operators vs go types](../README.md#operators-vs-go-types)
matrix, still respecting the alphabetical order.
- [ ] in [`toc.md#godoc-table-of-contents`](toc.md#godoc-table-of-contents),
add this new new `FooBar` operator:
- in [Main shortcut functions](toc.md#main-shortcut-functions);
- in [Shortcut methods of `*testdeep.T`](toc.md#shortcut-methods-of-testdeep-t);
- in [`Testdeep` operators](toc.md#testdeep-operators), a simple copy
of the line inserted in [Available operators](../README.md#available-operators)
and its corresponding link of course.

Each time you change `example_test.go`, re-run `./tools/gen_funcs.pl .`
to update corresponding `CmpFooBar` & `T.FooBar` examples.
Expand Down
Binary file modified doc/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ff0ad83

Please sign in to comment.