summaryrefslogtreecommitdiffstats
path: root/libgo/go/errors
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-03-02 20:01:37 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-03-02 20:01:37 +0000
commitef10b1dda693467283a3645a5da610e810149764 (patch)
tree3eeb8918d39d675108073c8b76d6dd10586a608c /libgo/go/errors
parentea6ad4ae9afbd45b5c19aadab39ddbf1db0d50f8 (diff)
downloadppe42-gcc-ef10b1dda693467283a3645a5da610e810149764.tar.gz
ppe42-gcc-ef10b1dda693467283a3645a5da610e810149764.zip
libgo: Update to weekly.2012-02-22 release.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184819 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/errors')
-rw-r--r--libgo/go/errors/errors_test.go30
1 files changed, 25 insertions, 5 deletions
diff --git a/libgo/go/errors/errors_test.go b/libgo/go/errors/errors_test.go
index c537eeb6251..63c05d7185b 100644
--- a/libgo/go/errors/errors_test.go
+++ b/libgo/go/errors/errors_test.go
@@ -5,29 +5,49 @@
package errors_test
import (
- . "errors"
+ "errors"
+ "fmt"
"testing"
)
func TestNewEqual(t *testing.T) {
// Different allocations should not be equal.
- if New("abc") == New("abc") {
+ if errors.New("abc") == errors.New("abc") {
t.Errorf(`New("abc") == New("abc")`)
}
- if New("abc") == New("xyz") {
+ if errors.New("abc") == errors.New("xyz") {
t.Errorf(`New("abc") == New("xyz")`)
}
// Same allocation should be equal to itself (not crash).
- err := New("jkl")
+ err := errors.New("jkl")
if err != err {
t.Errorf(`err != err`)
}
}
func TestErrorMethod(t *testing.T) {
- err := New("abc")
+ err := errors.New("abc")
if err.Error() != "abc" {
t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc")
}
}
+
+func ExampleNew() {
+ err := errors.New("emit macho dwarf: elf header corrupted")
+ if err != nil {
+ fmt.Print(err)
+ }
+ // Output: emit macho dwarf: elf header corrupted
+}
+
+// The fmt package's Errorf function lets us use the package's formatting
+// features to create descriptive error messages.
+func ExampleNew_errorf() {
+ const name, id = "bimmler", 17
+ err := fmt.Errorf("user %q (id %d) not found", name, id)
+ if err != nil {
+ fmt.Print(err)
+ }
+ // Output: user "bimmler" (id 17) not found
+}
OpenPOWER on IntegriCloud