Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1788)

Side by Side Diff: src/cmd/go/test.go

Issue 7229071: code review 7229071: cmd/go: run examples in source order, not name order (Closed)
Patch Set: diff -r 8faf9010cd77 https://code.google.com/p/go/ Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/cmd/go/test.bash ('k') | src/cmd/go/testdata/example1_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "go/ast" 10 "go/ast"
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 name := n.Name.String() 802 name := n.Name.String()
803 switch { 803 switch {
804 case isTest(name, "Test"): 804 case isTest(name, "Test"):
805 t.Tests = append(t.Tests, testFunc{pkg, name, ""}) 805 t.Tests = append(t.Tests, testFunc{pkg, name, ""})
806 *seen = true 806 *seen = true
807 case isTest(name, "Benchmark"): 807 case isTest(name, "Benchmark"):
808 t.Benchmarks = append(t.Benchmarks, testFunc{pkg, name, ""}) 808 t.Benchmarks = append(t.Benchmarks, testFunc{pkg, name, ""})
809 *seen = true 809 *seen = true
810 } 810 }
811 } 811 }
812 » for _, e := range doc.Examples(f) { 812 » ex := doc.Examples(f)
813 » sort.Sort(byOrder(ex))
814 » for _, e := range ex {
813 if e.Output == "" && !e.EmptyOutput { 815 if e.Output == "" && !e.EmptyOutput {
814 // Don't run examples with no output. 816 // Don't run examples with no output.
815 continue 817 continue
816 } 818 }
817 t.Examples = append(t.Examples, testFunc{pkg, "Example" + e.Name , e.Output}) 819 t.Examples = append(t.Examples, testFunc{pkg, "Example" + e.Name , e.Output})
818 *seen = true 820 *seen = true
819 } 821 }
820 return nil 822 return nil
821 } 823 }
822 824
825 type byOrder []*doc.Example
826
827 func (x byOrder) Len() int { return len(x) }
828 func (x byOrder) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
829 func (x byOrder) Less(i, j int) bool { return x[i].Order < x[j].Order }
830
823 var testmainTmpl = template.Must(template.New("main").Parse(` 831 var testmainTmpl = template.Must(template.New("main").Parse(`
824 package main 832 package main
825 833
826 import ( 834 import (
827 "regexp" 835 "regexp"
828 "testing" 836 "testing"
829 837
830 {{if .NeedTest}} 838 {{if .NeedTest}}
831 _test {{.Package.ImportPath | printf "%q"}} 839 _test {{.Package.ImportPath | printf "%q"}}
832 {{end}} 840 {{end}}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 873 }
866 } 874 }
867 return matchRe.MatchString(str), nil 875 return matchRe.MatchString(str), nil
868 } 876 }
869 877
870 func main() { 878 func main() {
871 testing.Main(matchString, tests, benchmarks, examples) 879 testing.Main(matchString, tests, benchmarks, examples)
872 } 880 }
873 881
874 `)) 882 `))
OLDNEW
« no previous file with comments | « src/cmd/go/test.bash ('k') | src/cmd/go/testdata/example1_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b