Skip to content

Commit

Permalink
Collect test coverage from the proper version of Go (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
destel authored Aug 18, 2024
1 parent 8f551fc commit 5e57553
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
gotest:
strategy:
matrix:
go-version: [1.21.x, 1.22.x, 1.23.0-rc.2]
go-version: [1.21.x, 1.23.x]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -20,22 +20,24 @@ jobs:
with:
go-version: ${{ matrix.go-version }}

- name: Cache go packages
uses: actions/cache@v4
- name: Run tests
run: go test -race ./...


coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-
${{ runner.os }}-go-
go-version: '1.23.x'

- name: Run tests
run: go test -race ./...
run: go test ./...

- name: Run coverage
run: go test -coverprofile=coverage.out -covermode=atomic ./...
run: go test -coverprofile=coverage.out -covermode=atomic $(go list ./... | grep -v internal/th)

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
Expand Down
52 changes: 32 additions & 20 deletions iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func TestToSeq2(t *testing.T) {
}

func TestFromSeq(t *testing.T) {
t.Run("nil", func(t *testing.T) {
in := FromSeq[int](nil, nil)
th.ExpectValue(t, in, nil)
})

t.Run("normal ", func(t *testing.T) {
in := FromSeq(rangeInt(0, 20), nil)

Expand All @@ -91,29 +96,36 @@ func TestFromSeq(t *testing.T) {
}

func TestFromSeq2(t *testing.T) {
// generate from 0 to 7, and when the value is 5, yield error
err5 := errors.New("err5")
gen := func(yield func(x int, err error) bool) {
for i := 0; i < 8; i++ {
var err error
if i == 5 {
err = err5
}
if !yield(i, err) {
break
t.Run("nil", func(t *testing.T) {
in := FromSeq2[int](nil)
th.ExpectValue(t, in, nil)
})

t.Run("normal", func(t *testing.T) {
// generate from 0 to 7, and when the value is 5, yield error
err5 := errors.New("err5")
gen := func(yield func(x int, err error) bool) {
for i := 0; i < 8; i++ {
var err error
if i == 5 {
err = err5
}
if !yield(i, err) {
break
}
}
}
}

in := FromSeq2(gen)
in := FromSeq2(gen)

var outSlice []int
var outError []error
for a := range in {
outSlice = append(outSlice, a.Value)
outError = append(outError, a.Error)
}
var outSlice []int
var outError []error
for a := range in {
outSlice = append(outSlice, a.Value)
outError = append(outError, a.Error)
}

th.ExpectSlice(t, outSlice, []int{0, 1, 2, 3, 4, 5, 6, 7})
th.ExpectSlice(t, outError, []error{nil, nil, nil, nil, nil, err5, nil, nil})
th.ExpectSlice(t, outSlice, []int{0, 1, 2, 3, 4, 5, 6, 7})
th.ExpectSlice(t, outError, []error{nil, nil, nil, nil, nil, err5, nil, nil})
})
}

0 comments on commit 5e57553

Please sign in to comment.