Skip to content

Commit

Permalink
Handle absolute paths in config
Browse files Browse the repository at this point in the history
  • Loading branch information
ZipFile committed Nov 23, 2023
1 parent eb5b1b5 commit 1c3afa5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
8 changes: 4 additions & 4 deletions runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (c *Config) colorInfo() map[string]string {
}

func (c *Config) buildLogPath() string {
return filepath.Join(c.tmpPath(), c.Build.Log)
return joinPath(c.tmpPath(), c.Build.Log)
}

func (c *Config) buildDelay() time.Duration {
Expand All @@ -346,15 +346,15 @@ func (c *Config) rerunDelay() time.Duration {
}

func (c *Config) binPath() string {
return filepath.Join(c.Root, c.Build.Bin)
return joinPath(c.Root, c.Build.Bin)
}

func (c *Config) tmpPath() string {
return filepath.Join(c.Root, c.TmpDir)
return joinPath(c.Root, c.TmpDir)
}

func (c *Config) testDataPath() string {
return filepath.Join(c.Root, c.TestDataDir)
return joinPath(c.Root, c.TestDataDir)
}

func (c *Config) rel(path string) string {
Expand Down
8 changes: 8 additions & 0 deletions runner/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,11 @@ func setTage2Map(root string, t reflect.Type, m map[string]TomlInfo, fieldPath s
}
}
}

func joinPath(root, path string) string {
if filepath.IsAbs(path) {
return path
}

return filepath.Join(root, path)
}
30 changes: 30 additions & 0 deletions runner/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,33 @@ func TestCheckIncludeFile(t *testing.T) {
assert.Equal(t, e.checkIncludeFile("no.go"), false)
assert.Equal(t, e.checkIncludeFile("."), false)
}

func TestJoinPathRelative(t *testing.T) {
root, err := filepath.Abs("test")

if err != nil {
t.Fatalf("couldn't get absolute path for testing: %v", err)
}

result := joinPath(root, "x")

assert.Equal(t, result, filepath.Join(root, "x"))
}

func TestJoinPathAbsolute(t *testing.T) {
root, err := filepath.Abs("test")

if err != nil {
t.Fatalf("couldn't get absolute path for testing: %v", err)
}

path, err := filepath.Abs("x")

if err != nil {
t.Fatalf("couldn't get absolute path for testing: %v", err)
}

result := joinPath(root, path)

assert.Equal(t, result, path)
}

0 comments on commit 1c3afa5

Please sign in to comment.