1// TODO: in order for this reporter to be completely honest 2// we need to retrofit to be more like the json reporter such that: 3// 1. it maintains ScopeResult collections, which count assertions 4// 2. it reports only after EndStory(), so that all tick marks 5// are placed near the appropriate title. 6// 3. Under unit test 7 8package reporting 9 10import ( 11 "fmt" 12 "strings" 13) 14 15type story struct { 16 out *Printer 17 titlesById map[string]string 18 currentKey []string 19} 20 21func (self *story) BeginStory(story *StoryReport) {} 22 23func (self *story) Enter(scope *ScopeReport) { 24 self.out.Indent() 25 26 self.currentKey = append(self.currentKey, scope.Title) 27 ID := strings.Join(self.currentKey, "|") 28 29 if _, found := self.titlesById[ID]; !found { 30 self.out.Println("") 31 self.out.Print(scope.Title) 32 self.out.Insert(" ") 33 self.titlesById[ID] = scope.Title 34 } 35} 36 37func (self *story) Report(report *AssertionResult) { 38 if report.Error != nil { 39 fmt.Print(redColor) 40 self.out.Insert(error_) 41 } else if report.Failure != "" { 42 fmt.Print(yellowColor) 43 self.out.Insert(failure) 44 } else if report.Skipped { 45 fmt.Print(yellowColor) 46 self.out.Insert(skip) 47 } else { 48 fmt.Print(greenColor) 49 self.out.Insert(success) 50 } 51 fmt.Print(resetColor) 52} 53 54func (self *story) Exit() { 55 self.out.Dedent() 56 self.currentKey = self.currentKey[:len(self.currentKey)-1] 57} 58 59func (self *story) EndStory() { 60 self.titlesById = make(map[string]string) 61 self.out.Println("\n") 62} 63 64func (self *story) Write(content []byte) (written int, err error) { 65 return len(content), nil // no-op 66} 67 68func NewStoryReporter(out *Printer) *story { 69 self := new(story) 70 self.out = out 71 self.titlesById = make(map[string]string) 72 return self 73} 74