Skip to content

Commit

Permalink
Moved path related method in util package.
Browse files Browse the repository at this point in the history
  • Loading branch information
BugDiver committed May 27, 2016
1 parent b27aff9 commit 0edf6d1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
11 changes: 4 additions & 7 deletions execution/rerun/rerun.go
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/getgauge/gauge/gauge"
"github.com/getgauge/gauge/gauge_messages"
"github.com/getgauge/gauge/logger"
"github.com/getgauge/gauge/util"
flag "github.com/getgauge/mflag"
)

Expand Down Expand Up @@ -113,17 +114,13 @@ func ListenFailedScenarios() {
func prepareScenarioFailedMetadata(res *result.ScenarioResult, sce *gauge.Scenario, executionInfo gauge_messages.ExecutionInfo) {
if res.GetFailed() {
specPath := executionInfo.GetCurrentSpec().GetFileName()
failedScenario := getRelativePath(specPath)
failedScenario := util.RelPathToProjectRoot(specPath)
failedMeta.addFailedItem(specPath, fmt.Sprintf("%s:%v", failedScenario, sce.Span.Start))
}
}

func getRelativePath(path string) string {
return strings.TrimPrefix(path, config.ProjectRoot+string(filepath.Separator))
}

func addSpecFailedMetadata(res result.Result) {
fileName := getRelativePath(res.(*result.SpecResult).ProtoSpec.GetFileName())
fileName := util.RelPathToProjectRoot(res.(*result.SpecResult).ProtoSpec.GetFileName())
if _, ok := failedMeta.failedItemsMap[fileName]; ok {
failedMeta.failedItemsMap[fileName] = []string{}
}
Expand All @@ -134,7 +131,7 @@ func addSuiteFailedMetadata(res result.Result) {
failedMeta.failedItemsMap = make(map[string][]string)
for _, arg := range flag.Args() {
path, err := filepath.Abs(arg)
path = getRelativePath(path)
path = util.RelPathToProjectRoot(path)
if err == nil {
failedMeta.addFailedItem(path, path)
}
Expand Down
3 changes: 2 additions & 1 deletion execution/rerun/rerun_test.go
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/getgauge/gauge/execution/result"
"github.com/getgauge/gauge/gauge"
"github.com/getgauge/gauge/gauge_messages"
"github.com/getgauge/gauge/util"

"sort"

Expand Down Expand Up @@ -113,7 +114,7 @@ func (s *MySuite) TestGetRelativePath(c *C) {
spec1Rel := filepath.Join("specs", "example1.spec")
spec1Abs := filepath.Join(config.ProjectRoot, spec1Rel)

path := getRelativePath(spec1Abs)
path := util.RelPathToProjectRoot(spec1Abs)

c.Assert(path, Equals, spec1Rel)
}
Expand Down
8 changes: 1 addition & 7 deletions reporter/consoleFormatter.go
Expand Up @@ -19,10 +19,8 @@ package reporter

import (
"fmt"
"path/filepath"
"strings"

"github.com/getgauge/gauge/config"
"github.com/getgauge/gauge/util"
)

Expand Down Expand Up @@ -75,7 +73,7 @@ func prepStepMsg(msg string) string {
}

func prepSpecInfo(fileName string, lineNo int) string {
return fmt.Sprintf("Specification: %s:%v", getRelativePath(fileName), lineNo)
return fmt.Sprintf("Specification: %s:%v", util.RelPathToProjectRoot(fileName), lineNo)
}

func prepStacktrace(stacktrace string) string {
Expand All @@ -85,7 +83,3 @@ func prepStacktrace(stacktrace string) string {
func formatErrorFragment(fragment string, indentation int) string {
return indent(fragment, indentation+errorIndentation) + newline
}

func getRelativePath(path string) string {
return strings.TrimPrefix(path, config.ProjectRoot+string(filepath.Separator))
}
4 changes: 4 additions & 0 deletions util/fileUtils.go
Expand Up @@ -194,6 +194,10 @@ func SaveFile(fileName string, content string, backup bool) {
}
}

func RelPathToProjectRoot(path string) string {
return strings.TrimPrefix(path, config.ProjectRoot+string(filepath.Separator))
}

// GetPathToFile returns the path to a given file from the Project root
func GetPathToFile(path string) string {
if filepath.IsAbs(path) {
Expand Down

0 comments on commit 0edf6d1

Please sign in to comment.