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 f62d885 commit d49cd26
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 32 deletions.
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
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
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/sourcegraph/jsonrpc2 v0.2.0
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc
google.golang.org/genproto/googleapis/rpc v0.0.0-20230717213848-3f92550aa753
google.golang.org/grpc v1.56.2
google.golang.org/protobuf v1.31.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
Expand All @@ -31,9 +31,9 @@ require (
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -105,11 +105,11 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
Expand All @@ -120,8 +120,8 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc h1:XSJ8Vk1SWuNr8S18z1NZSziL0CPIXLCCMDOEFtHBOFc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230717213848-3f92550aa753 h1:XUODHrpzJEUeWmVo/jfNTLj0YyVveOo28oE6vkFbkO4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230717213848-3f92550aa753/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
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
38 changes: 22 additions & 16 deletions util/fileUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,34 @@ var GetSpecFiles = func(paths []string) []string {
return specFiles
}

func getConceptFiles(paths []string) []string {
var conceptFiles []string
for _, path := range paths {
absPath, err := filepath.Abs(strings.TrimSpace(path))
if err != nil {
logger.Fatalf(true, "Error getting absolute concept path. %v", err)
}
conceptFiles = append(conceptFiles, FindConceptFilesIn(absPath)...)
}
return conceptFiles
}

// GetConceptFiles returns the list of concept files present in the PROJECTROOT
var GetConceptFiles = func() []string {
var conceptPaths = GetConceptsPaths()
if len(conceptPaths) > 0 {
return removeDuplicateValues(getConceptFiles(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)...)
files := getConceptFiles([]string{projRoot})
var specsDirFromProperties = os.Getenv(env.SpecsDir)
if specsDirFromProperties != "" {
var specDirectories = strings.Split(specsDirFromProperties, ",")
files = append(files, getConceptFiles(specDirectories)...)
}
return removeDuplicateValues(files)
}
Expand Down
25 changes: 25 additions & 0 deletions 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 @@ -163,13 +164,37 @@ func (s *MySuite) TestGetConceptFiles(c *C) {
c.Assert(len(GetConceptFiles()), Equals, 1)
}

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

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

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

os.Setenv(env.ConceptsDir, filepath.Join(config.ProjectRoot, "specs/subdir/concept2.cpt"))
c.Assert(len(GetConceptFiles()), Equals, 1)
}

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

func (s *MySuite) TestGetConceptFilesWhenSpecDirIsOutsideProjectRoot(c *C) {
os.Clearenv()
config.ProjectRoot = "_testdata"
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)
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 {
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
9 changes: 9 additions & 0 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ func (s *MySuite) TestSpecDirEnvVariableAllowsCommaSeparatedList(c *C) {
c.Assert(e, Equals, nil)
c.Assert(GetSpecDirs(), DeepEquals, []string{"spec1", "spec2", "spec3"})
}

func (s *MySuite) TestConceptsEnvVariableAllowsCommaSeparatedList(c *C) {
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

0 comments on commit d49cd26

Please sign in to comment.