diff --git a/internal/fxreflect/stack_test.go b/internal/fxreflect/stack_test.go index 400c7c2ba..c5eb8c949 100644 --- a/internal/fxreflect/stack_test.go +++ b/internal/fxreflect/stack_test.go @@ -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() @@ -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) }) diff --git a/internal/fxreflect/stack_test_120.go b/internal/fxreflect/stack_test_120.go new file mode 100644 index 000000000..b5e8e2f21 --- /dev/null +++ b/internal/fxreflect/stack_test_120.go @@ -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") + 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) + } +} diff --git a/internal/fxreflect/stack_test_121.go b/internal/fxreflect/stack_test_121.go new file mode 100644 index 000000000..40b03a2fe --- /dev/null +++ b/internal/fxreflect/stack_test_121.go @@ -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) + } +}