// Generate generates suites based on passed examples
Generate generates suites based on passed examples
// Generate generates suites based on passed examples
func (g *Generator) Generate(examples ...*linker.LinkedExample) []*Suite {
	var result []*Suite
	var tests = map[string][]*Test{}
	var index = map[string]*Suite{}
	var children = map[string][]*Suite{}
	moduleName := moduleName(g.conf.OutputDir)
	for _, e := range examples {
		if e.IsLeaf() {
			_, name := path.Split(e.Name)
			for _, parent := range e.Parents {
				tests[parent.Name] = append(tests[parent.Name], &Test{
					Dir:     e.Dir,
					Name:    strings.Title(nameRegex.ReplaceAllString(name, "_")),
					Cleanup: e.Cleanup,
					Run:     e.Run,
				})
			}
			continue
		}
		var deps = Dependencies([]Dependency{Dependency(g.conf.BasePkg)})
		deps = append(deps, normalizeDeps(moduleName, e.Dependencies())...)
		var depsToSetup = Dependencies([]Dependency{Dependency(g.conf.BasePkg)})
		depsToSetup = append(depsToSetup, normalizeDeps(moduleName, e.ParentDependencies())...)
		s := &Suite{
			Dir:         e.Dir,
			Location:    filepath.Join(g.conf.OutputDir, strings.ToLower(e.Name), "suite.gen.go"),
			Dependency:  Dependency(path.Join(g.conf.OutputDir, strings.ToLower(e.Name))),
			Cleanup:     e.Cleanup,
			Run:         e.Run,
			Deps:        deps,
			DepsToSetup: depsToSetup,
		}
		for _, parent := range e.Parents {
			children[parent.Name] = append(children[parent.Name], s)
		}
		result = append(result, s)
		index[e.Name] = s
	}
	for k, v := range tests {
		index[k].Tests = append(index[k].Tests, v...)
	}
	for k, v := range children {
		index[k].Children = append(index[k].Children, v...)
	}
	return result
}
func ( g * Generator ) Generate ( examples ... * linker . LinkedExample ) [ ] * Suite { var result [ ] * Suite var tests = map [ string ] [ ] * Test { } var index = map [ string ] * Suite { } var children = map [ string ] [ ] * Suite { } moduleName := moduleName ( g . conf . OutputDir ) for _ , e := range examples { if e . IsLeaf ( ) { _ , name := path . Split ( e . Name ) for _ , parent := range e . Parents { tests [ parent . Name ] = append ( tests [ parent . Name ] , & Test { Dir : e . Dir , Name : strings . Title ( nameRegex . ReplaceAllString ( name , " " ) ) , Cleanup : e . Cleanup , Run : e . Run , } ) } continue } var deps = Dependencies ( [ ] Dependency { Dependency ( g . conf . BasePkg ) } ) deps = append ( deps , normalizeDeps ( moduleName , e . Dependencies ( ) ) ... ) var depsToSetup = Dependencies ( [ ] Dependency { Dependency ( g . conf . BasePkg ) } ) depsToSetup = append ( depsToSetup , normalizeDeps ( moduleName , e . ParentDependencies ( ) ) ... ) s := & Suite { Dir : e . Dir , Location : filepath . Join ( g . conf . OutputDir , strings . ToLower ( e . Name ) , " " ) , Dependency : Dependency ( path . Join ( g . conf . OutputDir , strings . ToLower ( e . Name ) ) ) , Cleanup : e . Cleanup , Run : e . Run , Deps : deps , DepsToSetup : depsToSetup , } for _ , parent := range e . Parents { children [ parent . Name ] = append ( children [ parent . Name ] , s ) } result = append ( result , s ) index [ e . Name ] = s } for k , v := range tests { index [ k ] . Tests = append ( index [ k ] . Tests , v ... ) } for k , v := range children { index [ k ] . Children = append ( index [ k ] . Children , v ... ) } return result }
Generate generates suites based on passed examples
Generate generates suites based on passed examples
// Dependencies to import // Parent suites to setup first // Remember if suite is a subsuite // Apply tests to the suites // Apply subsuites to the suites