[BACK]Return to path_test.go CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / pkgtools / pkglint / files

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /pkgsrc/pkgtools/pkglint/files/Attic/path_test.go between version 1.3 and 1.8

version 1.3, 2019/11/30 20:35:11 version 1.8, 2020/01/04 19:53:14
Line 16  func (s *Suite) Test_NewPath(c *check.C)
Line 16  func (s *Suite) Test_NewPath(c *check.C)
         c.Check(NewPath("\\"), check.Not(check.Equals), NewPath("/"))          c.Check(NewPath("\\"), check.Not(check.Equals), NewPath("/"))
 }  }
   
 func (s *Suite) Test_NewPathSlash(c *check.C) {  
         t := s.Init(c)  
   
         t.CheckEquals(NewPathSlash("filename"), NewPathSlash("filename"))  
         t.CheckEquals(NewPathSlash("\\"), NewPathSlash("\\"))  
   
         t.CheckEquals(  
                 NewPathSlash("\\"),  
                 NewPathSlash(condStr(runtime.GOOS == "windows", "/", "\\")))  
 }  
   
 func (s *Suite) Test_Path_String(c *check.C) {  func (s *Suite) Test_Path_String(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         for _, p := range []string{"", "filename", "a/b", "c\\d"} {          test := func(p Path) {
                 t.CheckEquals(NewPath(p).String(), p)                  t.CheckEquals(p.String(), string(p))
         }          }
   
           test("")
           test("filename")
           test("a/b")
   
           // No normalization takes place here.
           // That's what NewPathSlash is for.
           test("c\\d")
 }  }
   
 func (s *Suite) Test_Path_GoString(c *check.C) {  func (s *Suite) Test_Path_GoString(c *check.C) {
Line 60  func (s *Suite) Test_Path_IsEmpty(c *che
Line 57  func (s *Suite) Test_Path_IsEmpty(c *che
         test("/", false)          test("/", false)
 }  }
   
 func (s *Suite) Test_Path_Dir(c *check.C) {  func (s *Suite) Test_Path_DirClean(c *check.C) {
           t := s.Init(c)
   
           test := func(p, dir Path) {
                   t.CheckEquals(p.DirClean(), dir)
           }
   
           test("", ".")
           test("././././", ".")
           test("/root", "/")
           test("filename", ".")
           test("dir/filename", "dir")
           test("dir/filename\\with\\backslash", "dir")
   
           test("././././dir/filename", "dir")
   }
   
   func (s *Suite) Test_Path_DirNoClean(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         test := func(p, dir Path) {          test := func(p, dir Path) {
                 t.CheckEquals(p.Dir(), dir)                  t.CheckEquals(p.DirNoClean(), dir)
         }          }
   
         test("", ".")          test("", ".")
Line 73  func (s *Suite) Test_Path_Dir(c *check.C
Line 87  func (s *Suite) Test_Path_Dir(c *check.C
         test("filename", ".")          test("filename", ".")
         test("dir/filename", "dir")          test("dir/filename", "dir")
         test("dir/filename\\with\\backslash", "dir")          test("dir/filename\\with\\backslash", "dir")
           test("dir/./file", "dir")
           test("./file", ".")
 }  }
   
 func (s *Suite) Test_Path_Base(c *check.C) {  func (s *Suite) Test_Path_Base(c *check.C) {
Line 294  func (s *Suite) Test_Path_ContainsPath(c
Line 310  func (s *Suite) Test_Path_ContainsPath(c
         test("aa/bb/cc", "c", false)          test("aa/bb/cc", "c", false)
 }  }
   
 func (s *Suite) Test_Path_ContainsPathCanonical(c *check.C) {  
         t := s.Init(c)  
   
         test := func(p, sub Path, contains bool) {  
                 t.CheckEquals(p.ContainsPathCanonical(sub), contains)  
         }  
   
         test("", "", false)  
         test(".", "", false)  
         test("filename", "", false)  
         test("filename", "filename", true)  
         test("a/b/c", "a", true)  
         test("a/b/c", "b", true)  
         test("a/b/c", "c", true)  
         test("a/b/c", "a/b", true)  
         test("a/b/c", "b/c", true)  
         test("a/b/c", "a/b/c", true)  
         test("aa/b/c", "a", false)  
         test("a/bb/c", "b", false)  
         test("a/bb/c", "b/c", false)  
         test("mk/fetch/fetch.mk", "mk", true)  
         test("category/package/../../wip/mk", "mk", true)  
         test("category/package/../../wip/mk/..", "mk", true) // FIXME  
         test("category/package/../../wip/mk/../..", "mk", false)  
 }  
   
 func (s *Suite) Test_Path_HasSuffixText(c *check.C) {  func (s *Suite) Test_Path_HasSuffixText(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
Line 393  func (s *Suite) Test_Path_Replace(c *che
Line 383  func (s *Suite) Test_Path_Replace(c *che
 func (s *Suite) Test_Path_JoinClean(c *check.C) {  func (s *Suite) Test_Path_JoinClean(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         test := func(p Path, suffix Path, result Path) {          test := func(p Path, rel RelPath, result Path) {
                 t.CheckEquals(p.JoinClean(suffix), result)                  t.CheckEquals(p.JoinClean(rel), result)
         }          }
   
         test("dir", "file", "dir/file")          test("dir", "file", "dir/file")
Line 406  func (s *Suite) Test_Path_JoinClean(c *c
Line 396  func (s *Suite) Test_Path_JoinClean(c *c
 func (s *Suite) Test_Path_JoinNoClean(c *check.C) {  func (s *Suite) Test_Path_JoinNoClean(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         test := func(p, suffix Path, result Path) {          test := func(p Path, rel RelPath, result Path) {
                 t.CheckEquals(p.JoinNoClean(suffix), result)                  t.CheckEquals(p.JoinNoClean(rel), result)
         }          }
   
         test("dir", "file", "dir/file")          test("dir", "file", "dir/file")
         test("dir", "///file", "dir////file")          test("dir", "///file", "dir////file")
         test("dir/./../dir/", "///file", "dir/./../dir/////file")          test("dir/./../dir/", "///file", "dir/./../dir/////file")
         test("dir", "..", "dir/..")          test("dir", "..", "dir/..")
           test(".", "sub", "./sub")
 }  }
   
 func (s *Suite) Test_Path_Clean(c *check.C) {  func (s *Suite) Test_Path_Clean(c *check.C) {
Line 439  func (s *Suite) Test_Path_CleanDot(c *ch
Line 430  func (s *Suite) Test_Path_CleanDot(c *ch
         test("", "")          test("", "")
         test(".", ".")          test(".", ".")
         test("./././", ".")          test("./././", ".")
           test("dir/", "dir/") // TODO: Or maybe "dir/."?
         test("a/bb///../c", "a/bb/../c")          test("a/bb///../c", "a/bb/../c")
         test("./filename", "filename")          test("./filename", "filename")
         test("/absolute", "/absolute")          test("/absolute", "/absolute")
         test("/usr/pkgsrc/wip/package", "/usr/pkgsrc/wip/package")          test("/usr/pkgsrc/wip/package", "/usr/pkgsrc/wip/package")
         test("/usr/pkgsrc/wip/package/../mk/git-package.mk", "/usr/pkgsrc/wip/package/../mk/git-package.mk")          test("/usr/pkgsrc/wip/package/../mk/git-package.mk", "/usr/pkgsrc/wip/package/../mk/git-package.mk")
           test("a//b", "a/b")
   }
   
   func (s *Suite) Test_Path_CleanPath(c *check.C) {
           t := s.Init(c)
   
           test := func(from, to Path) {
                   t.CheckEquals(from.CleanPath(), to)
           }
   
           test("simple/path", "simple/path")
           test("/absolute/path", "/absolute/path")
   
           // Single dot components are removed, unless it's the only component of the path.
           test("./././.", ".")
           test("./././", ".")
           test("dir/multi/././/file", "dir/multi/file")
           test("dir/", "dir")
   
           test("dir/", "dir")
   
           // Components like aa/bb/../.. are removed, but not in the initial part of the path,
           // and only if they are not followed by another "..".
           test("dir/../dir/../dir/../dir/subdir/../../Makefile", "dir/../dir/../dir/../Makefile")
           test("111/222/../../333/444/../../555/666/../../777/888/9", "111/222/../../777/888/9")
           test("1/2/3/../../4/5/6/../../7/8/9/../../../../10", "1/2/3/../../4/7/8/9/../../../../10")
           test("cat/pkg.v1/../../cat/pkg.v2/Makefile", "cat/pkg.v1/../../cat/pkg.v2/Makefile")
           test("aa/../../../../../a/b/c/d", "aa/../../../../../a/b/c/d")
           test("aa/bb/../../../../a/b/c/d", "aa/bb/../../../../a/b/c/d")
           test("aa/bb/cc/../../../a/b/c/d", "aa/bb/cc/../../../a/b/c/d")
           test("aa/bb/cc/dd/../../a/b/c/d", "aa/bb/a/b/c/d")
           test("aa/bb/cc/dd/ee/../a/b/c/d", "aa/bb/cc/dd/ee/../a/b/c/d")
           test("../../../../../a/b/c/d", "../../../../../a/b/c/d")
           test("aa/../../../../a/b/c/d", "aa/../../../../a/b/c/d")
           test("aa/bb/../../../a/b/c/d", "aa/bb/../../../a/b/c/d")
           test("aa/bb/cc/../../a/b/c/d", "aa/bb/cc/../../a/b/c/d")
           test("aa/bb/cc/dd/../a/b/c/d", "aa/bb/cc/dd/../a/b/c/d")
           test("aa/../cc/../../a/b/c/d", "aa/../cc/../../a/b/c/d")
   
           // The initial 2 components of the path are typically category/package, when
           // pkglint is called from the pkgsrc top-level directory.
           // This path serves as the context and therefore is always kept.
           test("aa/bb/../../cc/dd/../../ee/ff", "aa/bb/../../ee/ff")
           test("aa/bb/../../cc/dd/../..", "aa/bb/../..")
           test("aa/bb/cc/dd/../..", "aa/bb")
           test("aa/bb/../../cc/dd/../../ee/ff/buildlink3.mk", "aa/bb/../../ee/ff/buildlink3.mk")
           test("./aa/bb/../../cc/dd/../../ee/ff/buildlink3.mk", "aa/bb/../../ee/ff/buildlink3.mk")
   
           test("../.", "..")
           test("../././././././.", "..")
           test(".././././././././", "..")
   
           test(
                   "x11/kde-runtime4/../../misc/kdepimlibs4/../../databases/openldap-client/buildlink3.mk",
                   "x11/kde-runtime4/../../databases/openldap-client/buildlink3.mk")
 }  }
   
 func (s *Suite) Test_Path_IsAbs(c *check.C) {  func (s *Suite) Test_Path_IsAbs(c *check.C) {
Line 464  func (s *Suite) Test_Path_IsAbs(c *check
Line 511  func (s *Suite) Test_Path_IsAbs(c *check
 func (s *Suite) Test_Path_Rel(c *check.C) {  func (s *Suite) Test_Path_Rel(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         base := NewPath(".")          test := func(base Path, other Path, result RelPath) {
         abc := NewPath("a/b/c")                  t.CheckEquals(base.Rel(other), result)
         defFile := NewPath("d/e/f/file")          }
   
           test("a/b/c", "d/e/f/file", "../../../d/e/f/file")
           test(".", ".", ".")
   
           // The trailing dot marks the difference between a file and a directory.
           // This is the same behavior as with filepath.Rel.
           test("a/b/c", ".", "../../../.")
   
           // Intermediate dotdot components are removed.
           test("a/../b", "c/../d", "../d")
   
           test(".", "dir/file", "dir/file")
           // XXX: maybe the /. is missing at the end
           test(".", "dir/subdir/", "dir/subdir")
           // XXX: maybe the /. is missing at the end
           test(".", "dir/subdir/.", "dir/subdir")
   }
   
   func (s *Suite) Test_NewCurrPath(c *check.C) {
           t := s.Init(c)
   
           curr := NewCurrPath("dir/.///file")
   
           t.CheckEquals(curr.String(), "dir/.///file")
   }
   
   func (s *Suite) Test_NewCurrPathString(c *check.C) {
           t := s.Init(c)
   
           curr := NewCurrPathString("dir/.///file")
   
           t.CheckEquals(curr.String(), "dir/.///file")
   }
   
   func (s *Suite) Test_NewCurrPathSlash(c *check.C) {
           t := s.Init(c)
   
           test := func(path, curr string) {
                   t.CheckEquals(NewCurrPathSlash(path).String(), curr)
           }
   
           test("filename", "filename")
           test("dir/.///file", "dir/.///file")
   }
   
   func (s *Suite) Test_NewCurrPathSlash__windows(c *check.C) {
           t := s.Init(c)
   
           test := func(path, currWindows, currOther string) {
                   t.CheckEquals(
                           NewCurrPathSlash(path).String(),
                           condStr(runtime.GOOS == "windows", currWindows, currOther))
           }
   
           test("\\", "/", "\\")
           test("dir\\.\\\\\\file", "dir/.///file", "dir\\.\\\\\\file")
   }
   
   func (s *Suite) Test_CurrPath_GoString(c *check.C) {
           t := s.Init(c)
   
           test := func(p CurrPath, str string) {
                   t.CheckEquals(p.GoString(), str)
           }
   
           // Tabs in filenames are rare, probably typos.
           test("dir/file\t", "\"dir/file\\t\"")
   }
   
   func (s *Suite) Test_CurrPath_String(c *check.C) {
           t := s.Init(c)
   
           test := func(p CurrPath, str string) {
                   t.CheckEquals(p.String(), str)
           }
   
           // Tabs in filenames are rare, probably typos.
           test("dir/file\t", "dir/file\t")
   }
   
   func (s *Suite) Test_CurrPath_AsPath(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, asPath Path) {
                   t.CheckEquals(curr.AsPath(), asPath)
           }
   
           // Tabs in filenames are rare, probably typos.
           test("dir/file\t", "dir/file\t")
   }
   
   func (s *Suite) Test_CurrPath_IsEmpty(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, isEmpty bool) {
                   t.CheckEquals(curr.IsEmpty(), isEmpty)
           }
   
           test("", true)
           test(".", false)
           test("/", false)
   }
   
   func (s *Suite) Test_CurrPath_DirClean(c *check.C) {
           t := s.Init(c)
   
           test := func(curr, dir CurrPath) {
                   t.CheckEquals(curr.DirClean(), dir)
           }
   
           test("./dir/../dir///./file", "dir")
   }
   
   func (s *Suite) Test_CurrPath_DirNoClean(c *check.C) {
           t := s.Init(c)
   
           test := func(curr, dir CurrPath) {
                   t.CheckEquals(curr.DirNoClean(), dir)
           }
   
           test("./dir/../dir///./file", "./dir/../dir")
   }
   
   func (s *Suite) Test_CurrPath_Base(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, base string) {
                   t.CheckEquals(curr.Base(), base)
           }
   
         t.CheckEquals(abc.Rel(defFile), NewPath("../../../d/e/f/file"))          test("dir/file", "file")
         t.CheckEquals(base.Rel(base), NewPath("."))  
         t.CheckEquals(abc.Rel(base), NewPath("../../../."))  
 }  }
   
 func (s *Suite) Test_Path_Rename(c *check.C) {  func (s *Suite) Test_CurrPath_Split(c *check.C) {
           t := s.Init(c)
   
           test := func(curr, dir CurrPath, base string) {
                   actualDir, actualBase := curr.Split()
                   t.CheckEquals(actualDir, dir)
                   t.CheckEquals(actualBase, base)
           }
   
           test("dir/file", "dir/", "file")
   }
   
   func (s *Suite) Test_CurrPath_Parts(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, parts ...string) {
                   t.CheckDeepEquals(curr.Parts(), parts)
           }
   
           test("dir/file", "dir", "file")
   }
   
   func (s *Suite) Test_CurrPath_IsAbs(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, isAbs bool) {
                   t.CheckDeepEquals(curr.IsAbs(), isAbs)
           }
   
           test("/", true)
           test("./", false)
           test("C:/", runtime.GOOS == "windows")
   }
   
   func (s *Suite) Test_CurrPath_HasPrefixPath(c *check.C) {
           t := s.Init(c)
   
           test := func(curr, prefix CurrPath, hasPrefix bool) {
                   t.CheckEquals(curr.HasPrefixPath(prefix), hasPrefix)
           }
   
           test("dir/file", "dir", true)
           test("dir/file", "file", false)
           test("dir", ".", true)
   }
   
   func (s *Suite) Test_CurrPath_ContainsPath(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, sub Path, hasPrefix bool) {
                   t.CheckEquals(curr.ContainsPath(sub), hasPrefix)
           }
   
           test("dir/file", "dir", true)
           test("dir/file", "file", true)
           test("dir/file", "fi", false)
           test("dir", ".", true)
   }
   
   func (s *Suite) Test_CurrPath_ContainsText(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, sub string, hasPrefix bool) {
                   t.CheckEquals(curr.ContainsText(sub), hasPrefix)
           }
   
           test("dir/file", "dir", true)
           test("dir/file", "r/f", true)
   }
   
   func (s *Suite) Test_CurrPath_HasSuffixPath(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, suffix Path, hasPrefix bool) {
                   t.CheckEquals(curr.HasSuffixPath(suffix), hasPrefix)
           }
   
           test("dir/file", "dir", false)
           test("dir/file", "file", true)
           test("dir/file", "le", false)
   
           // In contrast to HasPrefixPath, it doesn't really make sense to
           // ask whether a path ends with the current directory.
           test("dir", ".", false)
   }
   
   func (s *Suite) Test_CurrPath_HasSuffixText(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, suffix string, hasPrefix bool) {
                   t.CheckEquals(curr.HasSuffixText(suffix), hasPrefix)
           }
   
           test("dir/file", "dir", false)
           test("dir/file", "file", true)
           test("dir/file", "le", true)
   }
   
   func (s *Suite) Test_CurrPath_HasBase(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, base string, hasPrefix bool) {
                   t.CheckEquals(curr.HasBase(base), hasPrefix)
           }
   
           test("dir/file", "dir", false)
           test("dir/file", "file", true)
           test("dir/file", "le", false)
   }
   
   func (s *Suite) Test_CurrPath_TrimSuffix(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, suffix string, trimmed CurrPath) {
                   t.CheckEquals(curr.TrimSuffix(suffix), trimmed)
           }
   
           test("dir/file", "dir", "dir/file")
           test("dir/file", "file", "dir/")
           test("dir/file", "le", "dir/fi")
   }
   
   func (s *Suite) Test_CurrPath_ReplaceSuffix(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, from, to string, replaced CurrPath) {
                   t.CheckEquals(curr.ReplaceSuffix(from, to), replaced)
           }
   
           test("dir/file", "file", "subdir", "dir/subdir")
   
           // The path must actually end with the suffix, otherwise there is
           // the risk of creating unintended paths.
           t.ExpectAssert(
                   func() { test("dir/file", "no-match", "anything", "dir/file") })
   }
   
   func (s *Suite) Test_CurrPath_Clean(c *check.C) {
           t := s.Init(c)
   
           test := func(curr, cleaned CurrPath) {
                   t.CheckEquals(curr.Clean(), cleaned)
           }
   
           test("dir/file", "dir/file")
           test("dir/.////../file", "file")
   }
   
   func (s *Suite) Test_CurrPath_CleanDot(c *check.C) {
           t := s.Init(c)
   
           test := func(curr, cleaned CurrPath) {
                   t.CheckEquals(curr.CleanDot(), cleaned)
           }
   
           test("dir/file", "dir/file")
           test("dir/.////../file", "dir/../file")
   }
   
   func (s *Suite) Test_CurrPath_CleanPath(c *check.C) {
           t := s.Init(c)
   
           test := func(curr, cleaned CurrPath) {
                   t.CheckEquals(curr.CleanPath(), cleaned)
           }
   
           test("a/b/../../c/d/../../e/../f", "a/b/../../e/../f")
   }
   
   func (s *Suite) Test_CurrPath_JoinNoClean(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, rel RelPath, joined CurrPath) {
                   t.CheckEquals(curr.JoinNoClean(rel), joined)
           }
   
           test("", "", "/")
           test(".", "file", "./file")
           test("dir", "subdir/file", "dir/subdir/file")
   }
   
   func (s *Suite) Test_CurrPath_JoinClean(c *check.C) {
           t := s.Init(c)
   
           test := func(curr CurrPath, rel RelPath, joined CurrPath) {
                   t.CheckEquals(curr.JoinClean(rel), joined)
           }
   
           test("", "", "")
           test(".", "./////file", "file")
           test("dir/./.", "../subdir/file", "subdir/file")
   }
   
   func (s *Suite) Test_CurrPath_Rel(c *check.C) {
           t := s.Init(c)
   
           test := func(curr, rel CurrPath, result RelPath) {
                   t.CheckEquals(curr.Rel(rel), result)
           }
   
           test("dir/subdir", "dir", "..")
           test("dir/subdir", "file", "../../file")
   }
   
   func (s *Suite) Test_CurrPath_Rename(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         f := t.CreateFileLines("filename.old",          f := t.CreateFileLines("filename.old",
                 "line 1")                  "line 1")
         t.CheckEquals(f.IsFile(), true)          t.CheckEquals(f.IsFile(), true)
         dst := NewPath(f.TrimSuffix(".old").String() + ".new")          dst := f.ReplaceSuffix(".old", ".new")
   
         err := f.Rename(dst)          err := f.Rename(dst)
   
Line 489  func (s *Suite) Test_Path_Rename(c *chec
Line 867  func (s *Suite) Test_Path_Rename(c *chec
                 "line 1")                  "line 1")
 }  }
   
 func (s *Suite) Test_Path_Lstat(c *check.C) {  func (s *Suite) Test_CurrPath_Lstat(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         testDir := func(f Path, isDir bool) {          test := func(f CurrPath, isDir bool) {
                 st, err := f.Lstat()                  st, err := f.Lstat()
                 assertNil(err, "Lstat")                  assertNil(err, "Lstat")
                 t.CheckEquals(st.Mode()&os.ModeDir != 0, isDir)                  t.CheckEquals(st.Mode()&os.ModeDir != 0, isDir)
Line 501  func (s *Suite) Test_Path_Lstat(c *check
Line 879  func (s *Suite) Test_Path_Lstat(c *check
         t.CreateFileLines("subdir/file")          t.CreateFileLines("subdir/file")
         t.CreateFileLines("file")          t.CreateFileLines("file")
   
         testDir(t.File("subdir"), true)          test(t.File("subdir"), true)
         testDir(t.File("file"), false)          test(t.File("file"), false)
 }  }
   
 func (s *Suite) Test_Path_Stat(c *check.C) {  func (s *Suite) Test_CurrPath_Stat(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         testDir := func(f Path, isDir bool) {          test := func(f CurrPath, isDir bool) {
                 st, err := f.Stat()                  st, err := f.Stat()
                 assertNil(err, "Stat")                  assertNil(err, "Stat")
                 t.CheckEquals(st.Mode()&os.ModeDir != 0, isDir)                  t.CheckEquals(st.Mode()&os.ModeDir != 0, isDir)
Line 517  func (s *Suite) Test_Path_Stat(c *check.
Line 895  func (s *Suite) Test_Path_Stat(c *check.
         t.CreateFileLines("subdir/file")          t.CreateFileLines("subdir/file")
         t.CreateFileLines("file")          t.CreateFileLines("file")
   
         testDir(t.File("subdir"), true)          test(t.File("subdir"), true)
         testDir(t.File("file"), false)          test(t.File("file"), false)
 }  }
   
 func (s *Suite) Test_Path_Exists(c *check.C) {  func (s *Suite) Test_CurrPath_Exists(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         test := func(f Path, exists bool) {          test := func(f CurrPath, exists bool) {
                 t.CheckEquals(f.Exists(), exists)                  t.CheckEquals(f.Exists(), exists)
         }          }
   
Line 536  func (s *Suite) Test_Path_Exists(c *chec
Line 914  func (s *Suite) Test_Path_Exists(c *chec
         test(t.File("enoent"), false)          test(t.File("enoent"), false)
 }  }
   
 func (s *Suite) Test_Path_IsFile(c *check.C) {  func (s *Suite) Test_CurrPath_IsFile(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         t.CreateFileLines("dir/file")          t.CreateFileLines("dir/file")
           t.Chdir(".")
   
         t.CheckEquals(t.File("nonexistent").IsFile(), false)          test := func(curr CurrPath, isFile bool) {
         t.CheckEquals(t.File("dir").IsFile(), false)                  t.CheckEquals(curr.IsFile(), isFile)
         t.CheckEquals(t.File("dir/nonexistent").IsFile(), false)          }
         t.CheckEquals(t.File("dir/file").IsFile(), true)  
           test("nonexistent", false)
           test("dir", false)
           test("dir/nonexistent", false)
           test("dir/file", true)
 }  }
   
 func (s *Suite) Test_Path_IsDir(c *check.C) {  func (s *Suite) Test_CurrPath_IsDir(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         t.CreateFileLines("dir/file")          t.CreateFileLines("dir/file")
           t.Chdir(".")
   
           test := func(curr CurrPath, isFile bool) {
                   t.CheckEquals(curr.IsDir(), isFile)
           }
   
         t.CheckEquals(t.File("nonexistent").IsDir(), false)          test("nonexistent", false)
         t.CheckEquals(t.File("dir").IsDir(), true)          test("dir", true)
         t.CheckEquals(t.File("dir/nonexistent").IsDir(), false)          test("dir/nonexistent", false)
         t.CheckEquals(t.File("dir/file").IsDir(), false)          test("dir/file", false)
 }  }
   
 func (s *Suite) Test_Path_Chmod(c *check.C) {  func (s *Suite) Test_CurrPath_Chmod(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         testWritable := func(f Path, writable bool) {          testWritable := func(f CurrPath, writable bool) {
                 lstat, err := f.Lstat()                  lstat, err := f.Lstat()
                 assertNil(err, "Lstat")                  assertNil(err, "Lstat")
                 t.CheckEquals(lstat.Mode().Perm()&0200 != 0, writable)                  t.CheckEquals(lstat.Mode().Perm()&0200 != 0, writable)
Line 576  func (s *Suite) Test_Path_Chmod(c *check
Line 964  func (s *Suite) Test_Path_Chmod(c *check
         testWritable(f, false)          testWritable(f, false)
 }  }
   
 func (s *Suite) Test_Path_ReadDir(c *check.C) {  func (s *Suite) Test_CurrPath_ReadDir(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         t.CreateFileLines("subdir/file")          t.CreateFileLines("subdir/file")
         t.CreateFileLines("file")          t.CreateFileLines("file")
         t.CreateFileLines("CVS/Entries")          t.CreateFileLines("CVS/Entries")
         t.CreateFileLines(".git/info/exclude")          t.CreateFileLines(".git/info/exclude")
           t.Chdir(".")
   
         infos, err := t.File(".").ReadDir()          test := func(curr CurrPath, entries ...string) {
                   infos, err := curr.ReadDir()
                   assertNil(err, "ReadDir")
   
         assertNil(err, "ReadDir")                  var names []string
         var names []string                  for _, info := range infos {
         for _, info := range infos {                          names = append(names, info.Name())
                 names = append(names, info.Name())                  }
   
                   t.CheckDeepEquals(names, entries)
         }          }
   
         t.CheckDeepEquals(names, []string{".git", "CVS", "file", "subdir"})          test(".",
                   ".git", "CVS", "file", "subdir")
           test("subdir",
                   "file")
           test("CVS",
                   "Entries")
 }  }
   
 func (s *Suite) Test_Path_Open(c *check.C) {  func (s *Suite) Test_CurrPath_ReadPaths(c *check.C) {
           t := s.Init(c)
   
           t.CreateFileLines("dir/subdir/file")
           t.CreateFileLines("dir/CVS/Entries")
           t.CreateFileLines("dir/file")
           t.Chdir(".")
   
           test := func(dir CurrPath, entries ...CurrPath) {
                   t.CheckDeepEquals(dir.ReadPaths(), entries)
           }
   
           test(".",
                   "dir")
   
           test("dir",
                   "dir/file", "dir/subdir")
   }
   
   func (s *Suite) Test_CurrPath_Open(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         t.CreateFileLines("filename",          t.CreateFileLines("filename",
                 "line 1",                  "line 1",
                 "line 2")                  "line 2")
           t.Chdir(".")
   
         f, err := t.File("filename").Open()          test := func(curr CurrPath, content string) {
                   f, err := curr.Open()
                   assertNil(err, "Open")
                   defer func() { assertNil(f.Close(), "Close") }()
   
         assertNil(err, "Open")                  var sb strings.Builder
         defer func() { assertNil(f.Close(), "Close") }()                  n, err := io.Copy(&sb, f)
         var sb strings.Builder                  assertNil(err, "Copy")
         n, err := io.Copy(&sb, f)  
         assertNil(err, "Copy")                  t.CheckEquals(n, int64(len(content)))
         t.CheckEquals(n, int64(14))                  t.CheckEquals(sb.String(), content)
         t.CheckEquals(sb.String(), "line 1\nline 2\n")          }
   
           test("filename", "line 1\nline 2\n")
 }  }
   
 func (s *Suite) Test_Path_ReadString(c *check.C) {  func (s *Suite) Test_CurrPath_ReadString(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
           t.Chdir(".")
           t.CreateFileLines("empty")
         t.CreateFileLines("filename",          t.CreateFileLines("filename",
                 "line 1",                  "line 1",
                 "line 2")                  "line 2")
   
         text, err := t.File("filename").ReadString()          test := func(curr CurrPath, content string) {
                   text, err := curr.ReadString()
   
                   assertNil(err, "ReadString")
                   t.CheckEquals(text, content)
           }
   
         assertNil(err, "ReadString")          test("empty", "")
         t.CheckEquals(text, "line 1\nline 2\n")          test("filename", "line 1\nline 2\n")
 }  }
   
 func (s *Suite) Test_Path_WriteString(c *check.C) {  func (s *Suite) Test_CurrPath_WriteString(c *check.C) {
         t := s.Init(c)          t := s.Init(c)
   
         err := t.File("filename").WriteString("line 1\nline 2\n")          t.Chdir(".")
   
         assertNil(err, "WriteString")          test := func(curr CurrPath, content string, lines ...string) {
         t.CheckFileLines("filename",                  err := curr.WriteString(content)
                   assertNil(err, "WriteString")
   
                   t.CheckFileLines(NewRelPath(curr.AsPath()),
                           lines...)
           }
   
           test("empty", "",
                   nil...)
   
           test("filename", "line 1\nline 2\n",
                 "line 1",                  "line 1",
                 "line 2")                  "line 2")
 }  }
   
   func (s *Suite) Test_NewPkgsrcPath(c *check.C) {
           t := s.Init(c)
   
           p := NewPkgsrcPath("category/package")
   
           t.CheckEquals(p.AsPath(), NewPath("category/package"))
   }
   
   func (s *Suite) Test_PkgsrcPath_String(c *check.C) {
           t := s.Init(c)
   
           p := NewPkgsrcPath("any string..././")
   
           str := p.String()
   
           // No normalization takes place because it is typically not needed.
           t.CheckEquals(str, "any string..././")
   }
   
   func (s *Suite) Test_PkgsrcPath_AsPath(c *check.C) {
           t := s.Init(c)
   
           pp := NewPkgsrcPath("./category/package/Makefile")
   
           p := pp.AsPath()
   
           t.CheckEquals(p.String(), "./category/package/Makefile")
   }
   
   func (s *Suite) Test_PkgsrcPath_AsRelPath(c *check.C) {
           t := s.Init(c)
   
           pp := NewPkgsrcPath("./category/package/Makefile")
   
           rel := pp.AsRelPath()
   
           t.CheckEquals(rel.String(), "./category/package/Makefile")
   }
   
   func (s *Suite) Test_PkgsrcPath_DirClean(c *check.C) {
           t := s.Init(c)
   
           test := func(pp, cleaned PkgsrcPath) {
                   t.CheckEquals(pp.DirClean(), cleaned)
           }
   
           test("./dir/../dir/base///.", "dir/base")
   }
   
   func (s *Suite) Test_PkgsrcPath_DirNoClean(c *check.C) {
           t := s.Init(c)
   
           test := func(pp, cleaned PkgsrcPath) {
                   t.CheckEquals(pp.DirNoClean(), cleaned)
           }
   
           test("./dir/../dir/base///.", "./dir/../dir/base")
   }
   
   func (s *Suite) Test_PkgsrcPath_Base(c *check.C) {
           t := s.Init(c)
   
           test := func(pp PkgsrcPath, base string) {
                   t.CheckEquals(pp.Base(), base)
           }
   
           test("./dir/../dir/base///.", ".")
   }
   
   func (s *Suite) Test_PkgsrcPath_Count(c *check.C) {
           t := s.Init(c)
   
           test := func(pp PkgsrcPath, count int) {
                   t.CheckEquals(pp.Count(), count)
           }
   
           test("./...////dir", 2)
   }
   
   func (s *Suite) Test_PkgsrcPath_HasPrefixPath(c *check.C) {
           t := s.Init(c)
   
           test := func(pp PkgsrcPath, prefix Path, hasPrefixPath bool) {
                   t.CheckEquals(pp.HasPrefixPath(prefix), hasPrefixPath)
           }
   
           test("./././///prefix/suffix", "prefix", true)
   }
   
   func (s *Suite) Test_PkgsrcPath_JoinNoClean(c *check.C) {
           t := s.Init(c)
   
           test := func(pp PkgsrcPath, rel RelPath, joined PkgsrcPath) {
                   t.CheckEquals(pp.JoinNoClean(rel), joined)
           }
   
           test("base///.", "./../rel", "base///././../rel")
   }
   
   func (s *Suite) Test_NewPackagePath(c *check.C) {
           t := s.Init(c)
   
           p := NewPackagePath("../../category/package")
   
           t.CheckEquals(p.AsPath(), NewPath("../../category/package"))
   }
   
   func (s *Suite) Test_NewPackagePathString(c *check.C) {
           t := s.Init(c)
   
           p := NewPackagePathString("../../category/package")
   
           t.CheckEquals(p.AsPath(), NewPath("../../category/package"))
   }
   
   func (s *Suite) Test_PackagePath_AsPath(c *check.C) {
           t := s.Init(c)
   
           pp := NewPackagePath("../../category/package/Makefile")
   
           p := pp.AsPath()
   
           t.CheckEquals(p.String(), "../../category/package/Makefile")
   }
   
   func (s *Suite) Test_PackagePath_AsRelPath(c *check.C) {
           t := s.Init(c)
   
           pp := NewPackagePath("./category/package/Makefile")
   
           rel := pp.AsRelPath()
   
           t.CheckEquals(rel.String(), "./category/package/Makefile")
   }
   
   func (s *Suite) Test_PackagePath_String(c *check.C) {
           t := s.Init(c)
   
           pp := NewPackagePath("../../category/package/Makefile")
   
           str := pp.String()
   
           t.CheckEquals(str, "../../category/package/Makefile")
   }
   
   func (s *Suite) Test_PackagePath_JoinNoClean(c *check.C) {
           t := s.Init(c)
   
           test := func(pp PackagePath, other RelPath, joined PackagePath) {
                   t.CheckEquals(pp.JoinNoClean(other), joined)
   
           }
   
           test("../../category/package/patches", "patch-aa",
                   "../../category/package/patches/patch-aa")
   }
   
   func (s *Suite) Test_PackagePath_IsEmpty(c *check.C) {
           t := s.Init(c)
   
           test := func(p PackagePath, isEmpty bool) {
                   t.CheckEquals(p.IsEmpty(), isEmpty)
           }
   
           test("", true)
           test(".", false)
   }
   
   func (s *Suite) Test_NewRelPath(c *check.C) {
           t := s.Init(c)
   
           rel := NewRelPath("dir/file")
   
           t.CheckEquals(rel.String(), "dir/file")
   }
   
   func (s *Suite) Test_NewRelPathString(c *check.C) {
           t := s.Init(c)
   
           rel := NewRelPathString("dir/file")
   
           t.CheckEquals(rel.String(), "dir/file")
   }
   
   func (s *Suite) Test_RelPath_AsPath(c *check.C) {
           t := s.Init(c)
   
           rel := NewRelPath("relative")
   
           path := rel.AsPath()
   
           t.CheckEquals(path.String(), "relative")
   }
   
   func (s *Suite) Test_RelPath_String(c *check.C) {
           t := s.Init(c)
   
           rel := NewRelPath(".///rel")
   
           str := rel.String()
   
           t.CheckEquals(str, ".///rel")
   }
   
   func (s *Suite) Test_RelPath_IsEmpty(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, isEmpty bool) {
                   t.CheckEquals(rel.IsEmpty(), isEmpty)
           }
   
           test("", true)
           test(".", false)
           test("/", false)
   }
   
   func (s *Suite) Test_RelPath_Split(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, dir RelPath, base string) {
                   actualDir, actualBase := rel.Split()
                   t.CheckEquals(actualDir, dir)
                   t.CheckEquals(actualBase, base)
           }
   
           test("dir/file", "dir/", "file")
           test("././///file", "././///", "file")
   
           t.ExpectAssert(
                   func() { test("/", "/", "") })
   
   }
   
   func (s *Suite) Test_RelPath_DirClean(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, dir RelPath) {
                   t.CheckEquals(rel.DirClean(), dir)
           }
   
           test("./dir/../dir///./file", "dir")
   }
   
   func (s *Suite) Test_RelPath_DirNoClean(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, dir RelPath) {
                   t.CheckEquals(rel.DirNoClean(), dir)
           }
   
           test("./dir/../dir///./file", "./dir/../dir")
   }
   
   func (s *Suite) Test_RelPath_Base(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, base string) {
                   t.CheckEquals(rel.Base(), base)
           }
   
           test("./dir/../dir///./file", "file")
   }
   
   func (s *Suite) Test_RelPath_HasBase(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, base string, hasBase bool) {
                   t.CheckEquals(rel.HasBase(base), hasBase)
           }
   
           test("./dir/Makefile", "Makefile", true)
           test("./dir/Makefile", "Make", false)
           test("./dir/Makefile", "file", false)
           test("./dir/Makefile", "dir/Makefile", false)
   }
   
   func (s *Suite) Test_RelPath_Parts(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, parts ...string) {
                   t.CheckDeepEquals(rel.Parts(), parts)
           }
   
           test("./dir/.///base", "dir", "base")
   }
   
   func (s *Suite) Test_RelPath_Count(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, count int) {
                   t.CheckEquals(rel.Count(), count)
           }
   
           test("./dir/.///base", 2)
   }
   
   func (s *Suite) Test_RelPath_Clean(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, cleaned RelPath) {
                   t.CheckDeepEquals(rel.Clean(), cleaned)
           }
   
           test("a/b/../../c/d/../.././e/../f", "f")
   }
   
   func (s *Suite) Test_RelPath_CleanDot(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, cleaned RelPath) {
                   t.CheckEquals(rel.CleanDot(), cleaned)
           }
   
           test("a/b/../../c/d/../.././e/../f", "a/b/../../c/d/../../e/../f")
   }
   
   func (s *Suite) Test_RelPath_CleanPath(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, cleaned RelPath) {
                   t.CheckEquals(rel.CleanPath(), cleaned)
           }
   
           test("a/b/../../c/d/../.././e/../f", "a/b/../../e/../f")
   }
   
   func (s *Suite) Test_RelPath_JoinNoClean(c *check.C) {
           t := s.Init(c)
   
           test := func(rel, other, joined RelPath) {
                   t.CheckEquals(rel.JoinNoClean(other), joined)
           }
   
           test("basedir/.//", "./other", "basedir/.///./other")
   }
   
   func (s *Suite) Test_RelPath_Replace(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, from, to string, result RelPath) {
                   t.CheckEquals(rel.Replace(from, to), result)
           }
   
           test("dir/subdir/file", "/", ":", "dir:subdir:file")
   }
   
   func (s *Suite) Test_RelPath_HasPrefixPath(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, prefix Path, hasPrefixPath bool) {
                   t.CheckEquals(rel.HasPrefixPath(prefix), hasPrefixPath)
           }
   
           test("dir/subdir/file", "dir", true)
           test("dir/subdir/file", "dir/sub", false)
           test("dir/subdir/file", "subdir", false)
   }
   
   func (s *Suite) Test_RelPath_HasPrefixText(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, prefix string, hasPrefixPath bool) {
                   t.CheckEquals(rel.HasPrefixText(prefix), hasPrefixPath)
           }
   
           test("dir/subdir/file", "dir", true)
           test("dir/subdir/file", "dir/sub", true)
           test("dir/subdir/file", "subdir", false)
           test("dir/subdir/file", "super", false)
   }
   
   func (s *Suite) Test_RelPath_ContainsPath(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, prefix Path, hasPrefixPath bool) {
                   t.CheckEquals(rel.ContainsPath(prefix), hasPrefixPath)
           }
   
           test("dir/subdir/file", "dir", true)
           test("dir/subdir/file", "dir/sub", false)
           test("dir/subdir/file", "subdir", true)
   }
   
   func (s *Suite) Test_RelPath_ContainsText(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, prefix string, hasPrefixPath bool) {
                   t.CheckEquals(rel.ContainsText(prefix), hasPrefixPath)
           }
   
           test("dir/subdir/file", "dir", true)
           test("dir/subdir/file", "dir/sub", true)
           test("dir/subdir/file", "subdir", true)
           test("dir/subdir/file", "super", false)
   }
   
   func (s *Suite) Test_RelPath_HasSuffixPath(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, prefix Path, hasPrefixPath bool) {
                   t.CheckEquals(rel.HasSuffixPath(prefix), hasPrefixPath)
           }
   
           test("dir/subdir/file", "dir", false)
           test("dir/subdir/file", "file", true)
           test("dir/subdir/file", "le", false)
           test("dir/subdir/file", "subdir/file", true)
           test("dir/subdir/file", "subdir", false)
   }
   
   func (s *Suite) Test_RelPath_HasSuffixText(c *check.C) {
           t := s.Init(c)
   
           test := func(rel RelPath, prefix string, hasPrefixPath bool) {
                   t.CheckEquals(rel.HasSuffixText(prefix), hasPrefixPath)
           }
   
           test("dir/subdir/file", "dir", false)
           test("dir/subdir/file", "file", true)
           test("dir/subdir/file", "le", true)
           test("dir/subdir/file", "subdir/file", true)
           test("dir/subdir/file", "subdir", false)
   }
   
   func (s *Suite) Test_RelPath_Rel(c *check.C) {
           t := s.Init(c)
   
           test := func(base RelPath, other Path, result RelPath) {
                   t.CheckEquals(base.Rel(other), result)
           }
   
           test("a/b/c", "d/e/f/file", "../../../d/e/f/file")
           test(".", ".", ".")
   
           // The trailing dot marks the difference between a file and a directory.
           // This is the same behavior as with filepath.Rel.
           test("a/b/c", ".", "../../../.")
   }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.8

CVSweb <webmaster@jp.NetBSD.org>