Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / io / ioutil / tempfile_test.go
blobd949a86cf0961810816aa2ced2f6ee6588af692e
1 // 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.
5 package ioutil_test
7 import (
8 . "io/ioutil"
9 "os"
10 "regexp"
11 "testing"
14 func TestTempFile(t *testing.T) {
15 f, err := TempFile("/_not_exists_", "foo")
16 if f != nil || err == nil {
17 t.Errorf("TempFile(`/_not_exists_`, `foo`) = %v, %v", f, err)
20 dir := os.TempDir()
21 f, err = TempFile(dir, "ioutil_test")
22 if f == nil || err != nil {
23 t.Errorf("TempFile(dir, `ioutil_test`) = %v, %v", f, err)
25 if f != nil {
26 re := regexp.MustCompile("^" + regexp.QuoteMeta(dir) + "/ioutil_test[0-9]+$")
27 if !re.MatchString(f.Name()) {
28 t.Errorf("TempFile(`"+dir+"`, `ioutil_test`) created bad name %s", f.Name())
30 os.Remove(f.Name())
32 f.Close()