From 1ba25d7050cae6f1e6d36f515acdf00677ca06e9 Mon Sep 17 00:00:00 2001 From: Rudolph Jacobs Date: Tue, 21 Jan 2025 17:40:32 +0200 Subject: [PATCH] Fix binary paths when precompiling multiple suites. --- ginkgo/build/build_command.go | 12 +++++++----- .../suite1/build_reporting_1_suite_test.go | 13 +++++++++++++ .../suite1/build_reporting_1_test.go | 18 ++++++++++++++++++ .../suite2/build_reporting_2_suite_test.go | 13 +++++++++++++ .../suite2/build_reporting_2_test.go | 18 ++++++++++++++++++ integration/precompiled_test.go | 13 +++++++++++++ 6 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 integration/_fixtures/build_reporting_fixture/suite1/build_reporting_1_suite_test.go create mode 100644 integration/_fixtures/build_reporting_fixture/suite1/build_reporting_1_test.go create mode 100644 integration/_fixtures/build_reporting_fixture/suite2/build_reporting_2_suite_test.go create mode 100644 integration/_fixtures/build_reporting_fixture/suite2/build_reporting_2_test.go diff --git a/ginkgo/build/build_command.go b/ginkgo/build/build_command.go index fd17260843..c390be140a 100644 --- a/ginkgo/build/build_command.go +++ b/ginkgo/build/build_command.go @@ -55,18 +55,20 @@ func buildSpecs(args []string, cliConfig types.CLIConfig, goFlagsConfig types.Go if suite.State.Is(internal.TestSuiteStateFailedToCompile) { fmt.Println(suite.CompilationError.Error()) } else { - if len(goFlagsConfig.O) == 0 { - goFlagsConfig.O = path.Join(suite.Path, suite.PackageName+".test") - } else { + var testBinPath string + if len(goFlagsConfig.O) != 0 { stat, err := os.Stat(goFlagsConfig.O) if err != nil { panic(err) } if stat.IsDir() { - goFlagsConfig.O += "/" + suite.PackageName + ".test" + testBinPath = "/" + suite.PackageName + ".test" } } - fmt.Printf("Compiled %s\n", goFlagsConfig.O) + if len(testBinPath) == 0 { + testBinPath = path.Join(suite.Path, suite.PackageName+".test") + } + fmt.Printf("Compiled %s\n", testBinPath) } } diff --git a/integration/_fixtures/build_reporting_fixture/suite1/build_reporting_1_suite_test.go b/integration/_fixtures/build_reporting_fixture/suite1/build_reporting_1_suite_test.go new file mode 100644 index 0000000000..508afaf32b --- /dev/null +++ b/integration/_fixtures/build_reporting_fixture/suite1/build_reporting_1_suite_test.go @@ -0,0 +1,13 @@ +package suite1_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "testing" +) + +func TestAfterRunHook(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Build reporting suite 1") +} diff --git a/integration/_fixtures/build_reporting_fixture/suite1/build_reporting_1_test.go b/integration/_fixtures/build_reporting_fixture/suite1/build_reporting_1_test.go new file mode 100644 index 0000000000..9e8f654cc3 --- /dev/null +++ b/integration/_fixtures/build_reporting_fixture/suite1/build_reporting_1_test.go @@ -0,0 +1,18 @@ +package suite1_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("Testing", func() { + It("it should succeed", func() { + Ω(true).Should(Equal(true)) + }) + + PIt("a failing test", func() { + It("should fail", func() { + Ω(true).Should(Equal(false)) + }) + }) +}) diff --git a/integration/_fixtures/build_reporting_fixture/suite2/build_reporting_2_suite_test.go b/integration/_fixtures/build_reporting_fixture/suite2/build_reporting_2_suite_test.go new file mode 100644 index 0000000000..95c722e77c --- /dev/null +++ b/integration/_fixtures/build_reporting_fixture/suite2/build_reporting_2_suite_test.go @@ -0,0 +1,13 @@ +package suite2_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "testing" +) + +func TestAfterRunHook(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Build reporting suite 1") +} diff --git a/integration/_fixtures/build_reporting_fixture/suite2/build_reporting_2_test.go b/integration/_fixtures/build_reporting_fixture/suite2/build_reporting_2_test.go new file mode 100644 index 0000000000..061a807e2f --- /dev/null +++ b/integration/_fixtures/build_reporting_fixture/suite2/build_reporting_2_test.go @@ -0,0 +1,18 @@ +package suite2_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("Testing", func() { + It("it should succeed", func() { + Ω(true).Should(Equal(true)) + }) + + PIt("a failing test", func() { + It("should fail", func() { + Ω(true).Should(Equal(false)) + }) + }) +}) diff --git a/integration/precompiled_test.go b/integration/precompiled_test.go index b11c79a2e4..2ca71601d1 100644 --- a/integration/precompiled_test.go +++ b/integration/precompiled_test.go @@ -48,6 +48,19 @@ var _ = Describe("ginkgo build", func() { }) }) +var _ = Describe("ginkgo build with multiple suites", Label("build"), func() { + It("should correctly report multiple test binaries", func() { + fm.MountFixture("build_reporting") + session := startGinkgo(fm.PathTo("build_reporting"), "build", "-r") + Eventually(session).Should(gexec.Exit(0)) + output := string(session.Out.Contents()) + Ω(output).Should(ContainSubstring("Compiled suite1/suite1.test")) + Ω(output).Should(ContainSubstring("Compiled suite2/suite2.test")) + Ω(fm.PathTo("build_reporting", "suite1", "suite1.test")).Should(BeAnExistingFile()) + Ω(fm.PathTo("build_reporting", "suite2", "suite2.test")).Should(BeAnExistingFile()) + }) +}) + var _ = Describe("ginkgo build with custom output", Label("build"), func() { const customPath = "mycustomdir" var fullPath string