Commit f99b4128 authored by Russ Cox's avatar Russ Cox

io/ioutil, old/template: do not assume _test exists for scratch space

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5496052
parent 197eb8f7
......@@ -37,7 +37,11 @@ func TestReadFile(t *testing.T) {
}
func TestWriteFile(t *testing.T) {
filename := "_test/rumpelstilzchen"
f, err := TempFile("", "ioutil-test")
if err != nil {
t.Fatal(err)
}
filename := f.Name()
data := "Programming today is a race between software engineers striving to " +
"build bigger and better idiot-proof programs, and the Universe trying " +
"to produce bigger and better idiots. So far, the Universe is winning."
......
......@@ -10,6 +10,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"testing"
)
......@@ -463,23 +464,28 @@ func TestAll(t *testing.T) {
// Parse
testAll(t, func(test *Test) (*Template, error) { return Parse(test.in, formatters) })
// ParseFile
f, err := ioutil.TempFile("", "template-test")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
testAll(t, func(test *Test) (*Template, error) {
err := ioutil.WriteFile("_test/test.tmpl", []byte(test.in), 0600)
err := ioutil.WriteFile(f.Name(), []byte(test.in), 0600)
if err != nil {
t.Error("unexpected write error:", err)
return nil, err
}
return ParseFile("_test/test.tmpl", formatters)
return ParseFile(f.Name(), formatters)
})
// tmpl.ParseFile
testAll(t, func(test *Test) (*Template, error) {
err := ioutil.WriteFile("_test/test.tmpl", []byte(test.in), 0600)
err := ioutil.WriteFile(f.Name(), []byte(test.in), 0600)
if err != nil {
t.Error("unexpected write error:", err)
return nil, err
}
tmpl := New(formatters)
return tmpl, tmpl.ParseFile("_test/test.tmpl")
return tmpl, tmpl.ParseFile(f.Name())
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment