Skip to content

Commit

Permalink
Merge pull request #53 from aelsabbahy/issues/52
Browse files Browse the repository at this point in the history
Add `title` and `meta` to rspecish and documentation output
  • Loading branch information
aelsabbahy committed Mar 15, 2016
2 parents d3487d4 + 406f018 commit 1695b52
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
30 changes: 23 additions & 7 deletions outputs/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,44 @@ type Documentation struct{}

func (r Documentation) Output(results <-chan []resource.TestResult, startTime time.Time) (exitCode int) {
testCount := 0
var failed []resource.TestResult
var failed [][]resource.TestResult
for resultGroup := range results {
failedGroup := []resource.TestResult{}
first := resultGroup[0]
header := header(first)
if header != "" {
fmt.Print(header)
}
for _, testResult := range resultGroup {
if testResult.Successful {
fmt.Println(humanizeResult(testResult))
testCount++
} else {
fmt.Println(humanizeResult(testResult))
failed = append(failed, testResult)
failedGroup = append(failedGroup, testResult)
testCount++
}
}
fmt.Println("")
if len(failedGroup) > 0 {
failed = append(failed, failedGroup)
}
}

fmt.Print("\n")
fmt.Print("\n\n")
if len(failed) > 0 {
color.Red("Failures:")
for _, testResult := range failed {
fmt.Println(humanizeResult(testResult))
fmt.Println("Failures:\n")
for _, failedGroup := range failed {
first := failedGroup[0]
header := header(first)
if header != "" {
fmt.Print(header)
}
for _, testResult := range failedGroup {
fmt.Println(humanizeResult(testResult))
}
fmt.Print("\n")
}
fmt.Print("\n")
}

fmt.Printf("Total Duration: %.3fs\n", time.Since(startTime).Seconds())
Expand Down
24 changes: 22 additions & 2 deletions outputs/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ var red = color.New(color.FgRed).SprintfFunc()

func humanizeResult(r resource.TestResult) string {
if r.Err != nil {
return red("%s: %s:\nError: %s", r.ResourceId, r.Property, r.Err)
return red("%s: %s: Error: %s", r.ResourceId, r.Property, r.Err)
}

if r.Successful {
return green("%s: %s: %s: matches expectation: %s", r.ResourceType, r.ResourceId, r.Property, r.Expected)
} else {
if r.Human != "" {
return red("%s: %s: %s:\n%s\n", r.ResourceType, r.ResourceId, r.Property, r.Human)
return red("%s: %s: %s:\n%s", r.ResourceType, r.ResourceId, r.Property, r.Human)
}
return humanizeResult2(r)
}
Expand Down Expand Up @@ -119,3 +119,23 @@ func subtractSlice(x, y []string) []string {

return ret
}

func header(t resource.TestResult) string {
var out string
if t.Title != "" {
out += fmt.Sprintf("Title: %s\n", t.Title)
}
if t.Meta != nil {
var keys []string
for k := range t.Meta {
keys = append(keys, k)
}
sort.Strings(keys)

out += "Meta:\n"
for _, k := range keys {
out += fmt.Sprintf(" %v: %v\n", k, t.Meta[k])
}
}
return out
}
23 changes: 17 additions & 6 deletions outputs/rspecish.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,37 @@ type Rspecish struct{}

func (r Rspecish) Output(results <-chan []resource.TestResult, startTime time.Time) (exitCode int) {
testCount := 0
var failed []resource.TestResult
var failed [][]resource.TestResult
for resultGroup := range results {
failedGroup := []resource.TestResult{}
for _, testResult := range resultGroup {
if testResult.Successful {
fmt.Printf(green("."))
} else {
fmt.Printf(red("F"))
failed = append(failed, testResult)
failedGroup = append(failedGroup, testResult)
}
testCount++
}
if len(failedGroup) > 0 {
failed = append(failed, failedGroup)
}
}

fmt.Print("\n\n")
if len(failed) > 0 {
color.Red("Failures:")
for _, testResult := range failed {
fmt.Println(humanizeResult(testResult))
fmt.Println("Failures:\n")
for _, failedGroup := range failed {
first := failedGroup[0]
header := header(first)
if header != "" {
fmt.Print(header)
}
for _, testResult := range failedGroup {
fmt.Println(humanizeResult(testResult))
}
fmt.Print("\n")
}
fmt.Print("\n")
}

fmt.Printf("Total Duration: %.3fs\n", time.Since(startTime).Seconds())
Expand Down

0 comments on commit 1695b52

Please sign in to comment.