Skip to content

Commit

Permalink
refactor!: rename dotimport -> EF (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmzane authored Sep 13, 2023
1 parent 57e2293 commit 24e6853
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions dotimport/alias.go → EF/alias.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package dotimport provides type aliases for the parent [assert] package.
// Package EF provides type aliases for the parent [assert] package.
// It is intended to be dot-imported so that [E] and [F] can be used as local types.
package dotimport
package EF

import "go-simpler.org/assert"

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ There is also a special tool to do this automatically:
just add the following directive to any `.go` file and run `go generate ./...`:

```go
//go:generate go run -tags=copier go-simpler.org/assert/cmd/copier .
//go:generate go run -tags=copier go-simpler.org/assert/cmd/copier@latest .
```

See the `cmd/copier` documentation for details.

## 📋 Usage

The `dotimport` subpackage should be dot-imported so that `E` and `F` can be used as local types:
The `EF` subpackage should be dot-imported so that `E` and `F` can be used as local types:

```go
"go-simpler.org/assert"
. "go-simpler.org/assert/dotimport"
. "go-simpler.org/assert/EF"
```

Optional format and arguments can be provided to any assertion to customize the error message:
Expand Down
2 changes: 1 addition & 1 deletion assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"go-simpler.org/assert"
. "go-simpler.org/assert/dotimport"
. "go-simpler.org/assert/EF"
)

func TestEqual(t *testing.T) {
Expand Down
11 changes: 5 additions & 6 deletions cmd/copier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// Copier is a convenience tool that copies the assertions into a project,
// so that they can be used without introducing a direct dependency.
//
// Add the following directive to any .go file in the root of your project and run `go generate ./...`:
// Add the following directive to any .go file and run `go generate ./...`:
//
// go:generate go run -tags=copier go-simpler.org/assert/cmd/copier <path/to/pkg>
// go:generate go run -tags=copier go-simpler.org/assert/cmd/copier@latest <path/to/pkg>
//
// Where <path/to/pkg> is the location where you want to put the generated package,
// e.g. `.` for the project root (hint: for libraries you may want to put it in `internal`).
Expand Down Expand Up @@ -40,7 +40,7 @@ func run() error {
}

path := filepath.Join(os.Args[1], "assert")
fullpath := filepath.Join(path, "dotimport")
fullpath := filepath.Join(path, "EF")

if err := os.MkdirAll(fullpath, 0755); err != nil && !errors.Is(err, os.ErrExist) {
return err
Expand All @@ -54,13 +54,12 @@ func run() error {
importPath = filepath.Join(moduleName, path)
}

// update the import in the `dotimport/alias.go` file.
supportFile := strings.Replace(assert.SupportFile, "go-simpler.org/assert", importPath, 1)
aliasFile := strings.Replace(assert.AliasFile, "go-simpler.org/assert", importPath, 1)

if err := writeFile("assert.go", assert.MainFile); err != nil {
return err
}
if err := writeFile("dotimport/alias.go", supportFile); err != nil {
if err := writeFile("EF/alias.go", aliasFile); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import _ "embed"
var (
//go:embed assert.go
MainFile string
//go:embed dotimport/alias.go
SupportFile string
//go:embed EF/alias.go
AliasFile string
)
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"

"go-simpler.org/assert"
. "go-simpler.org/assert/dotimport"
. "go-simpler.org/assert/EF"
)

func ExampleEqual() {
Expand Down

0 comments on commit 24e6853

Please sign in to comment.