Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhang committed Aug 15, 2023
1 parent 3abbc3d commit 740db90
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
21 changes: 1 addition & 20 deletions internal/fxreflect/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,6 @@ func TestStack(t *testing.T) {
assert.NotZero(t, f.Line)
})

t.Run("default/deeper", func(t *testing.T) {
t.Parallel()

// Introduce a few frames.
frames := func() []Frame {
return func() []Frame {
return CallerStack(0, 0)
}()
}()

require.True(t, len(frames) > 3, "expected at least three frames")
for i, name := range []string{"func2.TestStack.func2.1.func2", "func2.1", "func2"} {
f := frames[i]
assert.Equal(t, "go.uber.org/fx/internal/fxreflect.TestStack."+name, f.Function)
assert.Contains(t, f.File, "internal/fxreflect/stack_test.go")
assert.NotZero(t, f.Line)
}
})

t.Run("skip", func(t *testing.T) {
t.Parallel()

Expand All @@ -78,7 +59,7 @@ func TestStack(t *testing.T) {

require.NotEmpty(t, frames)
f := frames[0]
assert.Equal(t, "go.uber.org/fx/internal/fxreflect.TestStack.func3", f.Function)
assert.Equal(t, "go.uber.org/fx/internal/fxreflect.TestStack.func2", f.Function)
assert.Contains(t, f.File, "internal/fxreflect/stack_test.go")
assert.NotZero(t, f.Line)
})
Expand Down
27 changes: 27 additions & 0 deletions internal/fxreflect/stack_test_120.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build !go1.21
// +build !go1.21

package fxreflect

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDeepStack(t *testing.T) {
// Introduce a few frames.
frames := func() []Frame {
return func() []Frame {
return CallerStack(0, 0)
}()
}()

require.True(t, len(frames) > 3, "expected at least three frames")

Check failure on line 20 in internal/fxreflect/stack_test_120.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.20.x)

undefined: require
for i, name := range []string{"func2.1.1", "func2.1", "func2"} {
f := frames[i]
assert.Equal(t, "go.uber.org/fx/internal/fxreflect.TestStack."+name, f.Function)
assert.Contains(t, f.File, "internal/fxreflect/stack_test.go")
assert.NotZero(t, f.Line)
}
}
28 changes: 28 additions & 0 deletions internal/fxreflect/stack_test_121.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build go1.21
// +build go1.21

package fxreflect

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDeepStack(t *testing.T) {
// Introduce a few frames.
frames := func() []Frame {
return func() []Frame {
return CallerStack(0, 0)
}()
}()

require.True(t, len(frames) > 3, "expected at least three frames")
for i, name := range []string{"func2.TestStack.func2.1.func2", "func2.1", "func2"} {
f := frames[i]
assert.Equal(t, "go.uber.org/fx/internal/fxreflect.TestStack."+name, f.Function)
assert.Contains(t, f.File, "internal/fxreflect/stack_test.go")
assert.NotZero(t, f.Line)
}
}

0 comments on commit 740db90

Please sign in to comment.