Skip to content
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
2 changes: 1 addition & 1 deletion codegen/internal/generator/funcmaps/funcmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func comment(str string) string {

func rTrimEmpty(lines []string) []string {
var i int
for i = len(lines) - 1; i >= 0; i-- {
for i = len(lines) - 1; i >= 0; i-- { //nolint:modernize // slicesbackward: we actually need the index, not the value.
if lines[i] != "" {
break
}
Expand Down
14 changes: 7 additions & 7 deletions codegen/internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ func (g *Generator) Generate(opts ...GenerateOption) error {
return nil
}

// Documentation yields the transformed package model as a [model.Documentation]
// usable by a generation step by the [DocGenerator].
func (g *Generator) Documentation() model.Documentation {
return g.docs
}

// orphanVariantRx matches a generated build-variant filename for the given target package,
// e.g. "assert_assertions_go126.go" or "assert_forward_go126_test.go". The "_go<N>" infix is
// what distinguishes a variant file from the default (unsuffixed) ones, which are always
Expand Down Expand Up @@ -179,7 +185,7 @@ func (g *Generator) sweepOrphanVariants() error {

// isGeneratedFile reports whether the file carries our "DO NOT EDIT" generated-code marker.
func isGeneratedFile(path string) (bool, error) {
data, err := os.ReadFile(path) //nolint:gosec // path is built from a controlled target directory listing
data, err := os.ReadFile(path) // path is built from a controlled target directory listing
if err != nil {
return false, fmt.Errorf("can't read candidate orphan %q: %w", path, err)
}
Expand Down Expand Up @@ -258,12 +264,6 @@ func variantTarget(base *model.AssertionPackage, constraint string) *model.Asser
return tgt
}

// Documentation yields the transformed package model as a [model.Documentation]
// usable by a generation step by the [DocGenerator].
func (g *Generator) Documentation() model.Documentation {
return g.docs
}

func (g *Generator) initContext(opts []GenerateOption) error {
// prepare options
g.ctx = &genCtx{
Expand Down
2 changes: 2 additions & 0 deletions codegen/internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ func (t CommentTag) String() string {
return "comment-tag-note"
case CommentTagDomainDescription:
return "comment-tag-domain-description"
case CommentTagOpposite:
return "comment-tag-opposite"
default:
return "invalid-value"
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/internal/scanner/comments/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func extractCommentFromTypeSpec(typedDeclaration *ast.GenDecl, spec ast.Spec, ob
case *ast.ValueSpec:
for _, ident := range typedSpec.Names {
if ident.Name != object.Name() {
return nil
continue
}

// return Doc, checking both GenDecl.Doc and ValueSpec.Doc
Expand Down
16 changes: 8 additions & 8 deletions docs/doc-site/api/equality.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func main() {
|--|--|
| [`assertions.Equal(t T, expected any, actual any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#Equal) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#Equal](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L30)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#Equal](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L33)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -434,7 +434,7 @@ type dummyStruct struct {
|--|--|
| [`assertions.EqualExportedValues(t T, expected any, actual any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#EqualExportedValues) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#EqualExportedValues](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L217)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#EqualExportedValues](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L220)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -548,7 +548,7 @@ func main() {
|--|--|
| [`assertions.EqualT[V comparable](t T, expected V, actual V, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#EqualT) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#EqualT](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L68)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#EqualT](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L71)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -662,7 +662,7 @@ func main() {
|--|--|
| [`assertions.EqualValues(t T, expected any, actual any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#EqualValues) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#EqualValues](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L144)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#EqualValues](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L147)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -773,7 +773,7 @@ func main() {
|--|--|
| [`assertions.Exactly(t T, expected any, actual any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#Exactly) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#Exactly](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L259)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#Exactly](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L270)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -1111,7 +1111,7 @@ func main() {
|--|--|
| [`assertions.NotEqual(t T, expected any, actual any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#NotEqual) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotEqual](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L93)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotEqual](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L96)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -1220,7 +1220,7 @@ func main() {
|--|--|
| [`assertions.NotEqualT[V comparable](t T, expected V, actual V, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#NotEqualT) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotEqualT](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L122)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotEqualT](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L125)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -1333,7 +1333,7 @@ func main() {
|--|--|
| [`assertions.NotEqualValues(t T, expected any, actual any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#NotEqualValues) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotEqualValues](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L179)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotEqualValues](https://github.com/go-openapi/testify/blob/master/internal/assertions/equal.go#L182)
{{% /tab %}}
{{< /tabs >}}

Expand Down
2 changes: 1 addition & 1 deletion docs/doc-site/api/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func testDataPath() string {
|--|--|
| [`assertions.FileNotEmpty(t T, path string, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#FileNotEmpty) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#FileNotEmpty](https://github.com/go-openapi/testify/blob/master/internal/assertions/file.go#L183)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#FileNotEmpty](https://github.com/go-openapi/testify/blob/master/internal/assertions/file.go#L191)
{{% /tab %}}
{{< /tabs >}}

Expand Down
4 changes: 2 additions & 2 deletions docs/doc-site/api/number.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func main() {
|--|--|
| [`assertions.InDeltaMapValues(t T, expected any, actual any, delta float64, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#InDeltaMapValues) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#InDeltaMapValues](https://github.com/go-openapi/testify/blob/master/internal/assertions/number.go#L375)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#InDeltaMapValues](https://github.com/go-openapi/testify/blob/master/internal/assertions/number.go#L378)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -754,7 +754,7 @@ func main() {
|--|--|
| [`assertions.InEpsilonSlice(t T, expected any, actual any, epsilon float64, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#InEpsilonSlice) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#InEpsilonSlice](https://github.com/go-openapi/testify/blob/master/internal/assertions/number.go#L430)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#InEpsilonSlice](https://github.com/go-openapi/testify/blob/master/internal/assertions/number.go#L433)
{{% /tab %}}
{{< /tabs >}}

Expand Down
6 changes: 3 additions & 3 deletions docs/doc-site/api/ordering.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func main() {
|--|--|
| [`assertions.IsDecreasingT[OrderedSlice ~[]E, E Ordered](t T, collection OrderedSlice, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#IsDecreasingT) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsDecreasingT](https://github.com/go-openapi/testify/blob/master/internal/assertions/order.go#L237)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsDecreasingT](https://github.com/go-openapi/testify/blob/master/internal/assertions/order.go#L236)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -611,7 +611,7 @@ func main() {
|--|--|
| [`assertions.IsNonDecreasing(t T, collection any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#IsNonDecreasing) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsNonDecreasing](https://github.com/go-openapi/testify/blob/master/internal/assertions/order.go#L270)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsNonDecreasing](https://github.com/go-openapi/testify/blob/master/internal/assertions/order.go#L269)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -726,7 +726,7 @@ func main() {
|--|--|
| [`assertions.IsNonDecreasingT[OrderedSlice ~[]E, E Ordered](t T, collection OrderedSlice, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#IsNonDecreasingT) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsNonDecreasingT](https://github.com/go-openapi/testify/blob/master/internal/assertions/order.go#L305)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsNonDecreasingT](https://github.com/go-openapi/testify/blob/master/internal/assertions/order.go#L304)
{{% /tab %}}
{{< /tabs >}}

Expand Down
18 changes: 9 additions & 9 deletions docs/doc-site/api/type.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ type myType float64
|--|--|
| [`assertions.IsNotOfTypeT[EType any](t T, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#IsNotOfTypeT) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsNotOfTypeT](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L152)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsNotOfTypeT](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L153)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -407,7 +407,7 @@ func main() {
|--|--|
| [`assertions.IsNotType(t T, theType any, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#IsNotType) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsNotType](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L131)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsNotType](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L132)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -518,7 +518,7 @@ type myType float64
|--|--|
| [`assertions.IsOfTypeT[EType any](t T, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#IsOfTypeT) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsOfTypeT](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L106)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsOfTypeT](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L107)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -629,7 +629,7 @@ func main() {
|--|--|
| [`assertions.IsType(t T, expectedType any, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#IsType) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsType](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L84)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#IsType](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L85)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -745,7 +745,7 @@ func main() {
|--|--|
| [`assertions.Kind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#Kind) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#Kind](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L222)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#Kind](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L223)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -856,7 +856,7 @@ func main() {
|--|--|
| [`assertions.NotImplements(t T, interfaceObject any, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#NotImplements) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotImplements](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L53)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotImplements](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L54)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -972,7 +972,7 @@ func main() {
|--|--|
| [`assertions.NotKind(t T, expectedKind reflect.Kind, object any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#NotKind) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotKind](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L256)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotKind](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L257)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -1083,7 +1083,7 @@ func main() {
|--|--|
| [`assertions.NotZero(t T, i any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#NotZero) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotZero](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L198)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#NotZero](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L199)
{{% /tab %}}
{{< /tabs >}}

Expand Down Expand Up @@ -1194,7 +1194,7 @@ func main() {
|--|--|
| [`assertions.Zero(t T, i any, msgAndArgs ...any) bool`](https://pkg.go.dev/github.com/go-openapi/testify/v2/internal/assertions#Zero) | internal implementation |

**Source:** [github.com/go-openapi/testify/v2/internal/assertions#Zero](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L176)
**Source:** [github.com/go-openapi/testify/v2/internal/assertions#Zero](https://github.com/go-openapi/testify/blob/master/internal/assertions/type.go#L177)
{{% /tab %}}
{{< /tabs >}}

Expand Down
2 changes: 1 addition & 1 deletion internal/assertions/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func SeqNotContainsT[E comparable](t T, iter iter.Seq[E], element E, msgAndArgs

for iterated := range iter {
if iterated == element {
return Fail(t, fmt.Sprintf("sequence does not contain %#v", element), msgAndArgs...)
return Fail(t, fmt.Sprintf("sequence should not contain %#v", element), msgAndArgs...)
}
}

Expand Down
12 changes: 6 additions & 6 deletions internal/assertions/equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,22 @@ func EqualExportedValues(t T, expected, actual any, msgAndArgs ...any) bool {
return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...)
}

expected, err = copyExportedFields(expected)
thisExpected, err := copyExportedFields(expected)
if err != nil {
return Fail(t, fmt.Sprintf("An error occurred while exploring the expected value: %v", err), msgAndArgs...)
}

actual, err = copyExportedFields(actual)
thisActual, err := copyExportedFields(actual)
if err != nil {
return Fail(t, fmt.Sprintf("An error occurred while exploring the actual value: %v", err), msgAndArgs...)
}

if !ObjectsAreEqualValues(expected, actual) {
diff := diff(expected, actual)
expected, actual = formatUnequalValues(expected, actual)
if !ObjectsAreEqualValues(thisExpected, thisActual) {
diff := diff(thisExpected, thisActual)
thisExpected, thisActual = formatUnequalValues(thisExpected, thisActual)
return Fail(t, fmt.Sprintf("Not equal (comparing only exported fields): \n"+
"expected: %s\n"+
"actual : %s%s", expected, actual, diff), msgAndArgs...)
"actual : %s%s", thisExpected, thisActual, diff), msgAndArgs...)
}

return true
Expand Down
15 changes: 11 additions & 4 deletions internal/assertions/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func NotErrorAs(t T, err error, target any, msgAndArgs ...any) bool {
}

func unwrapAll(err error) []error {
return appendUnwrapped(nil, err, make(map[error]struct{}))
return appendUnwrapped(nil, err, make(map[error]struct{}), 0)
}

// appendUnwrapped flattens an error chain, guarding against cyclic chains that
Expand All @@ -281,7 +281,13 @@ func unwrapAll(err error) []error {
// Only comparable errors are tracked: using an incomparable error as a map key
// would panic, so those simply skip cycle detection (mirroring how the standard
// library's errors.Is guards its own comparisons).
func appendUnwrapped(errs []error, err error, visited map[error]struct{}) []error {
//
// Unwrapping stops at 1000 nest levels, which should cover most practical usage of it.
func appendUnwrapped(errs []error, err error, visited map[error]struct{}, depth int) []error {
if depth > maxDepth {
return nil
}

if err != nil && reflect.TypeOf(err).Comparable() {
if _, ok := visited[err]; ok {
return errs // cyclic error chain: stop here
Expand All @@ -297,12 +303,13 @@ func appendUnwrapped(errs []error, err error, visited map[error]struct{}) []erro
if next == nil {
return errs
}
errs = appendUnwrapped(errs, next, visited)
errs = appendUnwrapped(errs, next, visited, depth+1)
case interface{ Unwrap() []error }:
for _, next := range x.Unwrap() {
errs = appendUnwrapped(errs, next, visited)
errs = appendUnwrapped(errs, next, visited, depth+1)
}
}

return errs
}

Expand Down
Loading
Loading