franela/goblin

Displaying expected and actual values

carlca opened this issue · 3 comments

Hello. It would be nice if there was a neat, compact way of being able to print the expected and actual values in a font color in keeping with the rest of the printed output. Maybe it can already be done but it's beyond my skill level if it is!

Okay. I've made a close approximation of what I want which will do for now.

func TestStatsVector(t *testing.T) {
	var v StatsVector
	v = populateVector(v)
	var expected string
	var actual string

	g := goblin.Goblin(t)
	fmt.Printf("%T", g)

	actual = fmt.Sprintf("%10.4f", v.Sum())
	expected = "26770.4503"
	g.Describe("Sum", func() {
		g.It("Should provide the sum of the constituent elements", func() {
			ReportAndAssert(g, expected, actual)
		})
	})
}

func ReportAndAssert(g *goblin.G, expected, actual string) {
	if expected == actual {
		PrintCheck()
	} else {
		PrintFail()
	}
	fmt.Print(MakeGray("Expected: " + expected))
	fmt.Println(MakeGray("   Actual: " + actual))
	g.Assert(actual).Equal(expected)
}

func PrintCheck() {
	fmt.Print("    \033[32m\u2713\033[0m ")
}

func PrintFail() {
	fmt.Print("    \033[31m" + "x" + "\033[0m ")
}

func MakeGray(s string) string {
	return "\033[90m" + s + "\033[0m"
}

This code will not run as it is but it should demonstrate what I have done. What would be nice if the functionality of printing the actual and expected was carried out by the

g.Assert(actual).Equal(expected)

line.

Hey @carlca I'd really love this feature, but I don't have time ATM to implement it. If you want to level up and take a shot with a PR I'll try to help in whatever I can to implement it.

Hi Marcos, I assume by PR you mean Pull Request (I'm new to the mysteries of Git!) and make changes that could be released as part of Goblin. Yeah, I'd be up for that. I'll need a bit of guidance on exactly what git commands to use and when to use them. Thanks in advance, Carl.