OSDN Git Service

libgo: Update to weekly.2012-02-07.
[pf3gnuchains/gcc-fork.git] / libgo / go / fmt / fmt_test.go
index 504194c..1b02f52 100644 (file)
@@ -443,6 +443,14 @@ var fmttests = []struct {
        {"%s", nil, "%!s(<nil>)"},
        {"%T", nil, "<nil>"},
        {"%-1", 100, "%!(NOVERB)%!(EXTRA int=100)"},
+
+       // The "<nil>" show up because maps are printed by
+       // first obtaining a list of keys and then looking up
+       // each key.  Since NaNs can be map keys but cannot
+       // be fetched directly, the lookup fails and returns a
+       // zero reflect.Value, which formats as <nil>.
+       // This test is just to check that it shows the two NaNs at all.
+       {"%v", map[float64]int{math.NaN(): 1, math.NaN(): 2}, "map[NaN:<nil> NaN:<nil>]"},
 }
 
 func TestSprintf(t *testing.T) {
@@ -532,13 +540,14 @@ var _ bytes.Buffer
 func TestCountMallocs(t *testing.T) {
        for _, mt := range mallocTest {
                const N = 100
-               runtime.UpdateMemStats()
-               mallocs := 0 - runtime.MemStats.Mallocs
+               memstats := new(runtime.MemStats)
+               runtime.ReadMemStats(memstats)
+               mallocs := 0 - memstats.Mallocs
                for i := 0; i < N; i++ {
                        mt.fn()
                }
-               runtime.UpdateMemStats()
-               mallocs += runtime.MemStats.Mallocs
+               runtime.ReadMemStats(memstats)
+               mallocs += memstats.Mallocs
                if mallocs/N > uint64(mt.count) {
                        t.Errorf("%s: expected %d mallocs, got %d", mt.desc, mt.count, mallocs/N)
                }