Skip to content

Commit

Permalink
Feature: migrate tool (#5)
Browse files Browse the repository at this point in the history
* feature: new string matcher

* feature: migrate tool

* fix: remove dependency to slices package
  • Loading branch information
halimath authored Nov 20, 2023
1 parent 70eb194 commit b599f40
Show file tree
Hide file tree
Showing 8 changed files with 1,490 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Expectation | Type constraints | Description
`is.StringContaining` | `string` | Expects the given value to be a string containing a given substring
`is.StringHavingPrefix` | `string` | Expects the given value to be a string having a given prefix
`is.StringHavingSuffix` | `string` | Expects the given value to be a string having a given suffix
`is.EqualToStringByLines` | `string` | Similar to EqualTo used on two strings but reports differences on a line-by-line basis

### Deep equality

Expand Down
58 changes: 58 additions & 0 deletions cmd/expect-migrate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# expect-migrate

`expect-migrate` is a small command line tool to upgrade your go test source files
using `github.com/halimath/[email protected]` to `github.com/halimath/expect@latest`. The tool rewrites
go source files that in a lot of cases directly compile and run. In some cases minor work by the developer
is needed.

# Installation

```shell
go install github.com/halimath/expect/cmd/expect-migrate@main
```

# Usage

Given an input file `some_test.go`

```go
package some

import (
"testing"
. "github.com/halimath/expect-go"
)

func TestSomething(t *testing.T) {
var err error
s := produceValue()

EnsureThat(t, err).Is(NoError())
ExpectThat(t, s).Is(Equal("foo"))
}
```

applying

```shell
expect-migrate some_test.go
```

will rewrite the file to

```go
package some

import (
"testing"
"github.com/halimath/expect"
"github.com/halimath/expect/is"
)

func TestSomething(t *testing.T) {
var err error
s := produceValue()
expect.That(t, expect.FailNow(is.NoError(err)))
expect.That(t, is.EqualTo(s, "foo"))
}
```
Loading

0 comments on commit b599f40

Please sign in to comment.