var-tracking.c (vt_add_function_parameter): Adjust for VEC changes.
[official-gcc.git] / libgo / go / os / error_test.go
blob42f846fa3c59b8fcf47071272be18047c32ab775
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package os_test
7 import (
8 "fmt"
9 "io/ioutil"
10 "os"
11 "path/filepath"
12 "testing"
15 func TestErrIsExist(t *testing.T) {
16 f, err := ioutil.TempFile("", "_Go_ErrIsExist")
17 if err != nil {
18 t.Fatalf("open ErrIsExist tempfile: %s", err)
19 return
21 defer os.Remove(f.Name())
22 defer f.Close()
23 f2, err := os.OpenFile(f.Name(), os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
24 if err == nil {
25 f2.Close()
26 t.Fatal("Open should have failed")
27 return
29 if s := checkErrorPredicate("os.IsExist", os.IsExist, err); s != "" {
30 t.Fatal(s)
31 return
35 func testErrNotExist(name string) string {
36 f, err := os.Open(name)
37 if err == nil {
38 f.Close()
39 return "Open should have failed"
41 if s := checkErrorPredicate("os.IsNotExist", os.IsNotExist, err); s != "" {
42 return s
45 err = os.Chdir(name)
46 if err == nil {
47 return "Chdir should have failed"
49 if s := checkErrorPredicate("os.IsNotExist", os.IsNotExist, err); s != "" {
50 return s
52 return ""
55 func TestErrIsNotExist(t *testing.T) {
56 tmpDir, err := ioutil.TempDir("", "_Go_ErrIsNotExist")
57 if err != nil {
58 t.Fatalf("create ErrIsNotExist tempdir: %s", err)
59 return
61 defer os.RemoveAll(tmpDir)
63 name := filepath.Join(tmpDir, "NotExists")
64 if s := testErrNotExist(name); s != "" {
65 t.Fatal(s)
66 return
69 name = filepath.Join(name, "NotExists2")
70 if s := testErrNotExist(name); s != "" {
71 t.Fatal(s)
72 return
76 func checkErrorPredicate(predName string, pred func(error) bool, err error) string {
77 if !pred(err) {
78 return fmt.Sprintf("%s does not work as expected for %#v", predName, err)
80 return ""