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

Annotation of pkgsrc/pkgtools/pkglint/files/path_test.go, Revision 1.3

1.1       rillig      1: package pkglint
                      2:
                      3: import (
                      4:        "gopkg.in/check.v1"
                      5:        "io"
                      6:        "os"
                      7:        "runtime"
                      8:        "strings"
                      9: )
                     10:
                     11: func (s *Suite) Test_NewPath(c *check.C) {
                     12:        t := s.Init(c)
                     13:
                     14:        t.CheckEquals(NewPath("filename"), NewPath("filename"))
                     15:        t.CheckEquals(NewPath("\\"), NewPath("\\"))
                     16:        c.Check(NewPath("\\"), check.Not(check.Equals), NewPath("/"))
                     17: }
                     18:
                     19: func (s *Suite) Test_NewPathSlash(c *check.C) {
                     20:        t := s.Init(c)
                     21:
                     22:        t.CheckEquals(NewPathSlash("filename"), NewPathSlash("filename"))
                     23:        t.CheckEquals(NewPathSlash("\\"), NewPathSlash("\\"))
                     24:
                     25:        t.CheckEquals(
                     26:                NewPathSlash("\\"),
                     27:                NewPathSlash(condStr(runtime.GOOS == "windows", "/", "\\")))
                     28: }
                     29:
                     30: func (s *Suite) Test_Path_String(c *check.C) {
                     31:        t := s.Init(c)
                     32:
                     33:        for _, p := range []string{"", "filename", "a/b", "c\\d"} {
                     34:                t.CheckEquals(NewPath(p).String(), p)
                     35:        }
                     36: }
                     37:
                     38: func (s *Suite) Test_Path_GoString(c *check.C) {
                     39:        t := s.Init(c)
                     40:
                     41:        test := func(p Path, s string) {
                     42:                t.CheckEquals(p.GoString(), s)
                     43:        }
                     44:
                     45:        test("", "\"\"")
                     46:        test("filename", "\"filename\"")
                     47:        test("a/b", "\"a/b\"")
                     48:        test("c\\d", "\"c\\\\d\"")
                     49: }
                     50:
1.3     ! rillig     51: func (s *Suite) Test_Path_IsEmpty(c *check.C) {
        !            52:        t := s.Init(c)
        !            53:
        !            54:        test := func(p Path, isEmpty bool) {
        !            55:                t.CheckEquals(p.IsEmpty(), isEmpty)
        !            56:        }
        !            57:
        !            58:        test("", true)
        !            59:        test(".", false)
        !            60:        test("/", false)
        !            61: }
        !            62:
