diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2aae83dcb..4ceae7a55 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: os: ["ubuntu-latest", "windows-latest"] - go: ["1.20.x", "1.21.x"] + go: ["1.21.x", "1.22.x"] steps: - name: Checkout code @@ -52,7 +52,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.21.x + go-version: 1.22.x - name: Test run: make cover COVER_MODULES=./docs @@ -68,7 +68,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.21.x + go-version: 1.22.x cache: false # managed by golangci-lint - uses: golangci/golangci-lint-action@v5 diff --git a/app_121_test.go b/app_121_test.go new file mode 100644 index 000000000..48c22d305 --- /dev/null +++ b/app_121_test.go @@ -0,0 +1,41 @@ +// Copyright (c) 2024 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:build !go1.22 +// +build !go1.22 + +package fx_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + . "go.uber.org/fx" +) + +func TestNopLoggerOptionString(t *testing.T) { + t.Parallel() + + assert.Equal(t, + "fx.WithLogger(go.uber.org/fx.glob..func1())", + NopLogger.String(), + ) +} diff --git a/app_122_test.go b/app_122_test.go new file mode 100644 index 000000000..2f6b91ccc --- /dev/null +++ b/app_122_test.go @@ -0,0 +1,41 @@ +// Copyright (c) 2024 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:build go1.22 +// +build go1.22 + +package fx_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + . "go.uber.org/fx" +) + +func TestNopLoggerOptionString(t *testing.T) { + t.Parallel() + + assert.Equal(t, + "fx.WithLogger(go.uber.org/fx.init.func1())", + NopLogger.String(), + ) +} diff --git a/app_test.go b/app_test.go index cc17a4f19..727828be8 100644 --- a/app_test.go +++ b/app_test.go @@ -2542,11 +2542,6 @@ func TestOptionString(t *testing.T) { give: WithLogger(func() fxevent.Logger { return testLogger{t} }), want: "fx.WithLogger(go.uber.org/fx_test.TestOptionString.func3())", }, - { - desc: "NopLogger", - give: NopLogger, - want: "fx.WithLogger(go.uber.org/fx.glob..func1())", - }, { desc: "ErrorHook", give: ErrorHook(testErrorHandler{t}), diff --git a/internal/fxreflect/stack_121_test.go b/internal/fxreflect/stack_121_test.go index 18880f0d1..832ed1b4f 100644 --- a/internal/fxreflect/stack_121_test.go +++ b/internal/fxreflect/stack_121_test.go @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -//go:build go1.21 -// +build go1.21 +//go:build (go1.21 && !go1.22) +// +build go1.21,!go1.22 package fxreflect diff --git a/internal/fxreflect/stack_122_test.go b/internal/fxreflect/stack_122_test.go new file mode 100644 index 000000000..c3976bf5f --- /dev/null +++ b/internal/fxreflect/stack_122_test.go @@ -0,0 +1,50 @@ +// Copyright (c) 2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:build go1.22 +// +build go1.22 + +package fxreflect + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestDeepStack(t *testing.T) { + t.Run("nest", func(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{"func1.TestDeepStack.func1.1.2", "func1.1", "func1"} { + f := frames[i] + assert.Equal(t, "go.uber.org/fx/internal/fxreflect.TestDeepStack."+name, f.Function) + assert.Contains(t, f.File, "internal/fxreflect/stack_122_test.go") + assert.NotZero(t, f.Line) + } + }) +}