diff --git a/integration/_fixtures/seed_fixture/seed_fixture_suite_test.go b/integration/_fixtures/seed_fixture/seed_fixture_suite_test.go new file mode 100644 index 000000000..3aed97c65 --- /dev/null +++ b/integration/_fixtures/seed_fixture/seed_fixture_suite_test.go @@ -0,0 +1,21 @@ +package seed_fixture_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestSeedFixture(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "SeedFixture Suite") +} + +var _ = BeforeSuite(func() { + Ω(GinkgoRandomSeed()).Should(Equal(int64(0))) +}) + +var _ = It("has the expected seed (namely, 0)", func() { + Ω(GinkgoRandomSeed()).Should(Equal(int64(0))) +}) diff --git a/integration/flags_test.go b/integration/flags_test.go index 18fcdea9b..5c4e6f31e 100644 --- a/integration/flags_test.go +++ b/integration/flags_test.go @@ -66,6 +66,12 @@ var _ = Describe("Flags Specs", func() { Ω(orders[0]).ShouldNot(BeNumerically("<", orders[1])) }) + It("should consistently pass in a zero seed when asked to", func() { + fm.MountFixture("seed") + session := startGinkgo(fm.PathTo("seed"), "--no-color", "--seed=0", "--nodes=2") + Eventually(session).Should(gexec.Exit(0)) + }) + It("should pass additional arguments in", func() { session := startGinkgo(fm.PathTo("flags"), "--", "--customFlag=madagascar") Eventually(session).Should(gexec.Exit(1)) diff --git a/types/config.go b/types/config.go index 7c82065df..cef273ee1 100644 --- a/types/config.go +++ b/types/config.go @@ -265,7 +265,7 @@ var FlagSections = GinkgoFlagSections{ // SuiteConfigFlags provides flags for the Ginkgo test process, and CLI var SuiteConfigFlags = GinkgoFlags{ {KeyPath: "S.RandomSeed", Name: "seed", SectionKey: "order", UsageDefaultValue: "randomly generated by Ginkgo", - Usage: "The seed used to randomize the spec suite."}, + Usage: "The seed used to randomize the spec suite.", AlwaysExport: true}, {KeyPath: "S.RandomizeAllSpecs", Name: "randomize-all", SectionKey: "order", DeprecatedName: "randomizeAllSpecs", DeprecatedDocLink: "changed-command-line-flags", Usage: "If set, ginkgo will randomize all specs together. By default, ginkgo only randomizes the top level Describe, Context and When containers."}, diff --git a/types/flags.go b/types/flags.go index 9186ae873..de69f3022 100644 --- a/types/flags.go +++ b/types/flags.go @@ -24,7 +24,8 @@ type GinkgoFlag struct { DeprecatedDocLink string DeprecatedVersion string - ExportAs string + ExportAs string + AlwaysExport bool } type GinkgoFlags []GinkgoFlag @@ -431,7 +432,7 @@ func (ssv stringSliceVar) Set(s string) error { return nil } -//given a set of GinkgoFlags and bindings, generate flag arguments suitable to be passed to an application with that set of flags configured. +// given a set of GinkgoFlags and bindings, generate flag arguments suitable to be passed to an application with that set of flags configured. func GenerateFlagArgs(flags GinkgoFlags, bindings interface{}) ([]string, error) { result := []string{} for _, flag := range flags { @@ -451,19 +452,19 @@ func GenerateFlagArgs(flags GinkgoFlags, bindings interface{}) ([]string, error) iface := value.Interface() switch value.Type() { case reflect.TypeOf(string("")): - if iface.(string) != "" { + if iface.(string) != "" || flag.AlwaysExport { result = append(result, fmt.Sprintf("--%s=%s", name, iface)) } case reflect.TypeOf(int64(0)): - if iface.(int64) != 0 { + if iface.(int64) != 0 || flag.AlwaysExport { result = append(result, fmt.Sprintf("--%s=%d", name, iface)) } case reflect.TypeOf(float64(0)): - if iface.(float64) != 0 { + if iface.(float64) != 0 || flag.AlwaysExport { result = append(result, fmt.Sprintf("--%s=%f", name, iface)) } case reflect.TypeOf(int(0)): - if iface.(int) != 0 { + if iface.(int) != 0 || flag.AlwaysExport { result = append(result, fmt.Sprintf("--%s=%d", name, iface)) } case reflect.TypeOf(bool(true)): @@ -471,7 +472,7 @@ func GenerateFlagArgs(flags GinkgoFlags, bindings interface{}) ([]string, error) result = append(result, fmt.Sprintf("--%s", name)) } case reflect.TypeOf(time.Duration(0)): - if iface.(time.Duration) != time.Duration(0) { + if iface.(time.Duration) != time.Duration(0) || flag.AlwaysExport { result = append(result, fmt.Sprintf("--%s=%s", name, iface)) } diff --git a/types/flags_test.go b/types/flags_test.go index 17d52ad28..11d9ff55a 100644 --- a/types/flags_test.go +++ b/types/flags_test.go @@ -427,10 +427,10 @@ var _ = Describe("Flags", func() { } flags = types.GinkgoFlags{ {Name: "string-flag", KeyPath: "A.StringProperty", DeprecatedName: "stringFlag"}, - {Name: "int-64-flag", KeyPath: "A.Int64Property"}, + {Name: "int-64-flag", KeyPath: "A.Int64Property", AlwaysExport: true}, {Name: "float-64-flag", KeyPath: "A.Float64Property"}, {Name: "int-flag", KeyPath: "B.IntProperty", ExportAs: "alias-int-flag"}, - {Name: "bool-flag", KeyPath: "B.BoolProperty", ExportAs: "alias-bool-flag"}, + {Name: "bool-flag", KeyPath: "B.BoolProperty", ExportAs: "alias-bool-flag", AlwaysExport: true}, {Name: "string-slice-flag", KeyPath: "B.StringSliceProperty"}, {DeprecatedName: "deprecated-flag", KeyPath: "B.DeprecatedProperty"}, } @@ -452,6 +452,24 @@ var _ = Describe("Flags", func() { })) }) + It("does not include 0 values unless AlwaysExport is true", func() { + A.StringProperty = "" + A.Int64Property = 0 + B.IntProperty = 0 + B.BoolProperty = false + + args, err := types.GenerateFlagArgs(flags, bindings) + Ω(err).ShouldNot(HaveOccurred()) + + Ω(args).Should(Equal([]string{ + "--int-64-flag=0", //always export + "--float-64-flag=3.141000", + "--string-slice-flag=once", + "--string-slice-flag=upon", + "--string-slice-flag=a time", + })) + }) + It("errors if there is a keypath issue", func() { flags[0] = types.GinkgoFlag{Name: "unsupported-type", KeyPath: "A.UnsupportedInt32"} args, err := types.GenerateFlagArgs(flags, bindings)