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

Blogs

Check out the latest blogs from LambdaTest on this topic:

Why Agile Is Great for Your Business

Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.

Top Programming Languages Helpful For Testers

There are many debates going on whether testers should know programming languages or not. Everyone has his own way of backing the statement. But when I went on a deep research into it, I figured out that no matter what, along with soft skills, testers must know some programming languages as well. Especially those that are popular in running automation tests.

Selenium C# Tutorial: Introduction

As per, Stack Overflow Annual Developer Survey 2019, C# is one of the most loved programming languages with 67% and is also deemed to be one of the most popular languages with 31% votes from all the respondents.

23 Node.js Best Practices For Automation Testing

If you are in the world of software development, you must be aware of Node.js. From Amazon to LinkedIn, a plethora of major websites use Node.js. Powered by JavaScript, Node.js can run on a server, and a majority of devs use it for enterprise applications. As they consider it a very respectable language due to the power it provides them to work with. And if you follow Node.js best practices, you can increase your application performance on a vast scale.

Cypress vs Selenium – Which Is Better ?

Selenium is one of the most prominent automation frameworks for functional testing and web app testing. Automation testers who use Selenium can run tests across different browser and platform combinations by leveraging an online Selenium Grid, you can learn more about what Is Selenium? Though Selenium is the go-to framework for test automation, Cypress – a relatively late entrant in the test automation game has been catching up at a breakneck pace.

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