1package reporting 2 3import "io" 4 5type Reporter interface { 6 BeginStory(story *StoryReport) 7 Enter(scope *ScopeReport) 8 Report(r *AssertionResult) 9 Exit() 10 EndStory() 11 io.Writer 12} 13 14type reporters struct{ collection []Reporter } 15 16func (self *reporters) BeginStory(s *StoryReport) { self.foreach(func(r Reporter) { r.BeginStory(s) }) } 17func (self *reporters) Enter(s *ScopeReport) { self.foreach(func(r Reporter) { r.Enter(s) }) } 18func (self *reporters) Report(a *AssertionResult) { self.foreach(func(r Reporter) { r.Report(a) }) } 19func (self *reporters) Exit() { self.foreach(func(r Reporter) { r.Exit() }) } 20func (self *reporters) EndStory() { self.foreach(func(r Reporter) { r.EndStory() }) } 21 22func (self *reporters) Write(contents []byte) (written int, err error) { 23 self.foreach(func(r Reporter) { 24 written, err = r.Write(contents) 25 }) 26 return written, err 27} 28 29func (self *reporters) foreach(action func(Reporter)) { 30 for _, r := range self.collection { 31 action(r) 32 } 33} 34 35func NewReporters(collection ...Reporter) *reporters { 36 self := new(reporters) 37 self.collection = collection 38 return self 39} 40