Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds gauge_concepts_dir for defining concepts directory #2379

Merged
merged 10 commits into from
Jul 20, 2023
Merged
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Install Gauge (windows)
if: matrix.os == 'windows-latest'
run: |
go run build/make.go --install --verbose
go run build/make.go --install --verbose
echo "C:\\Program Files\\gauge\\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Install Gauge (linux)
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
- name: Install Gauge (windows)
if: matrix.os == 'windows-latest'
run: |
go run build/make.go --install --verbose
go run build/make.go --install --verbose
echo "C:\\Program Files\\gauge\\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Install Gauge (linux)
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ If you are trying to write plugins for Gauge or trying to contribute to Gauge co
Ex:
```diff
// CurrentGaugeVersion represents the current version of Gauge
-var CurrentGaugeVersion = &Version{1, 0, 7}
+var CurrentGaugeVersion = &Version{1, 0, 8}
-var CurrentGaugeVersion = &Version{1, 5, 0}
+var CurrentGaugeVersion = &Version{1, 5, 1}

```
2 changes: 2 additions & 0 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
const (
// SpecsDir holds the location of spec files
SpecsDir = "gauge_specs_dir"
// ConceptsDir holds the location of concept files
ConceptsDir = "gauge_concepts_dir"
// GaugeReportsDir holds the location of reports
GaugeReportsDir = "gauge_reports_dir"
// GaugeEnvironment holds the name of the current environment
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gauge_specs_dir=spec1, spec2, spec3
gauge_specs_dir=spec1, spec2, spec3
gauge_concepts_dir=dir1, dir2, dir3
56 changes: 36 additions & 20 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 All @@ -173,28 +174,43 @@ var GetSpecFiles = func(paths []string) []string {
return specFiles
}

// GetConceptFiles returns the list of concept files present in the PROJECTROOT
func findConceptFiles(paths []string) []string {
var conceptFiles []string
for _, path := range paths {
var conceptPath = strings.TrimSpace(path)
if !filepath.IsAbs(conceptPath) {
conceptPath = filepath.Join(config.ProjectRoot, conceptPath)
}
absPath, err := filepath.Abs(conceptPath)
if err != nil {
logger.Fatalf(true, "Error getting absolute concept path. %v", err)
}
if !common.FileExists(absPath) {
exitWithMessage(fmt.Sprintf("No such file or diretory: %s", absPath))
}
conceptFiles = append(conceptFiles, FindConceptFilesIn(absPath)...)
}
return conceptFiles
}

// GetConceptFiles It returns the list of concept files
// It returns concept files from gauge_concepts_dir if present
// It returns concept files from projectRoot otherwise
var GetConceptFiles = func() []string {
conceptPaths := GetConceptsPaths()
if len(conceptPaths) > 0 {
return removeDuplicateValues(findConceptFiles(conceptPaths))
}
projRoot := config.ProjectRoot
if projRoot == "" {
logger.Fatalf(true, "Failed to get project root.")
}
absPath, err := filepath.Abs(projRoot)
if err != nil {
logger.Fatalf(true, "Error getting absolute path. %v", err)
}
files := FindConceptFilesIn(absPath)
var specFromProperties = os.Getenv(env.SpecsDir)
if specFromProperties == "" {
return files
}
var specDirectories = strings.Split(specFromProperties, ",")
for _, dir := range specDirectories {
absSpecPath, err := filepath.Abs(strings.TrimSpace(dir))
if err != nil {
logger.Fatalf(true, "Error getting absolute path. %v", err)
}
files = append(files, FindConceptFilesIn(absSpecPath)...)
absProjRoot, _ := filepath.Abs(projRoot)
files := findConceptFiles([]string{absProjRoot})
specDirFromProperties := os.Getenv(env.SpecsDir)
if specDirFromProperties != "" {
specDirectories := strings.Split(specDirFromProperties, ",")
files = append(files, findConceptFiles(specDirectories)...)
}
return removeDuplicateValues(files)
}
Expand Down Expand Up @@ -230,7 +246,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
47 changes: 46 additions & 1 deletion util/fileUtils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (s *MySuite) TestFindAllConceptFilesInNestedDir(c *C) {
}

func (s *MySuite) TestGetConceptFiles(c *C) {
os.Clearenv()
config.ProjectRoot = "_testdata"
specsDir, _ := filepath.Abs(filepath.Join("_testdata", "specs"))

Expand All @@ -164,17 +165,42 @@ func (s *MySuite) TestGetConceptFiles(c *C) {
}

func (s *MySuite) TestGetConceptFilesWhenSpecDirIsOutsideProjectRoot(c *C) {
os.Clearenv()
config.ProjectRoot = "_testdata"
os.Setenv(env.SpecsDir, "_testSpecDir")
os.Setenv(env.SpecsDir, "../_testSpecDir")
c.Assert(len(GetConceptFiles()), Equals, 3)
}

func (s *MySuite) TestGetConceptFilesWhenSpecDirIsWithInProject(c *C) {
os.Clearenv()
config.ProjectRoot = "_testdata"
os.Setenv(env.SpecsDir, "_testdata/specs")
c.Assert(len(GetConceptFiles()), Equals, 2)
}

func (s *MySuite) TestGetConceptFilesWhenConceptsDirSet(c *C) {
os.Clearenv()
config.ProjectRoot = "_testdata"
c.Assert(len(GetConceptFiles()), Equals, 2)

os.Setenv(env.ConceptsDir, filepath.Join("specs", "concept1.cpt"))
c.Assert(len(GetConceptFiles()), Equals, 1)

os.Setenv(env.ConceptsDir, filepath.Join("specs", "subdir"))
c.Assert(len(GetConceptFiles()), Equals, 1)

conceptPath, _ := filepath.Abs(filepath.Join("_testdata", "specs", "subdir", "concept2.cpt"))
os.Setenv(env.ConceptsDir, conceptPath)
c.Assert(len(GetConceptFiles()), Equals, 1)
}

func (s *MySuite) TestGetConceptFilesWhenConceptDirIsOutsideProjectRoot(c *C) {
os.Clearenv()
config.ProjectRoot = "_testdata"
os.Setenv(env.ConceptsDir, "../_testSpecDir,../_testdata/specs")
c.Assert(len(GetConceptFiles()), Equals, 3)
}

func (s *MySuite) TestFindAllNestedDirs(c *C) {
nested1 := filepath.Join(dir, "nested")
nested2 := filepath.Join(dir, "nested2")
Expand Down Expand Up @@ -261,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, "specs2")
GetConceptFiles()
directory, _ := filepath.Abs(filepath.Join(config.ProjectRoot, "specs2"))
c.Assert(expectedErrorMessage, Equals, fmt.Sprintf("No such file or diretory: %s", directory))

os.Setenv(env.SpecsDir, "_testSpecsDir,non-exisitng")
GetConceptFiles()
directory, _ = filepath.Abs(filepath.Join(config.ProjectRoot, "non-exisitng"))
c.Assert(expectedErrorMessage, Equals, fmt.Sprintf("No such file or diretory: %s", directory))
}

func (s *MySuite) TestGetSpecFilesWhenSpecsDirIsEmpty(c *C) {
var expectedErrorMessage string
exitWithMessage = func(message string) {
Expand Down
15 changes: 15 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ func GetSpecDirs() []string {
return []string{common.SpecsDirectoryName}
}

// GetConceptsPaths returns the concepts directory.
// It checks whether the environment variable for gauge_concepts_dir is set.
// It returns specs directories otherwise
func GetConceptsPaths() []string {
var conceptDirs []string
var conceptsDirFromProperties = os.Getenv(env.ConceptsDir)
if conceptsDirFromProperties != "" {
conceptDirs = strings.Split(conceptsDirFromProperties, ",")
for index, ele := range conceptDirs {
conceptDirs[index] = strings.TrimSpace(ele)
}
}
return conceptDirs
}

func ListContains(list []string, val string) bool {
for _, s := range list {
if s == val {
Expand Down
10 changes: 10 additions & 0 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ func (s *MySuite) TestSpecDirEnvVariableAllowsCommaSeparatedList(c *C) {
c.Assert(e, Equals, nil)
c.Assert(GetSpecDirs(), DeepEquals, []string{"spec1", "spec2", "spec3"})
}

func (s *MySuite) TestConceptsDirEnvVariableAllowsCommaSeparatedList(c *C) {
c.Skip("This is causing the net/httptest panic in util/httpUtils_test.go fail on windows.")
os.Clearenv()
config.ProjectRoot = "_testdata/proj1"

e := env.LoadEnv("multipleSpecs", nil)
c.Assert(e, Equals, nil)
c.Assert(GetConceptsPaths(), DeepEquals, []string{"dir1", "dir2", "dir3"})
}
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// CurrentGaugeVersion represents the current version of Gauge
var CurrentGaugeVersion = &Version{1, 5, 1}
var CurrentGaugeVersion = &Version{1, 5, 2}

// BuildMetadata represents build information of current release (e.g, nightly build information)
var BuildMetadata = ""
Expand Down