1.1       rillig     63: func (s *Suite) Test_Path_Dir(c *check.C) {
                     64:        t := s.Init(c)
                     65:
                     66:        test := func(p, dir Path) {
                     67:                t.CheckEquals(p.Dir(), dir)
                     68:        }
                     69:
                     70:        test("", ".")
                     71:        test("././././", ".")
                     72:        test("/root", "/")
                     73:        test("filename", ".")
                     74:        test("dir/filename", "dir")
                     75:        test("dir/filename\\with\\backslash", "dir")
                     76: }
                     77:
                     78: func (s *Suite) Test_Path_Base(c *check.C) {
                     79:        t := s.Init(c)
                     80:
                     81:        test := func(p Path, base string) {
                     82:                t.CheckEquals(p.Base(), base)
                     83:        }
                     84:
                     85:        test("", ".") // That's a bit surprising
                     86:        test("././././", ".")
                     87:        test("/root", "root")
                     88:        test("filename", "filename")
                     89:        test("dir/filename", "filename")
                     90:        test("dir/filename\\with\\backslash", "filename\\with\\backslash")
                     91: }
                     92:
                     93: func (s *Suite) Test_Path_Split(c *check.C) {
                     94:        t := s.Init(c)
                     95:
                     96:        test := func(p, dir, base string) {
                     97:                actualDir, actualBase := NewPath(p).Split()
                     98:
                     99:                t.CheckDeepEquals(
                    100:                        []string{actualDir.String(), actualBase},
                    101:                        []string{dir, base})
                    102:        }
                    103:
                    104:        test("", "", "")
                    105:        test("././././", "././././", "")
                    106:        test("/root", "/", "root")
                    107:        test("filename", "", "filename")
                    108:        test("dir/filename", "dir/", "filename")
                    109:        test("dir/filename\\with\\backslash", "dir/", "filename\\with\\backslash")
                    110: }
                    111:
                    112: func (s *Suite) Test_Path_Parts(c *check.C) {
                    113:        t := s.Init(c)
                    114:
                    115:        test := func(p string, parts ...string) {
                    116:                t.CheckDeepEquals(NewPath(p).Parts(), parts)
                    117:        }
                    118:
1.2       rillig    119:        // Only the empty path returns an empty slice.
                    120:        test("", nil...)
                    121:
                    122:        // The standard cases for relative paths.
                    123:        test("relative", "relative")
                    124:        test("relative/subdir", "relative", "subdir")
                    125:        test("relative////subdir", "relative", "subdir")
                    126:        test("relative/..", "relative", "..")
                    127:        test("relative/.", "relative")
                    128:
                    129:        // Leading dots are removed when they are followed by something.
                    130:        test("./relative", "relative")
                    131:
                    132:        // A path consisting of only dots produces a single dot.
                    133:        test("./././.", ".")
                    134:
                    135:        // Slashes at the end are treated like a single dot.
                    136:        test("././././", ".")
                    137:        test(".///////", ".")
                    138:
                    139:        // Absolute paths have an empty first component.
                    140:        test("/", "")
                    141:        test("/.", "")
                    142:        test("/root", "", "root")
                    143:
                    144:        // The backslash is not a path separator.
1.1       rillig    145:        test("dir/filename\\with\\backslash", "dir", "filename\\with\\backslash")
                    146: }
                    147:
                    148: func (s *Suite) Test_Path_Count(c *check.C) {
                    149:        t := s.Init(c)
                    150:
                    151:        test := func(p string, count int) {
                    152:                t.CheckEquals(NewPath(p).Count(), count)
                    153:        }
                    154:
1.2       rillig    155:        test("././././", 1)
                    156:        test("/root", 2)
1.1       rillig    157:        test("filename", 1)
                    158:        test("dir/filename", 2)
                    159:        test("dir/filename\\with\\backslash", 2)
1.2       rillig    160:
                    161:        // Only the empty path returns an empty slice.
                    162:        test("", 0)
                    163:
                    164:        // The standard cases for canonical relative paths.
                    165:        test("relative", 1)
                    166:        test("relative/subdir", 2)
                    167:        test("relative////subdir", 2)
                    168:        test("relative/..", 2)
                    169:        test("relative/.", 1)
                    170:
                    171:        // A path consisting of only dots produces a single dot.
                    172:        test("./././.", 1)
                    173:
                    174:        // Slashes at the end are treated like a single dot.
                    175:        test("././././", 1)
                    176:        test(".///////", 1)
                    177:
                    178:        // Absolute paths have an empty first component.
                    179:        test("/", 1)
                    180:        test("/.", 1)
                    181:        test("/root", 2)
                    182:
                    183:        // The backslash is not a path separator.
                    184:        test("dir/filename\\with\\backslash", 2)
1.1       rillig    185: }
                    186:
                    187: func (s *Suite) Test_Path_HasPrefixText(c *check.C) {
                    188:        t := s.Init(c)
                    189:
                    190:        test := func(p, prefix string, hasPrefix bool) {
                    191:                t.CheckEquals(NewPath(p).HasPrefixText(prefix), hasPrefix)
                    192:        }
                    193:
                    194:        test("", "", true)
                    195:        test("filename", "", true)
                    196:        test("", "x", false)
                    197:        test("/root", "/r", true)
                    198:        test("/root", "/root", true)
                    199:        test("/root", "/root/", false)
                    200:        test("/root", "root/", false)
                    201: }
                    202:
                    203: func (s *Suite) Test_Path_HasPrefixPath(c *check.C) {
                    204:        t := s.Init(c)
                    205:
                    206:        test := func(p, prefix Path, hasPrefix bool) {
                    207:                t.CheckEquals(p.HasPrefixPath(prefix), hasPrefix)
                    208:        }
                    209:
                    210:        test("", "", true)
                    211:        test("filename", "", false)
                    212:        test("", "x", false)
                    213:        test("/root", "/r", false)
                    214:        test("/root", "/root", true)
1.2       rillig    215:
                    216:        // Even though the textual representation of the prefix is longer than
                    217:        // the path. The trailing slash marks the path as a directory, and
                    218:        // there are only a few cases where the difference matters, such as
                    219:        // in rsync and mkdir.
                    220:        test("/root", "/root/", true)
                    221:
1.1       rillig    222:        test("/root/", "/root", true)
1.2       rillig    223:        test("/root/", "root", false)
1.1       rillig    224:        test("/root/subdir", "/root", true)
1.2       rillig    225:        test("filename", ".", true)
                    226:        test("filename", "./filename", true)
                    227:        test("filename", "./file", false)
                    228:        test("filename", "./filename/sub", false)
                    229:        test("/anything", ".", false)
1.1       rillig    230: }
                    231:
                    232: func (s *Suite) Test_Path_ContainsText(c *check.C) {
                    233:        t := s.Init(c)
                    234:
                    235:        test := func(p Path, text string, contains bool) {
                    236:                t.CheckEquals(p.ContainsText(text), contains)
                    237:        }
                    238:
                    239:        test("", "", true)
                    240:        test("filename", "", true)
                    241:        test("filename", ".", false)
                    242:        test("a.b", ".", true)
                    243:        test("..", ".", true)
                    244:        test("", "x", false)
                    245:        test("/root", "/r", true)
                    246:        test("/root", "/root", true)
                    247:        test("/root", "/root/", false)
                    248:        test("/root", "root/", false)
                    249:        test("/root", "ro", true)
                    250:        test("/root", "ot", true)
                    251: }
                    252:
                    253: func (s *Suite) Test_Path_ContainsPath(c *check.C) {
                    254:        t := s.Init(c)
                    255:
                    256:        test := func(p, sub Path, contains bool) {
                    257:                t.CheckEquals(p.ContainsPath(sub), contains)
                    258:        }
                    259:
                    260:        test("", "", true)          // It doesn't make sense to search for empty paths.
                    261:        test(".", "", false)        // It doesn't make sense to search for empty paths.
1.3     ! rillig    262:        test("filename", ".", true) // Every relative path contains "." implicitly at the beginning
1.1       rillig    263:        test("a.b", ".", true)
                    264:        test("..", ".", true)
                    265:        test("filename", "", false)
                    266:        test("filename", "filename", true)
                    267:        test("a/b/c", "a", true)
                    268:        test("a/b/c", "b", true)
                    269:        test("a/b/c", "c", true)
                    270:        test("a/b/c", "a/b", true)
                    271:        test("a/b/c", "b/c", true)
                    272:        test("a/b/c", "a/b/c", true)
                    273:        test("aa/b/c", "a", false)
                    274:        test("a/bb/c", "b", false)
                    275:        test("a/bb/c", "b/c", false)
                    276:        test("mk/fetch/fetch.mk", "mk", true)
                    277:        test("category/package/../../wip/mk/../..", "mk", true)
1.3     ! rillig    278:
        !           279:        test("a", "a", true)
        !           280:        test("a", "b", false)
        !           281:        test("a", "A", false)
        !           282:        test("a/b/c", "a", true)
        !           283:        test("a/b/c", "b", true)
        !           284:        test("a/b/c", "c", true)
        !           285:        test("a/b/c", "a/b", true)
        !           286:        test("a/b/c", "b/c", true)
        !           287:        test("a/b/c", "a/b/c", true)
        !           288:        test("aa/bb/cc", "a/b", false)
        !           289:        test("aa/bb/cc", "a/bb", false)
        !           290:        test("aa/bb/cc", "aa/b", false)
        !           291:        test("aa/bb/cc", "aa/bb", true)
        !           292:        test("aa/bb/cc", "a", false)
        !           293:        test("aa/bb/cc", "b", false)
        !           294:        test("aa/bb/cc", "c", false)
1.1       rillig    295: }
                    296:
                    297: func (s *Suite) Test_Path_ContainsPathCanonical(c *check.C) {
                    298:        t := s.Init(c)
                    299:
                    300:        test := func(p, sub Path, contains bool) {
                    301:                t.CheckEquals(p.ContainsPathCanonical(sub), contains)
                    302:        }
                    303:
                    304:        test("", "", false)
                    305:        test(".", "", false)
                    306:        test("filename", "", false)
                    307:        test("filename", "filename", true)
                    308:        test("a/b/c", "a", true)
                    309:        test("a/b/c", "b", true)
                    310:        test("a/b/c", "c", true)
                    311:        test("a/b/c", "a/b", true)
                    312:        test("a/b/c", "b/c", true)
                    313:        test("a/b/c", "a/b/c", true)
                    314:        test("aa/b/c", "a", false)
                    315:        test("a/bb/c", "b", false)
                    316:        test("a/bb/c", "b/c", false)
                    317:        test("mk/fetch/fetch.mk", "mk", true)
                    318:        test("category/package/../../wip/mk", "mk", true)
                    319:        test("category/package/../../wip/mk/..", "mk", true) // FIXME
                    320:        test("category/package/../../wip/mk/../..", "mk", false)
                    321: }
                    322:
                    323: func (s *Suite) Test_Path_HasSuffixText(c *check.C) {
                    324:        t := s.Init(c)
                    325:
                    326:        test := func(p Path, suffix string, has bool) {
                    327:                t.CheckEquals(p.HasSuffixText(suffix), has)
                    328:        }
                    329:
                    330:        test("", "", true)
                    331:        test("a/bb/c", "", true)
                    332:        test("a/bb/c", "c", true)
                    333:        test("a/bb/c", "/c", true)
                    334:        test("a/bb/c", "b/c", true)
                    335:        test("aa/b/c", "bb", false)
                    336: }
                    337:
                    338: func (s *Suite) Test_Path_HasSuffixPath(c *check.C) {
                    339:        t := s.Init(c)
                    340:
                    341:        test := func(p, suffix Path, has bool) {
                    342:                t.CheckEquals(p.HasSuffixPath(suffix), has)
                    343:        }
                    344:
                    345:        test("", "", true)
                    346:        test("a/bb/c", "", false)
                    347:        test("a/bb/c", "c", true)
                    348:        test("a/bb/c", "/c", false)
                    349:        test("a/bb/c", "b/c", false)
                    350:        test("aa/b/c", "bb", false)
                    351: }
                    352:
                    353: func (s *Suite) Test_Path_HasBase(c *check.C) {
                    354:        t := s.Init(c)
                    355:
                    356:        test := func(p Path, suffix string, hasBase bool) {
                    357:                t.CheckEquals(p.HasBase(suffix), hasBase)
                    358:        }
                    359:
                    360:        test("dir/file", "e", false)
                    361:        test("dir/file", "file", true)
                    362:        test("dir/file", "file.ext", false)
                    363:        test("dir/file", "/file", false)
                    364:        test("dir/file", "dir/file", false)
                    365: }
                    366:
                    367: func (s *Suite) Test_Path_TrimSuffix(c *check.C) {
                    368:        t := s.Init(c)
                    369:
                    370:        test := func(p Path, suffix string, result Path) {
                    371:                t.CheckEquals(p.TrimSuffix(suffix), result)
                    372:        }
                    373:
                    374:        test("dir/file", "e", "dir/fil")
                    375:        test("dir/file", "file", "dir/")
                    376:        test("dir/file", "/file", "dir")
                    377:        test("dir/file", "dir/file", "")
                    378:        test("dir/file", "subdir/file", "dir/file")
                    379: }
                    380:
                    381: func (s *Suite) Test_Path_Replace(c *check.C) {
                    382:        t := s.Init(c)
                    383:
                    384:        test := func(p Path, from, to string, result Path) {
                    385:                t.CheckEquals(p.Replace(from, to), result)
                    386:        }
                    387:
                    388:        test("dir/file", "dir", "other", "other/file")
                    389:        test("dir/file", "r", "sk", "disk/file")
                    390:        test("aaa/file", "a", "sub/", "sub/sub/sub//file")
                    391: }
                    392:
                    393: func (s *Suite) Test_Path_JoinClean(c *check.C) {
                    394:        t := s.Init(c)
                    395:
                    396:        test := func(p Path, suffix Path, result Path) {
                    397:                t.CheckEquals(p.JoinClean(suffix), result)
                    398:        }
                    399:
                    400:        test("dir", "file", "dir/file")
                    401:        test("dir", "///file", "dir/file")
                    402:        test("dir/./../dir/", "///file", "dir/file")
                    403:        test("dir", "..", ".")
                    404: }
                    405:
                    406: func (s *Suite) Test_Path_JoinNoClean(c *check.C) {
                    407:        t := s.Init(c)
                    408:
                    409:        test := func(p, suffix Path, result Path) {
                    410:                t.CheckEquals(p.JoinNoClean(suffix), result)
                    411:        }
                    412:
                    413:        test("dir", "file", "dir/file")
                    414:        test("dir", "///file", "dir////file")
                    415:        test("dir/./../dir/", "///file", "dir/./../dir/////file")
                    416:        test("dir", "..", "dir/..")
                    417: }
                    418:
                    419: func (s *Suite) Test_Path_Clean(c *check.C) {
                    420:        t := s.Init(c)
                    421:
                    422:        test := func(p, result Path) {
                    423:                t.CheckEquals(p.Clean(), result)
                    424:        }
                    425:
                    426:        test("", ".")
                    427:        test(".", ".")
                    428:        test("./././", ".")
                    429:        test("a/bb///../c", "a/c")
                    430: }
                    431:
