Loading android/testing.go +24 −3 Original line number Diff line number Diff line Loading @@ -101,8 +101,9 @@ type TestContext struct { // The list of pre-singletons and singletons registered for the test. preSingletons, singletons sortableComponents // The order in which the mutators will be run in this test context; for debugging. mutatorOrder []string // The order in which the pre-singletons, mutators and singletons will be run in this test // context; for debugging. preSingletonOrder, mutatorOrder, singletonOrder []string } func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) { Loading Loading @@ -315,8 +316,14 @@ type registrationSorter struct { // Used to ensure that this is only created once. once sync.Once // The order of pre-singletons preSingletonOrder registeredComponentOrder // The order of mutators mutatorOrder registeredComponentOrder // The order of singletons singletonOrder registeredComponentOrder } // populate initializes this structure from globally registered build components. Loading @@ -324,9 +331,16 @@ type registrationSorter struct { // Only the first call has any effect. func (s *registrationSorter) populate() { s.once.Do(func() { // Create an ordering from the globally registered pre-singletons. s.preSingletonOrder = registeredComponentOrderFromExistingOrder("pre-singleton", preSingletons) // Created an ordering from the globally registered mutators. globallyRegisteredMutators := collateGloballyRegisteredMutators() s.mutatorOrder = registeredComponentOrderFromExistingOrder("mutator", globallyRegisteredMutators) // Create an ordering from the globally registered singletons. globallyRegisteredSingletons := collateGloballyRegisteredSingletons() s.singletonOrder = registeredComponentOrderFromExistingOrder("singleton", globallyRegisteredSingletons) }) } Loading @@ -346,6 +360,9 @@ func globallyRegisteredComponentsOrder() *registrationSorter { func (ctx *TestContext) Register() { globalOrder := globallyRegisteredComponentsOrder() // Ensure that the pre-singletons used in the test are in the same order as they are used at // runtime. globalOrder.preSingletonOrder.enforceOrdering(ctx.preSingletons) ctx.preSingletons.registerAll(ctx.Context) mutators := collateRegisteredMutators(ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps) Loading @@ -356,10 +373,14 @@ func (ctx *TestContext) Register() { // Register the env singleton with this context before sorting. ctx.RegisterSingletonType("env", EnvSingleton) // Ensure that the singletons used in the test are in the same order as they are used at runtime. globalOrder.singletonOrder.enforceOrdering(ctx.singletons) ctx.singletons.registerAll(ctx.Context) // Save the mutator order away to make it easy to access while debugging. // Save the sorted components order away to make them easy to access while debugging. ctx.preSingletonOrder = globalOrder.preSingletonOrder.namesInOrder ctx.mutatorOrder = globalOrder.mutatorOrder.namesInOrder ctx.singletonOrder = globalOrder.singletonOrder.namesInOrder } // RegisterForBazelConversion prepares a test context for bp2build conversion. Loading Loading
android/testing.go +24 −3 Original line number Diff line number Diff line Loading @@ -101,8 +101,9 @@ type TestContext struct { // The list of pre-singletons and singletons registered for the test. preSingletons, singletons sortableComponents // The order in which the mutators will be run in this test context; for debugging. mutatorOrder []string // The order in which the pre-singletons, mutators and singletons will be run in this test // context; for debugging. preSingletonOrder, mutatorOrder, singletonOrder []string } func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) { Loading Loading @@ -315,8 +316,14 @@ type registrationSorter struct { // Used to ensure that this is only created once. once sync.Once // The order of pre-singletons preSingletonOrder registeredComponentOrder // The order of mutators mutatorOrder registeredComponentOrder // The order of singletons singletonOrder registeredComponentOrder } // populate initializes this structure from globally registered build components. Loading @@ -324,9 +331,16 @@ type registrationSorter struct { // Only the first call has any effect. func (s *registrationSorter) populate() { s.once.Do(func() { // Create an ordering from the globally registered pre-singletons. s.preSingletonOrder = registeredComponentOrderFromExistingOrder("pre-singleton", preSingletons) // Created an ordering from the globally registered mutators. globallyRegisteredMutators := collateGloballyRegisteredMutators() s.mutatorOrder = registeredComponentOrderFromExistingOrder("mutator", globallyRegisteredMutators) // Create an ordering from the globally registered singletons. globallyRegisteredSingletons := collateGloballyRegisteredSingletons() s.singletonOrder = registeredComponentOrderFromExistingOrder("singleton", globallyRegisteredSingletons) }) } Loading @@ -346,6 +360,9 @@ func globallyRegisteredComponentsOrder() *registrationSorter { func (ctx *TestContext) Register() { globalOrder := globallyRegisteredComponentsOrder() // Ensure that the pre-singletons used in the test are in the same order as they are used at // runtime. globalOrder.preSingletonOrder.enforceOrdering(ctx.preSingletons) ctx.preSingletons.registerAll(ctx.Context) mutators := collateRegisteredMutators(ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps) Loading @@ -356,10 +373,14 @@ func (ctx *TestContext) Register() { // Register the env singleton with this context before sorting. ctx.RegisterSingletonType("env", EnvSingleton) // Ensure that the singletons used in the test are in the same order as they are used at runtime. globalOrder.singletonOrder.enforceOrdering(ctx.singletons) ctx.singletons.registerAll(ctx.Context) // Save the mutator order away to make it easy to access while debugging. // Save the sorted components order away to make them easy to access while debugging. ctx.preSingletonOrder = globalOrder.preSingletonOrder.namesInOrder ctx.mutatorOrder = globalOrder.mutatorOrder.namesInOrder ctx.singletonOrder = globalOrder.singletonOrder.namesInOrder } // RegisterForBazelConversion prepares a test context for bp2build conversion. Loading