Add a test for AddNinjaFileDeps

Add a test for all the contexts that call AddNinjaFileDeps to ensure
they are propagated back to the main method.

Bug: 188547846
Test: TestAddNinjaFileDeps
Change-Id: Iaab32b8237eecee07fb930f2f9fe337c7d4e047c
This commit is contained in:
Colin Cross 2021-05-24 16:55:28 -07:00
parent 0f0e304d08
commit 7a2a352825

View file

@ -531,3 +531,103 @@ test2 {
)
})
}
type addNinjaDepsTestModule struct {
SimpleName
}
func addNinjaDepsTestModuleFactory() (Module, []interface{}) {
module := &addNinjaDepsTestModule{}
AddLoadHook(module, func(ctx LoadHookContext) {
ctx.AddNinjaFileDeps("LoadHookContext")
})
return module, []interface{}{&module.SimpleName.Properties}
}
func (m *addNinjaDepsTestModule) GenerateBuildActions(ctx ModuleContext) {
ctx.AddNinjaFileDeps("GenerateBuildActions")
}
func addNinjaDepsTestBottomUpMutator(ctx BottomUpMutatorContext) {
ctx.AddNinjaFileDeps("BottomUpMutator")
}
func addNinjaDepsTestTopDownMutator(ctx TopDownMutatorContext) {
ctx.AddNinjaFileDeps("TopDownMutator")
}
type addNinjaDepsTestPreSingleton struct{}
func addNinjaDepsTestPreSingletonFactory() Singleton {
return &addNinjaDepsTestPreSingleton{}
}
func (s *addNinjaDepsTestPreSingleton) GenerateBuildActions(ctx SingletonContext) {
ctx.AddNinjaFileDeps("PreSingleton")
}
type addNinjaDepsTestSingleton struct{}
func addNinjaDepsTestSingletonFactory() Singleton {
return &addNinjaDepsTestSingleton{}
}
func (s *addNinjaDepsTestSingleton) GenerateBuildActions(ctx SingletonContext) {
ctx.AddNinjaFileDeps("Singleton")
}
func TestAddNinjaFileDeps(t *testing.T) {
ctx := NewContext()
ctx.MockFileSystem(map[string][]byte{
"Blueprints": []byte(`
test {
name: "test",
}
`),
})
ctx.RegisterModuleType("test", addNinjaDepsTestModuleFactory)
ctx.RegisterBottomUpMutator("testBottomUpMutator", addNinjaDepsTestBottomUpMutator)
ctx.RegisterTopDownMutator("testTopDownMutator", addNinjaDepsTestTopDownMutator)
ctx.RegisterPreSingletonType("testPreSingleton", addNinjaDepsTestPreSingletonFactory)
ctx.RegisterSingletonType("testSingleton", addNinjaDepsTestSingletonFactory)
parseDeps, errs := ctx.ParseBlueprintsFiles("Blueprints", nil)
if len(errs) > 0 {
t.Errorf("unexpected parse errors:")
for _, err := range errs {
t.Errorf(" %s", err)
}
t.FailNow()
}
resolveDeps, errs := ctx.ResolveDependencies(nil)
if len(errs) > 0 {
t.Errorf("unexpected dep errors:")
for _, err := range errs {
t.Errorf(" %s", err)
}
t.FailNow()
}
prepareDeps, errs := ctx.PrepareBuildActions(nil)
if len(errs) > 0 {
t.Errorf("unexpected prepare errors:")
for _, err := range errs {
t.Errorf(" %s", err)
}
t.FailNow()
}
if g, w := parseDeps, []string{"Blueprints", "LoadHookContext"}; !reflect.DeepEqual(g, w) {
t.Errorf("ParseBlueprintsFiles: wanted deps %q, got %q", w, g)
}
if g, w := resolveDeps, []string{"PreSingleton", "BottomUpMutator", "TopDownMutator"}; !reflect.DeepEqual(g, w) {
t.Errorf("ResolveDependencies: wanted deps %q, got %q", w, g)
}
if g, w := prepareDeps, []string{"GenerateBuildActions", "Singleton"}; !reflect.DeepEqual(g, w) {
t.Errorf("PrepareBuildActions: wanted deps %q, got %q", w, g)
}
}