Skip to content

Conversation

@GregoryAlbouy
Copy link
Contributor

@GregoryAlbouy GregoryAlbouy commented Oct 31, 2021

Description

An experimentation branch to see where would lead the usage of generics in testx

Changes

So far:

Caveats:

  • Some issues generating the interfaces of checker providers with type parameters (numberCheckerProvider, see b101eadFix numberCheckerProvider interface generation)
  • Many tools do not support type parameters yet, impacting the CI and the code generation
    • golangci-lint (CI/lint)
    • go-acc (CI/coverage)
    • goimports (formats generated file)

Screenshots

Linked issue

* Use go1.18

- Declare go 1.18 in go.mod
- Update make commands

* Declare generic checker types

* Type checker providers using Checker[T] interface

* Update checker providers interfaces

- Disable code generation for providers interfaces
- Update providers interfaces manually

* Update checker providers unit tests

* Update package check examples

* Update package checkconv

- Type checkconv.Assert using check.Checker[T] interface
- Type checkconv.Cast using check.Checker[T] interface

* Update testx runners

- Add type parameters to ValueRunner
- Use new type check.Checker[T]
- Update tests and examples

* Update temporary CI config

- Disable jobs: gen, lint
- Disable test coverage
- Add setup step: Install gotip

* Replace all occurrences of interface{} -> any
@GregoryAlbouy GregoryAlbouy added WIP generics Related to Go 1.18 generics, must target branch `go1.18-generics-experimentations` labels Oct 31, 2021
@GregoryAlbouy GregoryAlbouy added this to the go1.18-generics milestone Oct 31, 2021
@GregoryAlbouy GregoryAlbouy force-pushed the go1.18-generics-experimentation branch 2 times, most recently from b737d9c to 5426b7b Compare October 31, 2021 18:12
@GregoryAlbouy GregoryAlbouy changed the title Go1.18 generics experimentations epic(generics): Go1.18 generics experimentations Oct 31, 2021
* Remove code generation directives and templates

* Remove typed checkers declarations

* Update remaining usages of typed checkers
* Implement check.Wrap, check.WrapMany

* Create temp package slices

* Write unit tests for check.Wrap, WrapMany

* Replace all checkconv usages with check.Wrap

* Delete package checkconv

* Use package drykit-go/slicex

- Remove local package internal/slices
- Install and use github.com/drykit-go/slicex v0.0.1
* Implement generic numberCheckerProvider[T Numeric]

* Update interfaces accordingly

* Write unit tests for numberCheckerProvider

* Delete previous numeric checker implementations

- intCheckerProvider
- float64CheckerProvider
* Delete go generate directive for typed checkers

* Remove kind "types" from cmd

* Remove gen.Types

* Remove template: assert.gotmpl

* Update contributing guidelines
* Pre-compute numeric vars for numberCheckerProvider

* Re-enable code generation for providers interfaces

* Fix numberCheckerProvider interface generation

* Run make gen
* Delete obsolete example

* Update readmes

* Remove last mentions of <Type>Checkers
* Remove mention to checkconv in readme

* Fix impossible example
* Type TableRunner with generics

* Remove testx.ExpNil

* Update unit tests to new Case.Exp behaviour

* Reorganize unit tests
* Remove mentions to checkconv and uncovered types

* Run make gen
* Exclude lint errors due to unsupported 1.18 syntax

* Restore CI job: lint

* Use gotip in make command: test-cov

* Restore CI step: coverage

* Restore CI job: gen

* Use golangci-lint v1.43.0 in CI
* Remove interfaces generation logics

* Run make gen

* Update package gen namings and docs

* Fix docparser.ParseDocLines docs

* Export checker providers structs

* Update providers gen

* Run make gen

* Refactor some var names generation
@codecov-commenter
Copy link

codecov-commenter commented Nov 11, 2021

Codecov Report

Merging #66 (b801705) into go1.18-generics-experimentation-base (cdfcba2) will decrease coverage by 1.24%.
The diff coverage is 97.87%.

Impacted file tree graph

@@                           Coverage Diff                            @@
##           go1.18-generics-experimentation-base      #66      +/-   ##
========================================================================
- Coverage                                 95.89%   94.65%   -1.25%     
========================================================================
  Files                                        33       32       -1     
  Lines                                      1290     1159     -131     
========================================================================
- Hits                                       1237     1097     -140     
- Misses                                       40       46       +6     
- Partials                                     13       16       +3     
Impacted Files Coverage Δ
check/providers.go 66.66% <66.66%> (ø)
internal/providers/providers_map.go 93.57% <85.10%> (ø)
runner_value.go 87.50% <92.85%> (+1.78%) ⬆️
check/check.go 100.00% <100.00%> (ø)
check/wrap.go 100.00% <100.00%> (ø)
internal/checktypes/checktypes.go 100.00% <100.00%> (ø)
internal/fmtexpl/fmtexpl.go 100.00% <100.00%> (ø)
internal/providers/bool.go 100.00% <100.00%> (ø)
internal/providers/providers_base.go 100.00% <100.00%> (ø)
internal/providers/providers_bytes.go 100.00% <100.00%> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cdfcba2...b801705. Read the comment docs.

* Use fixed gotip version

* Remove duplicate gotip download command

* Fix CI: add confirmation user prompt

* Add '|| true' to gotip download command
* Use generics in MapCheckerProvider implementation

* Update code gen and template manually

* Run make gen

* Update Map unit tests

* Update Bytes.AsMap

- Change parameter type Checker[any] -> Cheker[map[string]any]
- Update unit tests for Bytes
- Run make gen
* Type SliceCheckerProvider with generics

* Update var gen

* Run make gen

* Update unit tests

* Fix Map().CheckValues explain output
* Update var gen

* Run make gen

* Type ValueCheckerProvider with generics

* Update unit tests

* Exclude lint rule with false positive
@GregoryAlbouy GregoryAlbouy changed the title epic(generics): Go1.18 generics experimentations epic(generics): use Go1.18 type parameters Nov 17, 2021
@GregoryAlbouy GregoryAlbouy added WIP and removed WIP labels Nov 20, 2021
* Create internal package checktypes

- Avoid cyclic deps

* Create package internal/providers

- Copy providers impl and tests into internal/providers

* Update code gen

- Move check/gen.go -> internal/providers/gen.go
- Require output filepath argument (-o)
- Adapt providers vars generation logics

* Run make gen

* Remove providers files in package check

* Fix check.Wrap inference issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

epic generics Related to Go 1.18 generics, must target branch `go1.18-generics-experimentations` WIP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants