How to use ParseSpecFiles method of parser Package

Best Gauge code snippet using parser.ParseSpecFiles

parse.go

Source:parse.go Github

copy

Full Screen

...31 "github.com/getgauge/gauge/logger"32 "github.com/getgauge/gauge/order"33 "github.com/getgauge/gauge/util"34)35// ParseSpecFiles gets all the spec files and parse each spec file.36// Generates specifications and parse results.37// TODO: Use single channel instead of one for spec and another for result, so that mapping is consistent38type parseInfo struct {39 parseResult *ParseResult40 spec *gauge.Specification41}42func newParseInfo(spec *gauge.Specification, pr *ParseResult) *parseInfo {43 return &parseInfo{spec: spec, parseResult: pr}44}45func parse(wg *sync.WaitGroup, sfc *specFileCollection, cpt *gauge.ConceptDictionary, piChan chan *parseInfo) {46 defer wg.Done()47 for {48 if s, err := sfc.Next(); err == nil {49 piChan <- newParseInfo(parseSpec(s, cpt))50 } else {51 return52 }53 }54}55func parseSpecFiles(sfc *specFileCollection, conceptDictionary *gauge.ConceptDictionary, piChan chan *parseInfo, limit int) {56 wg := &sync.WaitGroup{}57 for i := 0; i < limit; i++ {58 wg.Add(1)59 go parse(wg, sfc, conceptDictionary, piChan)60 }61 wg.Wait()62 close(piChan)63}64func ParseSpecFiles(specFiles []string, conceptDictionary *gauge.ConceptDictionary, buildErrors *gauge.BuildErrors) ([]*gauge.Specification, []*ParseResult) {65 sfc := NewSpecFileCollection(specFiles)66 piChan := make(chan *parseInfo)67 limit := len(specFiles)68 rLimit, e := util.RLimit()69 if e == nil && rLimit < limit {70 logger.Debugf(true, "No of specifcations %d is higher than Max no of open file descriptors %d.\n"+71 "Starting %d routines for parallel parsing.", limit, rLimit, rLimit/2)72 limit = rLimit / 273 }74 go parseSpecFiles(sfc, conceptDictionary, piChan, limit)75 var parseResults []*ParseResult76 var specs []*gauge.Specification77 for r := range piChan {78 if r.spec != nil {79 specs = append(specs, r.spec)80 var parseErrs []error81 for _, e := range r.parseResult.ParseErrors {82 parseErrs = append(parseErrs, e)83 }84 if len(parseErrs) != 0 {85 buildErrors.SpecErrs[r.spec] = parseErrs86 }87 }88 parseResults = append(parseResults, r.parseResult)89 }90 return specs, parseResults91}92// ParseSpecs parses specs in the give directory and gives specification and pass/fail status, used in validation.93func ParseSpecs(specsToParse []string, conceptsDictionary *gauge.ConceptDictionary, buildErrors *gauge.BuildErrors) ([]*gauge.Specification, bool) {94 specs, failed := parseSpecsInDirs(conceptsDictionary, specsToParse, buildErrors)95 specsToExecute := order.Sort(filter.FilterSpecs(specs))96 return specsToExecute, failed97}98// ParseConcepts creates concept dictionary and concept parse result.99func ParseConcepts() (*gauge.ConceptDictionary, *ParseResult, error) {100 logger.Debug(true, "Started concepts parsing.")101 conceptsDictionary, conceptParseResult, err := CreateConceptsDictionary()102 if err != nil {103 return nil, nil, err104 }105 HandleParseResult(conceptParseResult)106 logger.Debugf(true, "%d concepts parsing completed.", len(conceptsDictionary.ConceptsMap))107 return conceptsDictionary, conceptParseResult, nil108}109func parseSpec(specFile string, conceptDictionary *gauge.ConceptDictionary) (*gauge.Specification, *ParseResult) {110 specFileContent, err := common.ReadFileContents(specFile)111 if err != nil {112 return nil, &ParseResult{ParseErrors: []ParseError{ParseError{FileName: specFile, Message: err.Error()}}, Ok: false}113 }114 spec, parseResult, err := new(SpecParser).Parse(specFileContent, conceptDictionary, specFile)115 if err != nil {116 logger.Fatalf(true, err.Error())117 }118 return spec, parseResult119}120type specFile struct {121 filePath string122 indices []int123}124// parseSpecsInDirs parses all the specs in list of dirs given.125// It also de-duplicates all specs passed through `specDirs` before parsing specs.126func parseSpecsInDirs(conceptDictionary *gauge.ConceptDictionary, specDirs []string, buildErrors *gauge.BuildErrors) ([]*gauge.Specification, bool) {127 passed := true128 givenSpecs, specFiles := getAllSpecFiles(specDirs)129 var specs []*gauge.Specification130 var specParseResults []*ParseResult131 allSpecs := make([]*gauge.Specification, len(specFiles))132 logger.Debug(true, "Started specifications parsing.")133 specs, specParseResults = ParseSpecFiles(givenSpecs, conceptDictionary, buildErrors)134 passed = !HandleParseResult(specParseResults...) && passed135 logger.Debugf(true, "%d specifications parsing completed.", len(specFiles))136 for _, spec := range specs {137 i, _ := getIndexFor(specFiles, spec.FileName)138 specFile := specFiles[i]139 if len(specFile.indices) > 0 {140 s, _ := spec.Filter(filter.NewScenarioFilterBasedOnSpan(specFile.indices))141 allSpecs[i] = s142 } else {143 allSpecs[i] = spec144 }145 }146 return allSpecs, !passed147}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful