Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: migrate tool #5

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading