How to use OnConceptFileModify method of infoGatherer Package

Best Gauge code snippet using infoGatherer.OnConceptFileModify

apiMessageHandler.go

Source:apiMessageHandler.go Github

copy

Full Screen

...195}196func (handler *gaugeAPIMessageHandler) performRefresh(files []string) {197 for _, file := range files {198 if util.IsConcept(file) {199 handler.specInfoGatherer.OnConceptFileModify(file)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}...

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

OnConceptFileModify

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Run(`5 var i = 0;6 setInterval(function(){7 i++;8 if (i > 10) {9 throw new Error("i is too high!");10 }11 console.log("i = " + i);12 }, 1000);13 fmt.Println("Done")14}15import (16func main() {17 vm := otto.New()18 value, err := vm.Run(`19 (function(){20 return "Hello, World!";21 })();22 if err != nil {23 panic(err)24 }25 fmt.Println(value)26}27import (28func main() {29 vm := otto.New()30 value, err := vm.Run(`31 (function(){32 return 1 + 1;33 })();34 if err != nil {35 panic(err)36 }37 fmt.Println(value)38}39import (40func main() {41 vm := otto.New()42 value, err := vm.Run(`43 (function(){44 return 1 + 1;45 })();46 if err != nil {47 panic(err)48 }49 result, err := value.ToInteger()50 if err != nil {51 panic(err)52 }53 fmt.Println(result)54}55import (56func main() {57 vm := otto.New()58 value, err := vm.Run(`59 (function(){60 return 1 + 1;61 })();62 if err != nil {63 panic(err)64 }65 result, err := value.ToInteger()66 if err != nil {67 panic(err)68 }69 fmt.Println(result)70}71import (72func main() {73 vm := otto.New()74 value, err := vm.Run(`75 (function(){

Full Screen

Full Screen

OnConceptFileModify

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ig := infoGatherer.NewInfoGatherer()4 ig.RegisterCallback(func(file string) {5 fmt.Println("File modified:", file)6 })7 ig.OnConceptFileModify("concept.txt")8 time.Sleep(10 * time.Second)9 ig.Stop()10 f, _ := os.OpenFile("concept.txt", os.O_APPEND|os.O_WRONLY, 0600)11 f.WriteString("Hello")12 f.Close()13 time.Sleep(10 * time.Second)14}15import (16func main() {17 ig := infoGatherer.NewInfoGatherer()18 ig.RegisterCallback(func(file string) {19 fmt.Println("File modified:", file)20 })21 ig.OnConceptFileModify("concept.txt")22 time.Sleep(10 * time.Second)23 ig.Stop()24 f, _ := os.OpenFile("concept.txt", os.O_APPEND|os.O_WRONLY, 0600)25 f.WriteString("Hello")26 f.Close()27 time.Sleep(10 * time.Second)28}29import (30func main() {31 ig := infoGatherer.NewInfoGatherer()

Full Screen

Full Screen

OnConceptFileModify

Using AI Code Generation

copy

Full Screen

1infoGatherer.OnConceptFileModify(ConceptFileModifyEventArgs args)2{3}4infoGatherer.OnConceptFileModify(ConceptFileModifyEventArgs args)5{6}7infoGatherer.OnConceptFileModify(ConceptFileModifyEventArgs args)8{9}10infoGatherer.OnConceptFileModify(ConceptFileModifyEventArgs args)11{12}13infoGatherer.OnConceptFileModify(ConceptFileModifyEventArgs args)14{15}16infoGatherer.OnConceptFileModify(ConceptFileModifyEventArgs args)17{18}19infoGatherer.OnConceptFileModify(ConceptFileModifyEventArgs args)20{21}22infoGatherer.OnConceptFileModify(ConceptFileModifyEventArgs args)

Full Screen

Full Screen

OnConceptFileModify

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ig := infoGatherer.InfoGatherer{}4 ig.OnConceptFileModify("test.txt")5}6import (7func main() {8 ig := infoGatherer.InfoGatherer{}9 ig.OnConceptFileModify("test.txt")10}11import (12func main() {13 ig := infoGatherer.InfoGatherer{}14 ig.OnConceptFileModify("test.txt")15}16import (17func main() {18 ig := infoGatherer.InfoGatherer{}19 ig.OnConceptFileModify("test.txt")20}21import (22func main() {23 ig := infoGatherer.InfoGatherer{}24 ig.OnConceptFileModify("test.txt")25}

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