summaryrefslogtreecommitdiff
path: root/src/pkg/os/os_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-06-25 20:24:55 -0700
committerRuss Cox <rsc@golang.org>2009-06-25 20:24:55 -0700
commitb26cd1bfcd7107d8208595614ba45f54d5efacf6 (patch)
tree1596fd2f89c1d896cdf5772aebc910f4e0ff5bda /src/pkg/os/os_test.go
parent37fd11a43607dc5f7ff5c38311b060ada2a0e7a5 (diff)
downloadgolang-b26cd1bfcd7107d8208595614ba45f54d5efacf6.tar.gz
Change os.Error convention:
echo back context of call in error if likely to be useful. For example, if os.Open("/etc/passwd", os.O_RDONLY) fails with syscall.EPERM, it returns as the os.Error &PathError{ Op: "open", Path: "/etc/passwd" Error: os.EPERM } which formats as open /etc/passwd: permission denied Not converted: datafmt go/... google/... regexp tabwriter template R=r DELTA=1153 (561 added, 156 deleted, 436 changed) OCL=30738 CL=30781
Diffstat (limited to 'src/pkg/os/os_test.go')
-rw-r--r--src/pkg/os/os_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/pkg/os/os_test.go b/src/pkg/os/os_test.go
index 77b69447d..fb555eb86 100644
--- a/src/pkg/os/os_test.go
+++ b/src/pkg/os/os_test.go
@@ -549,3 +549,41 @@ func TestSeek(t *testing.T) {
}
f.Close();
}
+
+type openErrorTest struct {
+ path string;
+ mode int;
+ error string;
+}
+
+var openErrorTests = []openErrorTest {
+ openErrorTest {
+ "/etc/no-such-file",
+ O_RDONLY,
+ "open /etc/no-such-file: no such file or directory",
+ },
+ openErrorTest {
+ "/etc",
+ O_WRONLY,
+ "open /etc: is a directory",
+ },
+ openErrorTest {
+ "/etc/passwd/group",
+ O_WRONLY,
+ "open /etc/passwd/group: not a directory",
+ },
+}
+
+func TestOpenError(t *testing.T) {
+ for i, tt := range openErrorTests {
+ f, err := Open(tt.path, tt.mode, 0);
+ if err == nil {
+ t.Errorf("Open(%q, %d) succeeded", tt.path, tt.mode);
+ f.Close();
+ continue;
+ }
+ if s := err.String(); s != tt.error {
+ t.Errorf("Open(%q, %d) = _, %q; want %q", tt.path, tt.mode, s, tt.error);
+ }
+ }
+}