1.2       rillig    432: func (s *Suite) Test_Path_CleanDot(c *check.C) {
                    433:        t := s.Init(c)
                    434:
                    435:        test := func(p, result Path) {
                    436:                t.CheckEquals(p.CleanDot(), result)
                    437:        }
                    438:
                    439:        test("", "")
                    440:        test(".", ".")
                    441:        test("./././", ".")
                    442:        test("a/bb///../c", "a/bb/../c")
                    443:        test("./filename", "filename")
                    444:        test("/absolute", "/absolute")
                    445:        test("/usr/pkgsrc/wip/package", "/usr/pkgsrc/wip/package")
                    446:        test("/usr/pkgsrc/wip/package/../mk/git-package.mk", "/usr/pkgsrc/wip/package/../mk/git-package.mk")
                    447: }
                    448:
1.1       rillig    449: func (s *Suite) Test_Path_IsAbs(c *check.C) {
                    450:        t := s.Init(c)
                    451:
                    452:        test := func(p Path, abs bool) {
                    453:                t.CheckEquals(p.IsAbs(), abs)
                    454:        }
                    455:
                    456:        test("", false)
                    457:        test(".", false)
                    458:        test("a/b", false)
                    459:        test("/a", true)
                    460:        test("C:/", runtime.GOOS == "windows")
                    461:        test("c:/", runtime.GOOS == "windows")
                    462: }
                    463:
                    464: func (s *Suite) Test_Path_Rel(c *check.C) {
                    465:        t := s.Init(c)
                    466:
                    467:        base := NewPath(".")
                    468:        abc := NewPath("a/b/c")
                    469:        defFile := NewPath("d/e/f/file")
                    470:
                    471:        t.CheckEquals(abc.Rel(defFile), NewPath("../../../d/e/f/file"))
                    472:        t.CheckEquals(base.Rel(base), NewPath("."))
                    473:        t.CheckEquals(abc.Rel(base), NewPath("../../../."))
                    474: }
                    475:
                    476: func (s *Suite) Test_Path_Rename(c *check.C) {
                    477:        t := s.Init(c)
                    478:
                    479:        f := t.CreateFileLines("filename.old",
                    480:                "line 1")
                    481:        t.CheckEquals(f.IsFile(), true)
                    482:        dst := NewPath(f.TrimSuffix(".old").String() + ".new")
                    483:
                    484:        err := f.Rename(dst)
                    485:
                    486:        assertNil(err, "Rename")
                    487:        t.CheckEquals(f.IsFile(), false)
                    488:        t.CheckFileLines("filename.new",
                    489:                "line 1")
                    490: }
                    491:
                    492: func (s *Suite) Test_Path_Lstat(c *check.C) {
                    493:        t := s.Init(c)
                    494:
                    495:        testDir := func(f Path, isDir bool) {
                    496:                st, err := f.Lstat()
                    497:                assertNil(err, "Lstat")
                    498:                t.CheckEquals(st.Mode()&os.ModeDir != 0, isDir)
                    499:        }
                    500:
                    501:        t.CreateFileLines("subdir/file")
                    502:        t.CreateFileLines("file")
                    503:
                    504:        testDir(t.File("subdir"), true)
                    505:        testDir(t.File("file"), false)
                    506: }
                    507:
                    508: func (s *Suite) Test_Path_Stat(c *check.C) {
                    509:        t := s.Init(c)
                    510:
                    511:        testDir := func(f Path, isDir bool) {
                    512:                st, err := f.Stat()
                    513:                assertNil(err, "Stat")
                    514:                t.CheckEquals(st.Mode()&os.ModeDir != 0, isDir)
                    515:        }
                    516:
                    517:        t.CreateFileLines("subdir/file")
                    518:        t.CreateFileLines("file")
                    519:
                    520:        testDir(t.File("subdir"), true)
                    521:        testDir(t.File("file"), false)
                    522: }
                    523:
                    524: func (s *Suite) Test_Path_Exists(c *check.C) {
                    525:        t := s.Init(c)
                    526:
                    527:        test := func(f Path, exists bool) {
                    528:                t.CheckEquals(f.Exists(), exists)
                    529:        }
                    530:
                    531:        t.CreateFileLines("subdir/file")
                    532:        t.CreateFileLines("file")
                    533:
                    534:        test(t.File("subdir"), true)
                    535:        test(t.File("file"), true)
                    536:        test(t.File("enoent"), false)
                    537: }
                    538:
                    539: func (s *Suite) Test_Path_IsFile(c *check.C) {
                    540:        t := s.Init(c)
                    541:
                    542:        t.CreateFileLines("dir/file")
                    543:
                    544:        t.CheckEquals(t.File("nonexistent").IsFile(), false)
                    545:        t.CheckEquals(t.File("dir").IsFile(), false)
                    546:        t.CheckEquals(t.File("dir/nonexistent").IsFile(), false)
                    547:        t.CheckEquals(t.File("dir/file").IsFile(), true)
                    548: }
                    549:
                    550: func (s *Suite) Test_Path_IsDir(c *check.C) {
                    551:        t := s.Init(c)
                    552:
                    553:        t.CreateFileLines("dir/file")
                    554:
                    555:        t.CheckEquals(t.File("nonexistent").IsDir(), false)
                    556:        t.CheckEquals(t.File("dir").IsDir(), true)
                    557:        t.CheckEquals(t.File("dir/nonexistent").IsDir(), false)
                    558:        t.CheckEquals(t.File("dir/file").IsDir(), false)
                    559: }
                    560:
                    561: func (s *Suite) Test_Path_Chmod(c *check.C) {
                    562:        t := s.Init(c)
                    563:
                    564:        testWritable := func(f Path, writable bool) {
                    565:                lstat, err := f.Lstat()
                    566:                assertNil(err, "Lstat")
                    567:                t.CheckEquals(lstat.Mode().Perm()&0200 != 0, writable)
                    568:        }
                    569:
                    570:        f := t.CreateFileLines("file")
                    571:        testWritable(f, true)
                    572:
                    573:        err := f.Chmod(0444)
                    574:        assertNil(err, "Chmod")
                    575:
                    576:        testWritable(f, false)
                    577: }
                    578:
                    579: func (s *Suite) Test_Path_ReadDir(c *check.C) {
                    580:        t := s.Init(c)
                    581:
                    582:        t.CreateFileLines("subdir/file")
                    583:        t.CreateFileLines("file")
                    584:        t.CreateFileLines("CVS/Entries")
                    585:        t.CreateFileLines(".git/info/exclude")
                    586:
                    587:        infos, err := t.File(".").ReadDir()
                    588:
                    589:        assertNil(err, "ReadDir")
                    590:        var names []string
                    591:        for _, info := range infos {
                    592:                names = append(names, info.Name())
                    593:        }
                    594:
                    595:        t.CheckDeepEquals(names, []string{".git", "CVS", "file", "subdir"})
                    596: }
                    597:
                    598: func (s *Suite) Test_Path_Open(c *check.C) {
                    599:        t := s.Init(c)
                    600:
                    601:        t.CreateFileLines("filename",
                    602:                "line 1",
                    603:                "line 2")
                    604:
                    605:        f, err := t.File("filename").Open()
                    606:
                    607:        assertNil(err, "Open")
                    608:        defer func() { assertNil(f.Close(), "Close") }()
                    609:        var sb strings.Builder
                    610:        n, err := io.Copy(&sb, f)
                    611:        assertNil(err, "Copy")
                    612:        t.CheckEquals(n, int64(14))
                    613:        t.CheckEquals(sb.String(), "line 1\nline 2\n")
                    614: }
                    615:
                    616: func (s *Suite) Test_Path_ReadString(c *check.C) {
                    617:        t := s.Init(c)
                    618:
                    619:        t.CreateFileLines("filename",
                    620:                "line 1",
                    621:                "line 2")
                    622:
                    623:        text, err := t.File("filename").ReadString()
                    624:
                    625:        assertNil(err, "ReadString")
                    626:        t.CheckEquals(text, "line 1\nline 2\n")
                    627: }
                    628:
                    629: func (s *Suite) Test_Path_WriteString(c *check.C) {
                    630:        t := s.Init(c)
                    631:
                    632:        err := t.File("filename").WriteString("line 1\nline 2\n")
                    633:
                    634:        assertNil(err, "WriteString")
                    635:        t.CheckFileLines("filename",
                    636:                "line 1",
                    637:                "line 2")
                    638: }

CVSweb <webmaster@jp.NetBSD.org>