OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [io/] [ioutil/] [ioutil_test.go] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 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.
4
 
5
package ioutil_test
6
 
7
import (
8
        . "io/ioutil"
9
        "os"
10
        "testing"
11
)
12
 
13
func checkSize(t *testing.T, path string, size int64) {
14
        dir, err := os.Stat(path)
15
        if err != nil {
16
                t.Fatalf("Stat %q (looking for size %d): %s", path, size, err)
17
        }
18
        if dir.Size() != size {
19
                t.Errorf("Stat %q: size %d want %d", path, dir.Size(), size)
20
        }
21
}
22
 
23
func TestReadFile(t *testing.T) {
24
        filename := "rumpelstilzchen"
25
        contents, err := ReadFile(filename)
26
        if err == nil {
27
                t.Fatalf("ReadFile %s: error expected, none found", filename)
28
        }
29
 
30
        filename = "ioutil_test.go"
31
        contents, err = ReadFile(filename)
32
        if err != nil {
33
                t.Fatalf("ReadFile %s: %v", filename, err)
34
        }
35
 
36
        checkSize(t, filename, int64(len(contents)))
37
}
38
 
39
func TestWriteFile(t *testing.T) {
40
        f, err := TempFile("", "ioutil-test")
41
        if err != nil {
42
                t.Fatal(err)
43
        }
44
        filename := f.Name()
45
        data := "Programming today is a race between software engineers striving to " +
46
                "build bigger and better idiot-proof programs, and the Universe trying " +
47
                "to produce bigger and better idiots. So far, the Universe is winning."
48
 
49
        if err := WriteFile(filename, []byte(data), 0644); err != nil {
50
                t.Fatalf("WriteFile %s: %v", filename, err)
51
        }
52
 
53
        contents, err := ReadFile(filename)
54
        if err != nil {
55
                t.Fatalf("ReadFile %s: %v", filename, err)
56
        }
57
 
58
        if string(contents) != data {
59
                t.Fatalf("contents = %q\nexpected = %q", string(contents), data)
60
        }
61
 
62
        // cleanup
63
        f.Close()
64
        os.Remove(filename) // ignore error
65
}
66
 
67
func TestReadDir(t *testing.T) {
68
        dirname := "rumpelstilzchen"
69
        _, err := ReadDir(dirname)
70
        if err == nil {
71
                t.Fatalf("ReadDir %s: error expected, none found", dirname)
72
        }
73
 
74
        /* Does not work in gccgo testing environment.
75
        dirname = ".."
76
        list, err := ReadDir(dirname)
77
        if err != nil {
78
                t.Fatalf("ReadDir %s: %v", dirname, err)
79
        }
80
 
81
        foundFile := false
82
        foundSubDir := false
83
        for _, dir := range list {
84
                switch {
85
                case !dir.IsDir() && dir.Name() == "io_test.go":
86
                        foundFile = true
87
                case dir.IsDir() && dir.Name() == "ioutil":
88
                        foundSubDir = true
89
                }
90
        }
91
        if !foundFile {
92
                t.Fatalf("ReadDir %s: io_test.go file not found", dirname)
93
        }
94
        if !foundSubDir {
95
                t.Fatalf("ReadDir %s: ioutil directory not found", dirname)
96
        }
97
        */
98
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.