encoding/xml: make sure Encoder.Encode reports Write errors.

Fixes #4112.

R=remyoudompheng, daniel.morsing, dave, rsc
CC=golang-dev
https://golang.org/cl/7085053
This commit is contained in:
Olivier Saingre 2013-02-20 14:41:23 -08:00 committed by Brad Fitzpatrick
parent 8eb80914ca
commit afde71cfbd
4 changed files with 61 additions and 14 deletions

View file

@ -689,3 +689,17 @@ func TestDirectivesWithComments(t *testing.T) {
}
}
}
// Writer whose Write method always returns an error.
type errWriter struct{}
func (errWriter) Write(p []byte) (n int, err error) { return 0, fmt.Errorf("unwritable") }
func TestEscapeTextIOErrors(t *testing.T) {
expectErr := "unwritable"
err := EscapeText(errWriter{}, []byte{'A'})
if err == nil || err.Error() != expectErr {
t.Errorf("EscapeTest = [error] %v, want %v", err, expectErr)
}
}