Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5426b7b
feat(generics): create viable POC (#63)
GregoryAlbouy Oct 31, 2021
bfd8a9b
ops(generics): add gotip to CircleCI cache (#67)
GregoryAlbouy Oct 31, 2021
a888d6a
dev(generics): remove typed checkers (#65)
GregoryAlbouy Oct 31, 2021
31dd96a
feat(generics): remove package checkconv (#68)
GregoryAlbouy Nov 1, 2021
5bc0039
feat(generics): implement generic number checker provider (#69)
GregoryAlbouy Nov 1, 2021
b8222ef
dev(generics): cherrypick #52 (#71)
GregoryAlbouy Nov 1, 2021
24223bc
dev(generics): remove obsolete generation code (#72)
GregoryAlbouy Nov 1, 2021
5152d02
fix(generics): fix checker providers interfaces generation (#73)
GregoryAlbouy Nov 1, 2021
81b495f
docs(generics): remove typed checkers mentions (#74)
GregoryAlbouy Nov 1, 2021
06bebb3
docs(generics): remove checkconv from readme example (#75)
GregoryAlbouy Nov 3, 2021
c21d7c5
feat(generics): type TableRunner with generics (#77)
GregoryAlbouy Nov 5, 2021
9bff281
docs(generics): remove all mentions to checkconv (#76)
GregoryAlbouy Nov 5, 2021
70ae4a3
ops(generics): restore lint and coverage (#80)
GregoryAlbouy Nov 11, 2021
137c7fc
feat(generics): remove checker providers interfaces (#79)
GregoryAlbouy Nov 11, 2021
354609c
ops(generics): use determined gotip version (#82)
GregoryAlbouy Nov 17, 2021
469485e
feat(generics): type MapCheckerProvider with generics (#78)
GregoryAlbouy Nov 17, 2021
bb7f7cc
feat(generics): type SliceCheckerProvider with generics (#83)
GregoryAlbouy Nov 17, 2021
36ed999
feat(generics): type ValueCheckerProvider with generics (#84)
GregoryAlbouy Nov 17, 2021
b801705
dev(generics): move providers to dedicated internal package (#91)
GregoryAlbouy Nov 21, 2021
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
25 changes: 21 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ commands:
setup:
steps:
- checkout

- restore_cache:
keys:
- go-mod-v4-{{ checksum "go.sum" }}-{{ .Environment.CACHE_VERSION }}
Expand All @@ -20,14 +21,31 @@ commands:
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}-{{ .Environment.CACHE_VERSION }}
paths:
- "/go/pkg/mod"
- /go/pkg/mod

- restore_cache:
keys:
- gotip-{{ .Environment.CACHE_VERSION }}
- run:
name: Install gotip
command: |
command -v /go/bin/gotip && echo "Skipping gotip installation" && exit
go install golang.org/dl/gotip@latest
- save_cache:
key: gotip-{{ .Environment.CACHE_VERSION }}
paths:
- /go/bin/gotip
- run:
name: Run gotip download
command: | # Nov 12 (https://go-review.googlesource.com/c/go/+/359478)
yes | gotip download 359478 || true

setup-lint:
description: Set up lint
parameters:
version:
type: string
default: v1.40.1
default: v1.43.0
steps:
- restore_cache:
keys:
Expand Down Expand Up @@ -68,7 +86,7 @@ commands:
- run:
name: Install goimports
command: |
command -v /go/bin/goimports && echo "Skipping go-acc installation" && exit
command -v /go/bin/goimports && echo "Skipping goimports installation" && exit
go get -v golang.org/x/tools/cmd/goimports

- save_cache:
Expand Down Expand Up @@ -123,4 +141,3 @@ workflows:
- lint
- test
- gen

16 changes: 13 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ linters-settings:
sizeThreshold: 256

gofumpt:
lang-version: "1.16"
lang-version: "1.18"
extra-rules: true

goimports:
Expand All @@ -117,11 +117,11 @@ linters-settings:
enableAllRules: true

staticcheck:
go: "1.16"
go: "1.18"
checks: [all]

stylecheck:
go: "1.16"
go: "1.18"
checks: [all]

linters:
Expand All @@ -147,6 +147,7 @@ linters:
- thelper # enforce t.Helper()
- varcheck # unused global var and const
- wastedassign
disable:
fast: false

issues:
Expand All @@ -156,3 +157,12 @@ issues:
- dupl
- gocognit
- gocyclo

# temporary fixes for unsupported type parameters syntax
exclude:
- "expected .*, found .*"
- "expected expression"
- "undeclared name: `any`"
- "missing ',' in parameter list"
- "missing element type in array type expression"
- "mixed named and unnamed parameters"
65 changes: 12 additions & 53 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ The main documentation can help understand how the repository globally works:
- [Go package documentation](https://pkg.go.dev/github.com/drykit-go/testx#section-documentation)
- [Main Readme](./README.md)
- [Package `check` Readme](./check/README.md)
- [Package `checkconv` Readme](./checkconv/README.md)

## Internal documentation

Expand All @@ -36,7 +35,6 @@ The main documentation can help understand how the repository globally works:
. # Package testx (test runners)
├── bin # Binary files (for code generation)
├── check # Package check (checkers interfaces & providers)
├── checkconv # Package checkconv (checkers conversion)
├── cmd # Runnable source files
│   └── gen # Code generation main command
└── internal # Cross-packages utilities for internal use only
Expand All @@ -55,47 +53,19 @@ The main documentation can help understand how the repository globally works:
We use code generation to reduce code repetition, and consequently
reduce the complexity of implementations and the risks of errors.

We have 2 use cases for that:
- Generate repetitive declarations for each checker type declared in `internal/gen/types.go`.
- Generate public interfaces of checker providers from their implementation.
We have 1 use case for that: generate public interfaces of checker providers
from their implementation.

#### Generated files

The following files are generated:

<details>
<summary>Generated files</summary>
<table>
<thead>
<tr>
<th>File</th>
<th>Use case</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>check/check.go</code></td>
<td>Checkers types declarations</td>
</tr>
<tr>
<td><code>check/checkers.go</code></td>
<td>Checkers types declarations</td>
</tr>
<tr>
<td><code>check/providers.go</code></td>
<td>Checkers providers interfaces</td>
</tr>
<tr>
<td><code>checkconv/assert.go</code></td>
<td>Checkers types declarations</td>
</tr>
</tbody>
</table>
</details>
- `check/providers.go`

These files should **never** be manually edited, as specified
in their header (your IDE will likely inform you it shouldn't be edited
if you attempt to).
If an update is needed, re-generated them using the command described below.

#### Command

Expand All @@ -111,11 +81,8 @@ then runs all `//go:generate` directives found in the whole repository.
Located in `gen.go` files, these directives execute `bin/gen` binary
with various arguments.

Run this command each time:

- you declare a new checker type (in file `internal/gen/types.go`)
- you implement a new `check.<Type>CheckerProvider` or update one
in a way that changes its public interface, which includes:
Run this command each time you implement a new `check.<Type>CheckerProvider`
or update one in a way that changes its public interface, which includes:
- Adding/removing a method
- Changing a method signature (a parameter name change counts)
- Editing a doc comment for a method
Expand All @@ -126,18 +93,6 @@ To illustrate the process described above, let's implement
`check.Complex128`, a `check.Complex128CheckerProvider`
that performs checks on type `complex128`:

1. In file `internal/gen/types.go`, add a new entry to `types`:
```go
{N: "Complex128", T: "complex128"},
```
Note: `N` is the **Name** of the checker provider, while **T** refers
to the **Type** of the value it checks. Technically, the former could be
any valid name, whereas the second must be a valid Go type.

1. Run `make gen`
This generates `check.Complex128Checker` interface along with other
necessary declarations to work with this new type.

1. Create file `check/providers_complex128.go` and implement
`complex128CheckerProvider` following the existing models.

Expand All @@ -157,11 +112,13 @@ Here are some contributing suggestions:

## Dev environment

For an optimal dev experience, we recommend:
This branches uses Go 1.18 type parameters, which is yet to be released.
As a consequence it has specific requirements:

- Go 1.16 or higher ([download](https://golang.org/dl/))
- Go 1.18 (we recommand using the wrapper [`gotip`](https://pkg.go.dev/golang.org/dl/gotip))
- `make` commands available (native on Unix-based systems)
- `golangci-lint` to run linters locally ([installation](https://golangci-lint.run/usage/install/#local-installation))
Note: it currently doesn't work properly with type parameters syntax.

## Conventions

Expand All @@ -170,6 +127,8 @@ For an optimal dev experience, we recommend:
Code style conventions are enforced by `golangci-lint`.
Run `make lint` to ensure your code is compliant.

Note: the linter currently doesn't work properly with type parameters syntax.

### Unit tests

We try to maintain a high level of test coverage, so we encourage you
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ default:
.PHONY: gen
gen:
@echo "🛠 Building gen binary"
@go build -o ./bin/gen ./cmd/gen/main.go
@gotip build -o ./bin/gen ./cmd/gen/main.go
@echo "✅ Done\n"
@go generate ./...
@gotip generate ./...

# Check code

Expand All @@ -26,11 +26,11 @@ lint:

.PHONY: tests
tests:
@go test ./...
@gotip test ./...

.PHONY: test-cov
test-cov: # Unit tests with coverage, excluding gen-related files
@go-acc --ignore cmd/gen,internal/gen ./...
@GO_TEST_BINARY="gotip test" go-acc --ignore cmd/gen,internal/gen ./...

TEST_FUNC=^.*$$
ifdef t
Expand All @@ -43,7 +43,7 @@ endif

.PHONY: test
test:
@go test -timeout 30s -run $(TEST_FUNC) $(TEST_PKG)
@gotip test -timeout 30s -run $(TEST_FUNC) $(TEST_PKG)

# Docs

Expand Down
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<tr>
<td>testx</td>
<td><a href="./check/README.md">testx/check</a></td>
<td><a href="./checkconv/README.md">testx/checkconv</a></td>
</tr>
</table>

Expand All @@ -22,7 +21,7 @@
</p>

`testx` is a Go testing library that provides test runners to write reliable
and expressive unit tests effortlessly, with minimal boilerplate.
and expressive unit tests with minimal boilerplate.

## Table of contents

Expand Down Expand Up @@ -58,11 +57,11 @@ go get -u github.com/drykit-go/testx
func TestGet42(t *testing.T) {
testx.Value(Get42()).
Exp(42). // expect 42
Not(3, "hello"). // expect not 3 nor "hello"
Pass(checkconv.AssertMany( // expect to pass input checkers:
Not(3, 4, 5). // expect not 3 nor 4 nor 5
Pass( // expect to pass all input checkers:
check.Int.InRange(41, 43), // expect in range [41:43]
// ...
)...).
).
Run(t)
}
```
Expand Down Expand Up @@ -185,7 +184,3 @@ Related examples:

- Package `check` 📄 [Readme](./check/README.md)
> Package `check` provides extensible and customizable checkers to perform checks on typed values.

- Package `checkconv` 📄 [Readme](./checkconv/README.md)
> Package `checkconv` provides conversion utilities to convert any typed checker to a `check.ValueChecker`

Loading