Skip to content

Commit

Permalink
Adds gauge_concepts_dir for defining concepts directory
Browse files Browse the repository at this point in the history
Signed-off-by: Haroon Sheikh <[email protected]>
Signed-off-by: Haroon Sheikh <[email protected]>
  • Loading branch information
haroon-sheikh committed Jul 20, 2023
1 parent c152cb1 commit c8d0dcc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
16 changes: 12 additions & 4 deletions util/fileUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ func IsDir(path string) bool {
return fileInfo.IsDir()
}

// GetSpecFiles returns the list of spec files present at the given path.
// If the path itself represents a spec file, it returns the same.
var exitWithMessage = func(message string) {
logger.Errorf(true, message)
os.Exit(1)
}

// GetSpecFiles returns the list of spec files present at the given path.
// If the path itself represents a spec file, it returns the same.
var GetSpecFiles = func(paths []string) []string {
var specFiles []string
for _, path := range paths {
Expand Down Expand Up @@ -180,6 +181,9 @@ func findConceptFiles(paths []string) []string {
if err != nil {
logger.Fatalf(true, "Error getting absolute concept path. %v", err)
}
if !common.FileExists(absPath) {
exitWithMessage(fmt.Sprintf("The directory %s does not exist.", absPath))
}
conceptFiles = append(conceptFiles, FindConceptFilesIn(absPath)...)
}
return conceptFiles
Expand All @@ -198,7 +202,11 @@ var GetConceptFiles = func() []string {
logger.Fatalf(true, "Failed to get project root.")
}
files := findConceptFiles([]string{projRoot})
files = append(files, findConceptFiles(GetSpecDirs())...)
var specDirFromProperties = os.Getenv(env.SpecsDir)
if specDirFromProperties != "" {
var specDirectories = strings.Split(specDirFromProperties, ",")
files = append(files, findConceptFiles(specDirectories)...)
}
return removeDuplicateValues(files)
}

Expand Down Expand Up @@ -233,7 +241,7 @@ func GetPathToFile(path string) string {
}

gaugeDataDir := env.GaugeDataDir()
if gaugeDataDir != "." && filepath.IsAbs((env.GaugeDataDir())) {
if gaugeDataDir != "." && filepath.IsAbs(env.GaugeDataDir()) {
logger.Warningf(true, "'gauge_data_dir' property must be relative to Project Root. Found absolute path: %s", gaugeDataDir)
}

Expand Down
19 changes: 19 additions & 0 deletions util/fileUtils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,25 @@ func (s *MySuite) TestGetSpecFilesWhenSpecsDirDoesNotExists(c *C) {
c.Assert(expectedErrorMessage, Equals, "Specs directory dir1 does not exist.")
}

func (s *MySuite) TestGetConceptFilesWhenConceptsDirDoesNotExists(c *C) {
os.Clearenv()
var expectedErrorMessage string
exitWithMessage = func(message string) {
expectedErrorMessage = message
}
config.ProjectRoot = "_testdata"

os.Setenv(env.SpecsDir, "specs")
GetConceptFiles()
directory, _ := filepath.Abs("specs")
c.Assert(expectedErrorMessage, Equals, fmt.Sprintf("The directory %s does not exist.", directory))

os.Setenv(env.SpecsDir, "_testSpecsDir,non-exisitng")
GetConceptFiles()
directory, _ = filepath.Abs("non-exisitng")
c.Assert(expectedErrorMessage, Equals, fmt.Sprintf("The directory %s does not exist.", directory))
}

func (s *MySuite) TestGetSpecFilesWhenSpecsDirIsEmpty(c *C) {
var expectedErrorMessage string
exitWithMessage = func(message string) {
Expand Down

0 comments on commit c8d0dcc

Please sign in to comment.