diff options
Diffstat (limited to 'libgo/go/os/os_test.go')
-rw-r--r-- | libgo/go/os/os_test.go | 106 |
1 files changed, 72 insertions, 34 deletions
diff --git a/libgo/go/os/os_test.go b/libgo/go/os/os_test.go index 36bb496d979..8d3f677fd4e 100644 --- a/libgo/go/os/os_test.go +++ b/libgo/go/os/os_test.go @@ -13,6 +13,7 @@ import ( "path/filepath" "runtime" "strings" + "syscall" "testing" "time" ) @@ -23,7 +24,6 @@ var dot = []string{ "error.go", "file.go", "os_test.go", - "time.go", "types.go", } @@ -528,7 +528,6 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) { if err != nil { t.Fatalf("StartProcess: %v", err) } - defer p.Release() w.Close() var b bytes.Buffer @@ -539,7 +538,7 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) { t.Errorf("exec %q returned %q wanted %q", strings.Join(append([]string{cmd}, args...), " "), output, expect) } - p.Wait(0) + p.Wait() } func TestStartProcess(t *testing.T) { @@ -742,19 +741,6 @@ func TestChdirAndGetwd(t *testing.T) { fd.Close() } -func TestTime(t *testing.T) { - // Just want to check that Time() is getting something. - // A common failure mode on Darwin is to get 0, 0, - // because it returns the time in registers instead of - // filling in the structure passed to the system call. - // Too bad the compiler doesn't know that - // 365.24*86400 is an integer. - sec, nsec, err := Time() - if sec < (2009-1970)*36524*864 { - t.Errorf("Time() = %d, %d, %s; not plausible", sec, nsec, err) - } -} - func TestSeek(t *testing.T) { f := newFile("TestSeek", t) defer Remove(f.Name()) @@ -781,7 +767,7 @@ func TestSeek(t *testing.T) { for i, tt := range tests { off, err := f.Seek(tt.in, tt.whence) if off != tt.out || err != nil { - if e, ok := err.(*PathError); ok && e.Err == EINVAL && tt.out > 1<<32 { + if e, ok := err.(*PathError); ok && e.Err == syscall.EINVAL && tt.out > 1<<32 { // Reiserfs rejects the big seeks. // http://code.google.com/p/go/issues/detail?id=91 break @@ -801,17 +787,17 @@ var openErrorTests = []openErrorTest{ { sfdir + "/no-such-file", O_RDONLY, - ENOENT, + syscall.ENOENT, }, { sfdir, O_WRONLY, - EISDIR, + syscall.EISDIR, }, { sfdir + "/" + sfname + "/no-such-file", O_WRONLY, - ENOTDIR, + syscall.ENOTDIR, }, } @@ -859,12 +845,11 @@ func run(t *testing.T, cmd []string) string { if err != nil { t.Fatal(err) } - defer p.Release() w.Close() var b bytes.Buffer io.Copy(&b, r) - _, err = p.Wait(0) + _, err = p.Wait() if err != nil { t.Fatalf("run hostname Wait: %v", err) } @@ -997,32 +982,85 @@ func TestAppend(t *testing.T) { } func TestStatDirWithTrailingSlash(t *testing.T) { - // Create new dir, in _test so it will get - // cleaned up by make if not by us. - path := "_test/_TestStatDirWithSlash_" - err := MkdirAll(path, 0777) + // Create new temporary directory and arrange to clean it up. + path, err := ioutil.TempDir("", "/_TestStatDirWithSlash_") if err != nil { - t.Fatalf("MkdirAll %q: %s", path, err) + t.Fatalf("TempDir: %s", err) } defer RemoveAll(path) // Stat of path should succeed. _, err = Stat(path) if err != nil { - t.Fatal("stat failed:", err) + t.Fatalf("stat %s failed: %s", path, err) } // Stat of path+"/" should succeed too. - _, err = Stat(path + "/") + path += "/" + _, err = Stat(path) if err != nil { - t.Fatal("stat failed:", err) + t.Fatalf("stat %s failed: %s", path, err) } } -func TestNilWaitmsgString(t *testing.T) { - var w *Waitmsg - s := w.String() +func TestNilProcessStateString(t *testing.T) { + var ps *ProcessState + s := ps.String() if s != "<nil>" { - t.Errorf("(*Waitmsg)(nil).String() = %q, want %q", s, "<nil>") + t.Errorf("(*ProcessState)(nil).String() = %q, want %q", s, "<nil>") + } +} + +func TestSameFile(t *testing.T) { + fa, err := Create("a") + if err != nil { + t.Fatalf("Create(a): %v", err) + } + defer Remove(fa.Name()) + fa.Close() + fb, err := Create("b") + if err != nil { + t.Fatalf("Create(b): %v", err) + } + defer Remove(fb.Name()) + fb.Close() + + ia1, err := Stat("a") + if err != nil { + t.Fatalf("Stat(a): %v", err) + } + ia2, err := Stat("a") + if err != nil { + t.Fatalf("Stat(a): %v", err) + } + if !SameFile(ia1, ia2) { + t.Errorf("files should be same") + } + + ib, err := Stat("b") + if err != nil { + t.Fatalf("Stat(b): %v", err) + } + if SameFile(ia1, ib) { + t.Errorf("files should be different") + } +} + +func TestDevNullFile(t *testing.T) { + f, err := Open(DevNull) + if err != nil { + t.Fatalf("Open(%s): %v", DevNull, err) + } + defer f.Close() + fi, err := f.Stat() + if err != nil { + t.Fatalf("Stat(%s): %v", DevNull, err) + } + name := filepath.Base(DevNull) + if fi.Name() != name { + t.Fatalf("wrong file name have %v want %v", fi.Name(), name) + } + if fi.Size() != 0 { + t.Fatalf("wrong file size have %d want 0", fi.Size()) } } |