How to use OnSpecFileModify method of infoGatherer Package

Best Gauge code snippet using infoGatherer.OnSpecFileModify

apiMessageHandler.go

Source:apiMessageHandler.go Github

copy

Full Screen

...200 }201 }202 for _, file := range files {203 if util.IsSpec(file) {204 handler.specInfoGatherer.OnSpecFileModify(file)205 }206 }207}208func (handler *gaugeAPIMessageHandler) extractConcept(message *gauge_messages.APIMessage) *gauge_messages.APIMessage {209 request := message.GetExtractConceptRequest()210 success, err, filesChanged := conceptExtractor.ExtractConcept(request.GetConceptName(), request.GetSteps(), request.GetConceptFileName(), request.GetChangeAcrossProject(), request.GetSelectedTextInfo())211 response := &gauge_messages.ExtractConceptResponse{IsSuccess: success, Error: err.Error(), FilesChanged: filesChanged}212 return &gauge_messages.APIMessage{MessageId: message.MessageId, MessageType: gauge_messages.APIMessage_ExtractConceptResponse, ExtractConceptResponse: response}213}214func (handler *gaugeAPIMessageHandler) formatSpecs(message *gauge_messages.APIMessage) *gauge_messages.APIMessage {215 request := message.GetFormatSpecsRequest()216 results := formatter.FormatSpecFiles(request.GetSpecs()...)217 var warnings []string218 var errors []string...

Full Screen

Full Screen

specDetails.go

Source:specDetails.go Github

copy

Full Screen

1// Copyright 2015 ThoughtWorks, Inc.2// This file is part of Gauge.3// Gauge is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7// Gauge is distributed in the hope that it will be useful,8// but WITHOUT ANY WARRANTY; without even the implied warranty of9// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10// GNU General Public License for more details.11// You should have received a copy of the GNU General Public License12// along with Gauge. If not, see <http://www.gnu.org/licenses/>.13package infoGatherer14import (15 "io/ioutil"16 "path/filepath"17 "sync"18 "os"19 "github.com/fsnotify/fsnotify"20 "github.com/getgauge/common"21 "github.com/getgauge/gauge/config"22 "github.com/getgauge/gauge/gauge"23 "github.com/getgauge/gauge/gauge_messages"24 "github.com/getgauge/gauge/logger"25 "github.com/getgauge/gauge/parser"26 "github.com/getgauge/gauge/util"27)28// SpecInfoGatherer contains the caches for specs, concepts, and steps29type SpecInfoGatherer struct {30 waitGroup sync.WaitGroup31 mutex sync.Mutex32 conceptDictionary *gauge.ConceptDictionary33 specsCache map[string]*SpecDetail34 conceptsCache map[string][]*gauge.Concept35 stepsCache map[string]*gauge.StepValue36 SpecDirs []string37}38type SpecDetail struct {39 Spec *gauge.Specification40 Errs []parser.ParseError41}42func (d *SpecDetail) HasSpec() bool {43 return d.Spec != nil && d.Spec.Heading != nil44}45// MakeListOfAvailableSteps initializes all the SpecInfoGatherer caches46func (s *SpecInfoGatherer) MakeListOfAvailableSteps() {47 go s.watchForFileChanges()48 s.waitGroup.Wait()49 // Concepts parsed first because we need to create a concept dictionary that spec parsing can use50 s.waitGroup.Add(3)51 s.initConceptsCache()52 s.initSpecsCache()53 s.initStepsCache()54}55func (s *SpecInfoGatherer) initSpecsCache() {56 defer s.waitGroup.Done()57 s.specsCache = make(map[string]*SpecDetail, 0)58 details := s.getParsedSpecs(getSpecFiles(s.SpecDirs))59 logger.APILog.Info("Initializing specs cache with %d specs", len(details))60 for _, d := range details {61 logger.APILog.Debug("Adding specs from %s", d.Spec.FileName)62 s.addToSpecsCache(d.Spec.FileName, d)63 }64}65func getSpecFiles(specs []string) []string {66 var specFiles []string67 for _, dir := range specs {68 specFiles = append(specFiles, util.FindSpecFilesIn(dir)...)69 }70 return specFiles71}72func (s *SpecInfoGatherer) initConceptsCache() {73 defer s.waitGroup.Done()74 s.conceptsCache = make(map[string][]*gauge.Concept, 0)75 parsedConcepts := s.getParsedConcepts()76 logger.APILog.Info("Initializing concepts cache with %d concepts", len(parsedConcepts))77 for _, concept := range parsedConcepts {78 logger.APILog.Debug("Adding concepts from %s", concept.FileName)79 s.addToConceptsCache(concept.FileName, concept)80 }81}82func (s *SpecInfoGatherer) initStepsCache() {83 defer s.waitGroup.Done()84 s.stepsCache = make(map[string]*gauge.StepValue, 0)85 stepsFromSpecs := s.getStepsFromCachedSpecs()86 stepsFromConcepts := s.getStepsFromCachedConcepts()87 allSteps := append(stepsFromSpecs, stepsFromConcepts...)88 logger.APILog.Info("Initializing steps cache with %d steps", len(allSteps))89 s.addToStepsCache(allSteps)90}91func (s *SpecInfoGatherer) addToSpecsCache(key string, value *SpecDetail) {92 s.mutex.Lock()93 s.specsCache[key] = value94 s.mutex.Unlock()95}96func (s *SpecInfoGatherer) addToConceptsCache(key string, value *gauge.Concept) {97 s.mutex.Lock()98 if s.conceptsCache[key] == nil {99 s.conceptsCache[key] = make([]*gauge.Concept, 0)100 }101 s.conceptsCache[key] = append(s.conceptsCache[key], value)102 s.mutex.Unlock()103}104func (s *SpecInfoGatherer) addToStepsCache(allSteps []*gauge.StepValue) {105 s.mutex.Lock()106 for _, step := range allSteps {107 if _, ok := s.stepsCache[step.StepValue]; !ok {108 s.stepsCache[step.StepValue] = step109 }110 }111 s.mutex.Unlock()112}113func (s *SpecInfoGatherer) getParsedSpecs(specFiles []string) []*SpecDetail {114 if s.conceptDictionary == nil {115 s.conceptDictionary = gauge.NewConceptDictionary()116 }117 parsedSpecs, parseResults := parser.ParseSpecFiles(specFiles, s.conceptDictionary, gauge.NewBuildErrors())118 specs := make(map[string]*SpecDetail)119 for _, spec := range parsedSpecs {120 specs[spec.FileName] = &SpecDetail{Spec: spec}121 }122 for _, v := range parseResults {123 _, ok := specs[v.FileName]124 if !ok {125 specs[v.FileName] = &SpecDetail{Spec: &gauge.Specification{FileName: v.FileName}}126 }127 specs[v.FileName].Errs = append(v.CriticalErrors, v.ParseErrors...)128 }129 details := make([]*SpecDetail, 0)130 for _, d := range specs {131 details = append(details, d)132 }133 return details134}135func (s *SpecInfoGatherer) getParsedConcepts() map[string]*gauge.Concept {136 var result *parser.ParseResult137 s.conceptDictionary, result = parser.CreateConceptsDictionary()138 handleParseFailures([]*parser.ParseResult{result})139 return s.conceptDictionary.ConceptsMap140}141func (s *SpecInfoGatherer) getStepsFromCachedSpecs() []*gauge.StepValue {142 var stepValues []*gauge.StepValue143 s.mutex.Lock()144 for _, detail := range s.specsCache {145 stepValues = append(stepValues, getStepsFromSpec(detail.Spec)...)146 }147 s.mutex.Unlock()148 return stepValues149}150func (s *SpecInfoGatherer) getStepsFromCachedConcepts() []*gauge.StepValue {151 var stepValues []*gauge.StepValue152 s.mutex.Lock()153 for _, conceptList := range s.conceptsCache {154 for _, concept := range conceptList {155 stepValues = append(stepValues, getStepsFromConcept(concept)...)156 }157 }158 s.mutex.Unlock()159 return stepValues160}161func (s *SpecInfoGatherer) onSpecFileModify(file string) {162 s.waitGroup.Add(1)163 defer s.waitGroup.Done()164 logger.APILog.Info("Spec file added / modified: %s", file)165 details := s.getParsedSpecs([]string{file})166 s.addToSpecsCache(file, details[0])167 stepsFromSpec := getStepsFromSpec(details[0].Spec)168 s.addToStepsCache(stepsFromSpec)169}170func (s *SpecInfoGatherer) onConceptFileModify(file string) {171 s.waitGroup.Add(1)172 defer s.waitGroup.Done()173 logger.APILog.Info("Concept file added / modified: %s", file)174 conceptParser := new(parser.ConceptParser)175 concepts, parseResults := conceptParser.ParseFile(file)176 if parseResults != nil && len(parseResults.ParseErrors) > 0 {177 for _, err := range parseResults.ParseErrors {178 logger.APILog.Error("Error parsing concepts: ", err)179 }180 return181 }182 for _, concept := range concepts {183 c := gauge.Concept{ConceptStep: concept, FileName: file}184 s.addToConceptsCache(file, &c)185 stepsFromConcept := getStepsFromConcept(&c)186 s.addToStepsCache(stepsFromConcept)187 }188}189func (s *SpecInfoGatherer) onSpecFileRemove(file string) {190 s.waitGroup.Add(1)191 defer s.waitGroup.Done()192 logger.APILog.Info("Spec file removed: %s", file)193 s.mutex.Lock()194 delete(s.specsCache, file)195 s.mutex.Unlock()196}197func (s *SpecInfoGatherer) onConceptFileRemove(file string) {198 s.waitGroup.Add(1)199 defer s.waitGroup.Done()200 logger.APILog.Info("Concept file removed: %s", file)201 s.mutex.Lock()202 delete(s.conceptsCache, file)203 s.mutex.Unlock()204}205func (s *SpecInfoGatherer) onFileAdd(watcher *fsnotify.Watcher, file string) {206 if util.IsDir(file) {207 addDirToFileWatcher(watcher, file)208 }209 s.onFileModify(watcher, file)210}211func (s *SpecInfoGatherer) onFileModify(watcher *fsnotify.Watcher, file string) {212 if util.IsSpec(file) {213 s.onSpecFileModify(file)214 } else if util.IsConcept(file) {215 s.onConceptFileModify(file)216 }217}218func (s *SpecInfoGatherer) onFileRemove(watcher *fsnotify.Watcher, file string) {219 if util.IsSpec(file) {220 s.onSpecFileRemove(file)221 } else if util.IsConcept(file) {222 s.onConceptFileRemove(file)223 } else {224 removeWatcherOn(watcher, file)225 }226}227func (s *SpecInfoGatherer) onFileRename(watcher *fsnotify.Watcher, file string) {228 s.onFileRemove(watcher, file)229}230func (s *SpecInfoGatherer) handleEvent(event fsnotify.Event, watcher *fsnotify.Watcher) {231 s.waitGroup.Wait()232 file, err := filepath.Abs(event.Name)233 if err != nil {234 logger.APILog.Error("Failed to get abs file path for %s: %s", event.Name, err)235 return236 }237 if util.IsSpec(file) || util.IsConcept(file) || util.IsDir(file) {238 switch event.Op {239 case fsnotify.Create:240 s.onFileAdd(watcher, file)241 case fsnotify.Write:242 s.onFileModify(watcher, file)243 case fsnotify.Rename:244 s.onFileRename(watcher, file)245 case fsnotify.Remove:246 s.onFileRemove(watcher, file)247 }248 }249}250func (s *SpecInfoGatherer) watchForFileChanges() {251 s.waitGroup.Add(1)252 watcher, err := fsnotify.NewWatcher()253 if err != nil {254 logger.APILog.Error("Error creating fileWatcher: %s", err)255 }256 defer watcher.Close()257 done := make(chan bool)258 go func() {259 for {260 select {261 case event := <-watcher.Events:262 s.handleEvent(event, watcher)263 case err := <-watcher.Errors:264 logger.APILog.Error("Error event while watching specs", err)265 }266 }267 }()268 var allDirsToWatch []string269 var specDir string270 for _, dir := range s.SpecDirs {271 specDir = filepath.Join(config.ProjectRoot, dir)272 allDirsToWatch = append(allDirsToWatch, specDir)273 allDirsToWatch = append(allDirsToWatch, util.FindAllNestedDirs(specDir)...)274 }275 for _, dir := range allDirsToWatch {276 addDirToFileWatcher(watcher, dir)277 }278 s.waitGroup.Done()279 <-done280}281// GetAvailableSpecs returns the list of all the specs in the gauge project282func (s *SpecInfoGatherer) GetAvailableSpecDetails(specs []string) []*SpecDetail {283 if len(specs) < 1 {284 specs = []string{common.SpecsDirectoryName}285 }286 specFiles := getSpecFiles(specs)287 s.waitGroup.Wait()288 var details []*SpecDetail289 s.mutex.Lock()290 for _, f := range specFiles {291 if d, ok := s.specsCache[f]; ok {292 details = append(details, d)293 }294 }295 s.mutex.Unlock()296 return details297}298// GetAvailableSteps returns the list of all the steps in the gauge project299func (s *SpecInfoGatherer) GetAvailableSteps() []*gauge.StepValue {300 s.waitGroup.Wait()301 var steps []*gauge.StepValue302 s.mutex.Lock()303 for _, stepValue := range s.stepsCache {304 steps = append(steps, stepValue)305 }306 s.mutex.Unlock()307 return steps308}309// GetConceptInfos returns an array containing information about all the concepts present in the Gauge project310func (s *SpecInfoGatherer) GetConceptInfos() []*gauge_messages.ConceptInfo {311 s.waitGroup.Wait()312 var conceptInfos []*gauge_messages.ConceptInfo313 s.mutex.Lock()314 for _, conceptList := range s.conceptsCache {315 for _, concept := range conceptList {316 stepValue := parser.CreateStepValue(concept.ConceptStep)317 conceptInfos = append(conceptInfos, &gauge_messages.ConceptInfo{StepValue: gauge.ConvertToProtoStepValue(&stepValue), Filepath: concept.FileName, LineNumber: int32(concept.ConceptStep.LineNo)})318 }319 }320 s.mutex.Unlock()321 return conceptInfos322}323func getStepsFromSpec(spec *gauge.Specification) []*gauge.StepValue {324 stepValues := getParsedStepValues(spec.Contexts)325 for _, scenario := range spec.Scenarios {326 stepValues = append(stepValues, getParsedStepValues(scenario.Steps)...)327 }328 return stepValues329}330func getStepsFromConcept(concept *gauge.Concept) []*gauge.StepValue {331 return getParsedStepValues(concept.ConceptStep.ConceptSteps)332}333func getParsedStepValues(steps []*gauge.Step) []*gauge.StepValue {334 var stepValues []*gauge.StepValue335 for _, step := range steps {336 if !step.IsConcept {337 stepValue := parser.CreateStepValue(step)338 stepValues = append(stepValues, &stepValue)339 }340 }341 return stepValues342}343func handleParseFailures(parseResults []*parser.ParseResult) {344 for _, result := range parseResults {345 if !result.Ok {346 logger.APILog.Error("Spec Parse failure: %s", result.Errors())347 if len(result.CriticalErrors) > 0 {348 os.Exit(1)349 }350 }351 }352}353func addDirToFileWatcher(watcher *fsnotify.Watcher, dir string) {354 err := watcher.Add(dir)355 if err != nil {356 logger.APILog.Error("Unable to add directory %v to file watcher: %s", dir, err)357 } else {358 logger.APILog.Info("Watching directory: %s", dir)359 files, _ := ioutil.ReadDir(dir)360 logger.APILog.Debug("Found %d files", len(files))361 }362}363func removeWatcherOn(watcher *fsnotify.Watcher, path string) {364 logger.APILog.Info("Removing watcher on : %s", path)365 watcher.Remove(path)366}...

Full Screen

Full Screen

OnSpecFileModify

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if len(os.Args) < 2 {4 fmt.Println("Usage: ", filepath.Base(os.Args[0]), "directory")5 os.Exit(1)6 }7 info := infoGatherer{}8 info.OnSpecFileModify(directory, 5*time.Second, func(path string) {9 fmt.Println("Modified file: ", path)10 })11}12import (13func main() {14 if len(os.Args) < 2 {15 fmt.Println("Usage: ", filepath.Base(os.Args[0]), "directory")16 os.Exit(1)17 }18 info := infoGatherer{}19 info.OnSpecFileModify(directory, 5*time.Second, func(path string) {20 fmt.Println("Modified file: ", path)21 })22}23import (24func main() {25 if len(os.Args) < 2 {26 fmt.Println("Usage: ", filepath.Base(os.Args[0]), "directory")27 os.Exit(1)28 }29 info := infoGatherer{}30 info.OnSpecFileModify(directory, 5*time.Second, func(path string) {31 fmt.Println("Modified file: ", path)32 })33}34import (35func main() {36 if len(os.Args) < 2 {37 fmt.Println("Usage: ", filepath.Base(os.Args[0]), "directory")38 os.Exit(1)39 }40 info := infoGatherer{}41 info.OnSpecFileModify(directory, 5*time.Second, func(path string) {42 fmt.Println("Modified file

Full Screen

Full Screen

OnSpecFileModify

Using AI Code Generation

copy

Full Screen

1func main(){2 infoGatherer := new(InfoGatherer)3 infoGatherer.OnSpecFileModify("path of spec file")4}5func main(){6 infoGatherer := new(InfoGatherer)7 infoGatherer.OnSpecFileModify("path of spec file")8}9func main(){10 infoGatherer := new(InfoGatherer)11 infoGatherer.OnSpecFileModify("path of spec file")12}13func main(){14 infoGatherer := new(InfoGatherer)15 infoGatherer.OnSpecFileModify("path of spec file")16}17func main(){18 infoGatherer := new(InfoGatherer)19 infoGatherer.OnSpecFileModify("path of spec file")20}21func main(){22 infoGatherer := new(InfoGatherer)23 infoGatherer.OnSpecFileModify("path of spec file")24}25func main(){26 infoGatherer := new(InfoGatherer)27 infoGatherer.OnSpecFileModify("path of spec file")28}29func main(){30 infoGatherer := new(InfoGatherer)31 infoGatherer.OnSpecFileModify("path of spec file")32}33func main(){34 infoGatherer := new(InfoGatherer)35 infoGatherer.OnSpecFileModify("path of spec file")36}37func main(){

Full Screen

Full Screen

OnSpecFileModify

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 currentDir, _ := os.Getwd()4 files, _ := ioutil.ReadDir(currentDir)5 for _, file := range files {6 absolutePath, _ := filepath.Abs(file.Name())7 infoGatherer.OnSpecFileModify(absolutePath)8 }9 time.Sleep(5 * time.Second)10}11import (12func main() {13 currentDir, _ := os.Getwd()14 files, _ := ioutil.ReadDir(currentDir)15 for _, file := range files {16 absolutePath, _ := filepath.Abs(file.Name())17 infoGatherer.OnSpecFileModify(absolutePath)18 }19 time.Sleep(5 * time.Second)20}

Full Screen

Full Screen

OnSpecFileModify

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("vim-go")4 infoGatherer := NewInfoGatherer()5 specFile := NewSpecFile("/tmp/test.txt")6 infoGatherer.AddSpecFile(specFile)7 infoGatherer.Start()8 specFile = NewSpecFile("/tmp/test2.txt")9 infoGatherer.AddSpecFile(specFile)10 specFile = NewSpecFile("/tmp/test3.txt")11 infoGatherer.AddSpecFile(specFile)12 time.Sleep(1 * time.Second)13 infoGatherer.RemoveSpecFile("/tmp/test.txt")14 time.Sleep(1 * time.Second)15 infoGatherer.Stop()16}17import (18func main() {19 fmt.Println("vim-go")20 infoGatherer := NewInfoGatherer()21 specFile := NewSpecFile("/tmp/test.txt")22 infoGatherer.AddSpecFile(specFile)23 infoGatherer.Start()24 time.Sleep(1 * time.Second)25 infoGatherer.Stop()26}27import (28func main() {29 fmt.Println("vim-go")

Full Screen

Full Screen

OnSpecFileModify

Using AI Code Generation

copy

Full Screen

1func main() {2 file, err := os.Open(specFile)3 if err != nil {4 log.Fatal(err)5 }6 defer file.Close()7 scanner := bufio.NewScanner(file)8 for scanner.Scan() {9 fmt.Println(scanner.Text())10 }11 if err := scanner.Err(); err != nil {12 log.Fatal(err)13 }14 dir, err := os.Getwd()15 if err != nil {16 log.Fatal(err)17 }18 fmt.Println(dir)19 info := infoGatherer{dir}20 info.OnSpecFileModify(specFile)21}22func main() {23 file, err := os.Open(specFile)24 if err != nil {25 log.Fatal(err)26 }27 defer file.Close()28 scanner := bufio.NewScanner(file)29 for scanner.Scan() {30 fmt.Println(scanner.Text())31 }32 if err := scanner.Err(); err != nil {33 log.Fatal(err)34 }35 dir, err := os.Getwd()36 if err != nil {37 log.Fatal(err)38 }39 fmt.Println(dir)40 info := infoGatherer{dir}41 info.OnSpecFileModify(specFile)42}43func main() {44 file, err := os.Open(specFile)45 if err != nil {46 log.Fatal(err)47 }48 defer file.Close()49 scanner := bufio.NewScanner(file)50 for scanner.Scan() {51 fmt.Println(scanner.Text())52 }53 if err := scanner.Err(); err != nil {54 log.Fatal(err)55 }56 dir, err := os.Getwd()57 if err != nil {

Full Screen

Full Screen

OnSpecFileModify

Using AI Code Generation

copy

Full Screen

1func (ig *infoGatherer) OnSpecFileModify(specFile *SpecFile) {2}3func (ig *infoGatherer) OnSpecFileModify(specFile *SpecFile) {4}5func (ig *infoGatherer) OnSpecFileModify(specFile *SpecFile) {6}7func (ig *infoGatherer) OnSpecFileModify(specFile *SpecFile) {8}9func (ig *infoGatherer) OnSpecFileModify(specFile *SpecFile) {10}11func (ig *infoGatherer) OnSpecFileModify(specFile *SpecFile) {12}13func (ig *infoGatherer) OnSpecFileModify(specFile *SpecFile) {14}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful