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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2010 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
        "path/filepath"
11
        "regexp"
12
        "testing"
13
)
14
 
15
func TestTempFile(t *testing.T) {
16
        f, err := TempFile("/_not_exists_", "foo")
17
        if f != nil || err == nil {
18
                t.Errorf("TempFile(`/_not_exists_`, `foo`) = %v, %v", f, err)
19
        }
20
 
21
        dir := os.TempDir()
22
        f, err = TempFile(dir, "ioutil_test")
23
        if f == nil || err != nil {
24
                t.Errorf("TempFile(dir, `ioutil_test`) = %v, %v", f, err)
25
        }
26
        if f != nil {
27
                f.Close()
28
                os.Remove(f.Name())
29
                re := regexp.MustCompile("^" + regexp.QuoteMeta(filepath.Join(dir, "ioutil_test")) + "[0-9]+$")
30
                if !re.MatchString(f.Name()) {
31
                        t.Errorf("TempFile(`"+dir+"`, `ioutil_test`) created bad name %s", f.Name())
32
                }
33
        }
34
}
35
 
36
func TestTempDir(t *testing.T) {
37
        name, err := TempDir("/_not_exists_", "foo")
38
        if name != "" || err == nil {
39
                t.Errorf("TempDir(`/_not_exists_`, `foo`) = %v, %v", name, err)
40
        }
41
 
42
        dir := os.TempDir()
43
        name, err = TempDir(dir, "ioutil_test")
44
        if name == "" || err != nil {
45
                t.Errorf("TempDir(dir, `ioutil_test`) = %v, %v", name, err)
46
        }
47
        if name != "" {
48
                os.Remove(name)
49
                re := regexp.MustCompile("^" + regexp.QuoteMeta(filepath.Join(dir, "ioutil_test")) + "[0-9]+$")
50
                if !re.MatchString(name) {
51
                        t.Errorf("TempDir(`"+dir+"`, `ioutil_test`) created bad name %s", name)
52
                }
53
        }
54
}

powered by: WebSVN 2.1.0

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