Skip to content

Commit f442a0f

Browse files
committed
refact: moved assert/enable to enable/stubs (usage is symmetric)
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 5d65adf commit f442a0f

11 files changed

Lines changed: 91 additions & 10 deletions

File tree

.claude/CLAUDE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ With 76 assertion functions, this generates 608 functions automatically.
9797
### Dependency Isolation Strategy
9898
- **internal/spew**: Internalized copy of go-spew for pretty-printing values
9999
- **internal/difflib**: Internalized copy of go-difflib for generating diffs
100-
- **assert/yaml**: Stub package that panics by default if YAML assertions are used
100+
- **internal/assertions/enable**: Internal stubs that panic by default if YAML/color assertions are used
101+
- **enable/stubs**: Public API for enabling optional features (yaml, colors)
101102
- **enable/yaml**: Optional module that activates YAML support via init() when imported
103+
- **enable/colors**: Optional module that activates colorized output via init() when imported
102104

103-
The "enable" pattern allows YAML functionality to be opt-in: import `_ "github.com/go-openapi/testify/v2/enable/yaml"` to activate YAML assertions without forcing a dependency on all users.
105+
The "enable" pattern allows optional functionality to be opt-in: import `_ "github.com/go-openapi/testify/v2/enable/yaml"` to activate YAML assertions, or `_ "github.com/go-openapi/testify/v2/enable/colors"` to enable colorized output, without forcing dependencies on all users.
104106

105107
## Development Commands
106108

assert/doc.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1+
// Package assert provides a set of testing tools for use with the standard Go testing system.
2+
//
3+
// # Note
4+
//
5+
// All functions in this package return a bool value indicating whether the assertion has passed.
6+
//
7+
// # Example usage
8+
//
9+
// The following is a complete example using assert in a standard test function:
10+
//
11+
// import (
12+
// "testing"
13+
// "github.com/go-openapi/testify/v2/assert"
14+
// )
15+
//
16+
// func TestSomething(t *testing.T) {
17+
//
18+
// var a string = "Hello"
19+
// var b string = "Hello"
20+
//
21+
// assert.Equal(t, a, b, "The two words should be the same.")
22+
//
23+
// }
24+
//
25+
// if you assert many times, use the format below:
26+
//
27+
// import (
28+
// "testing"
29+
// "github.com/go-openapi/testify/v2/assert"
30+
// )
31+
//
32+
// func TestSomething(t *testing.T) {
33+
// assert := assert.New(t)
34+
//
35+
// var a string = "Hello"
36+
// var b string = "Hello"
37+
//
38+
// assert.Equal(a, b, "The two words should be the same.")
39+
// }
40+
//
41+
// # Assertions
42+
//
43+
// Assertions allow you to easily write test code.
44+
//
45+
// All assertion functions take as the first argument, the [*testing.T] object provided by the
46+
// standard testing framework.
47+
//
48+
// This allows the assertion functions to write the failings and other details to the correct place.
49+
//
50+
// Every assertion function also takes an optional string message as the final argument,
51+
// allowing custom error messages to be appended to the message the assertion method outputs.
52+
//
53+
// See [our doc site](https://go-openapi.github.io/testify/) for usage and examples and
54+
// [go docs](https://pkg.go/dev/go-openapi/testify) for complete reference.
155
package assert

docs/doc-site/project/maintainers/ARCHITECTURE.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ Everything in these packages is generated. Never edit generated files directly.
4848
Exceptions:
4949
* `doc.go` is not generated
5050
* ad'hoc testable examples are not generated
51-
* the `assert` package contains an `enable` package to enable features. This is not generated.
51+
52+
**Optional Feature Packages: `enable/`**
53+
54+
The `enable/` package provides optional features that users can activate via blank imports:
55+
- `enable/stubs/` - Public stub APIs for enabling features (yaml, colors)
56+
- `enable/yaml/` - Activates YAML support via `import _ "github.com/go-openapi/testify/v2/enable/yaml"`
57+
- `enable/colors/` - Activates colorized output via `import _ "github.com/go-openapi/testify/v2/enable/colors"`
58+
59+
These packages are not generated and allow optional dependencies to be isolated from the core library.

docs/doc-site/project/maintainers/CODEGEN.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ This repository uses code generation extensively to maintain consistency across
5656
direction LR
5757
docgo_assert@{ shape: document, label: "doc.go" }
5858
adhoc_assert@{ shape: document, label: "*_adhoc*_test.go" }
59-
enable_assert@{ shape: lin-doc, label: "enable" }
6059
end
6160
end
6261

enable/colors/assertions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111

1212
target "github.com/go-openapi/testify/v2/assert"
13-
colorstub "github.com/go-openapi/testify/v2/assert/enable/colors"
13+
colorstub "github.com/go-openapi/testify/v2/enable/stubs/colors"
1414
)
1515

1616
func TestMain(m *testing.M) {

enable/colors/enable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"golang.org/x/term"
1313

14-
colorstub "github.com/go-openapi/testify/v2/assert/enable/colors"
14+
colorstub "github.com/go-openapi/testify/v2/enable/stubs/colors"
1515
)
1616

1717
const (

enable/stubs/doc.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-FileCopyrightText: Copyright 2025 go-swagger maintainers
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Package stubs provides public APIs for enabling optional features in testify.
5+
//
6+
// This package exports stub implementations that delegate to internal packages,
7+
// maintaining a clean separation between internal implementation and public API.
8+
//
9+
// Subpackages:
10+
// - yaml: API for enabling YAML assertions
11+
// - colors: API for enabling colorized output
12+
//
13+
// These stubs are used by the enable/{yaml,colors} modules to activate optional features.
14+
package stubs

enable/yaml/enable_yaml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package yaml
66

77
import (
8-
yamlstub "github.com/go-openapi/testify/v2/assert/enable/yaml"
8+
yamlstub "github.com/go-openapi/testify/v2/enable/stubs/yaml"
99

1010
yaml "go.yaml.in/yaml/v3"
1111
)

0 commit comments

Comments
 (0)