Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d182fb39 authored by Paul Duffin's avatar Paul Duffin
Browse files

Defer registration of singletons and pre-singletons in TestContext

In preparation for allowing the TestContext to enforce an ordering on
the registration of singletons and pre-singletons in the same way as it
does for mutators this defers the registration of them into the
underlying Context.

Bug: 181953909
Test: m nothing
Change-Id: I2d9652122bb6387b6b47ca4761e811885d15c2b6
parent 281deb2c
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -98,6 +98,9 @@ type TestContext struct {
	bp2buildPreArch, bp2buildDeps, bp2buildMutators []RegisterMutatorFunc
	NameResolver                                    *NameResolver

	// 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
}
@@ -343,13 +346,18 @@ func globallyRegisteredComponentsOrder() *registrationSorter {
func (ctx *TestContext) Register() {
	globalOrder := globallyRegisteredComponentsOrder()

	ctx.preSingletons.registerAll(ctx.Context)

	mutators := collateRegisteredMutators(ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps)
	// Ensure that the mutators used in the test are in the same order as they are used at runtime.
	globalOrder.mutatorOrder.enforceOrdering(mutators)
	mutators.registerAll(ctx.Context)

	// Register the env singleton with this context before sorting.
	ctx.RegisterSingletonType("env", EnvSingleton)

	ctx.singletons.registerAll(ctx.Context)

	// Save the mutator order away to make it easy to access while debugging.
	ctx.mutatorOrder = globalOrder.mutatorOrder.namesInOrder
}
@@ -382,11 +390,11 @@ func (ctx *TestContext) RegisterSingletonModuleType(name string, factory Singlet
}

func (ctx *TestContext) RegisterSingletonType(name string, factory SingletonFactory) {
	ctx.Context.RegisterSingletonType(name, SingletonFactoryAdaptor(ctx.Context, factory))
	ctx.singletons = append(ctx.singletons, newSingleton(name, factory))
}

func (ctx *TestContext) RegisterPreSingletonType(name string, factory SingletonFactory) {
	ctx.Context.RegisterPreSingletonType(name, SingletonFactoryAdaptor(ctx.Context, factory))
	ctx.preSingletons = append(ctx.preSingletons, newPreSingleton(name, factory))
}

func (ctx *TestContext) ModuleForTests(name, variant string) TestingModule {