File tree 6 files changed +152
-38
lines changed
6 files changed +152
-38
lines changed Original file line number Diff line number Diff line change @@ -6,16 +6,8 @@ submit changes. Contributions can be made in the form of GitHub
6
6
[ pull requests] ( https://github.com/BooleanCat/go-functional/pulls ) .
7
7
8
8
When submitting an issue, please choose the relevant template or choose a blank issue if your query
9
- doesn't naturally fit into an existing template.
10
-
11
- ## TL;DR contribution checklist
12
-
13
- - [ ] My code is formatted (` make check ` )
14
- - [ ] I have run tests (` make test ` )
15
- - [ ] My code has no lint errors (` make lint ` )
16
- - [ ] All commits in my PR conform to the commit hygiene section
17
- - [ ] I have added relevant tests
18
- - [ ] I have not added any dependencies
9
+ doesn't naturally fit into an existing template. The pull request template contains a contribution
10
+ checklist.
19
11
20
12
## Zero-dependency
21
13
@@ -25,6 +17,13 @@ must only incur one dependency: go-functional.
25
17
Development dependencies are OK as they will not be included as dependencies to end-users (such as
26
18
` golangci-lint ` ).
27
19
20
+ ## Development dependencies
21
+
22
+ 1 . [ golangci-lint] ( https://github.com/golangci/golangci-lint ) is used to lint the project when
23
+ running ` make check ` .
24
+ 2 . [ counterfeiter] ( https://github.com/maxbrunsfeld/counterfeiter ) is used to generate new fakes
25
+ (using ` go generate ./... ` ). Fakes are declared in ` internal/fakes/fakes.go ` .
26
+
28
27
## Commit hygiene
29
28
30
29
- Commits should contain only a single change
Original file line number Diff line number Diff line change 17
17
18
18
cov : SHELL:=/bin/bash
19
19
cov :
20
- $(GO_BINARY ) test -race -coverprofile=coverage.txt -covermode=atomic $$( $(GO_BINARY ) list ./... | grep -v assert )
20
+ $(GO_BINARY ) test -race -coverprofile=coverage.txt -covermode=atomic $$( $(GO_BINARY ) list ./... | grep -v assert | grep -v fakes )
Original file line number Diff line number Diff line change
1
+ package fakes
2
+
3
+ //go:generate counterfeiter -generate
4
+
5
+ //counterfeiter:generate --fake-name Reader -o . io.Reader
Original file line number Diff line number Diff line change 1
1
package it_test
2
2
3
3
import (
4
+ "errors"
4
5
"fmt"
5
6
"slices"
6
7
"strings"
7
8
"testing"
8
9
9
10
"github.com/BooleanCat/go-functional/v2/internal/assert"
11
+ "github.com/BooleanCat/go-functional/v2/internal/fakes"
10
12
"github.com/BooleanCat/go-functional/v2/it"
11
13
"github.com/BooleanCat/go-functional/v2/it/op"
12
14
)
@@ -157,11 +159,13 @@ func ExampleTryCollect() {
157
159
func TestTryCollectError (t * testing.T ) {
158
160
t .Parallel ()
159
161
160
- text := new (failSecondTime )
161
- lines , err := it .TryCollect (it .LinesString (text ))
162
+ reader := new (fakes.Reader )
163
+ reader .ReadReturns (0 , errors .New ("read error" ))
164
+
165
+ lines , err := it .TryCollect (it .LinesString (reader ))
162
166
163
167
assert .Equal (t , err .Error (), "read error" )
164
- assert .SliceEqual (t , lines , [] string { "o" } )
168
+ assert .Empty [ string ] (t , lines )
165
169
}
166
170
167
171
func ExampleLen () {
@@ -249,7 +253,10 @@ func TestMustCollectPanic(t *testing.T) {
249
253
}
250
254
}()
251
255
252
- it .MustCollect (it .LinesString (new (failSecondTime )))
256
+ reader := new (fakes.Reader )
257
+ reader .ReadReturns (0 , errors .New ("read error" ))
258
+
259
+ it .MustCollect (it .LinesString (reader ))
253
260
}
254
261
255
262
func ExampleAll () {
Original file line number Diff line number Diff line change @@ -3,11 +3,11 @@ package it_test
3
3
import (
4
4
"errors"
5
5
"fmt"
6
- "io"
7
6
"strings"
8
7
"testing"
9
8
10
9
"github.com/BooleanCat/go-functional/v2/internal/assert"
10
+ "github.com/BooleanCat/go-functional/v2/internal/fakes"
11
11
"github.com/BooleanCat/go-functional/v2/it"
12
12
)
13
13
@@ -70,27 +70,6 @@ func TestLinesYieldsFalseWithError(t *testing.T) {
70
70
})
71
71
}
72
72
73
- type failSecondTime struct {
74
- count int
75
- }
76
-
77
- func (f * failSecondTime ) Read (p []byte ) (n int , err error ) {
78
- if f .count == 0 {
79
- f .count ++
80
- copy (p , []byte ("o" ))
81
- return 1 , nil
82
- }
83
-
84
- if f .count == 1 {
85
- f .count ++
86
- return 0 , errors .New ("read error" )
87
- }
88
-
89
- return 0 , io .EOF
90
- }
91
-
92
- var _ io.Reader = new (failSecondTime )
93
-
94
73
func TestLinesFailsLater (t * testing.T ) {
95
74
t .Parallel ()
96
75
@@ -99,7 +78,11 @@ func TestLinesFailsLater(t *testing.T) {
99
78
lastErr error
100
79
)
101
80
102
- for _ , err := range it .LinesString (new (failSecondTime )) {
81
+ reader := new (fakes.Reader )
82
+ reader .ReadReturnsOnCall (0 , 1 , nil )
83
+ reader .ReadReturnsOnCall (1 , 0 , errors .New ("read error" ))
84
+
85
+ for _ , err := range it .LinesString (reader ) {
103
86
count ++
104
87
lastErr = err
105
88
}
You can’t perform that action at this time.
0 commit comments