Commit 955c0fd2 authored by Dave Cheney's avatar Dave Cheney

os: add test to ensure Rename returns *LinkError

Updates #10061

CL 12353 updated the documentation for os.Rename to stipulate the function will
return errors of type *os.LinkError. This CL adds a test to ensure that the
implementations continue to obey this contract.

Change-Id: I41beb8c9d8356c737de251fdc6f652caab3ee636
Reviewed-on: https://go-review.googlesource.com/12329Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent ed9a4c91
...@@ -768,6 +768,35 @@ func TestRenameOverwriteDest(t *testing.T) { ...@@ -768,6 +768,35 @@ func TestRenameOverwriteDest(t *testing.T) {
} }
} }
func TestRenameFailed(t *testing.T) {
defer chtmpdir(t)()
from, to := "renamefrom", "renameto"
// Ensure we are not testing the overwrite case here.
Remove(from)
Remove(to)
err := Rename(from, to)
switch err := err.(type) {
case *LinkError:
if err.Op != "rename" {
t.Errorf("rename %q, %q: err.Op: want %q, got %q", from, to, "rename", err.Op)
}
if err.Old != from {
t.Errorf("rename %q, %q: err.Old: want %q, got %q", from, to, from, err.Old)
}
if err.New != to {
t.Errorf("rename %q, %q: err.New: want %q, got %q", from, to, to, err.New)
}
case nil:
t.Errorf("rename %q, %q: expected error, got nil", from, to)
// cleanup whatever was placed in "renameto"
Remove(to)
default:
t.Errorf("rename %q, %q: expected %T, got %T %v", from, to, new(LinkError), err, err)
}
}
func exec(t *testing.T, dir, cmd string, args []string, expect string) { func exec(t *testing.T, dir, cmd string, args []string, expect string) {
r, w, err := Pipe() r, w, err := Pipe()
if err != nil { if err != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment