}
func (tc ToolConfig) GetPath(t Tree) (s string) {
- if tc.rootDir != "" && tc.Paths[t] != "" {
- return path.Clean(tc.rootDir + "/" + tc.Paths[t])
+ if tc.Paths[t] != "" {
+ s = tc.Paths[t]
+ if !path.IsAbs(s) {
+ if tc.rootDir != "" {
+ s = tc.rootDir + "/" + s
+ } else {
+ s = ""
+ return
+ }
+ }
+ s = path.Clean(s)
}
return
}
--- /dev/null
+package main
+
+import "testing"
+
+func TestGetPath(t *testing.T) {
+ tests := []struct {
+ xenpath string
+ rootDir string
+ expected string
+ }{
+ {"xen.git", "/build/hg/security", "/build/hg/security/xen.git"},
+ {"../xen.git", "/build/hg/security", "/build/hg/xen.git"},
+ {"/build/hg/xen.git", "/build/hg/security", "/build/hg/xen.git"},
+ {"/build/hg/xen.git", "", "/build/hg/xen.git"},
+ {"xen.git", "", ""},
+ }
+
+ tc := ToolConfig{}
+ tc.Paths = make(map[Tree]string)
+
+ for i := range tests {
+ t.Logf("Checking [\"%s\" \"%s\"]\n",
+ tests[i].xenpath, tests[i].rootDir)
+ tc.Paths[TreeXen] = tests[i].xenpath
+ tc.rootDir = tests[i].rootDir
+
+ out := tc.GetPath(TreeXen)
+
+ if out != tests[i].expected {
+ t.Errorf("Expected %s, got %s\n",
+ tests[i].expected,
+ out)
+ }
+ }
+}