Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying expected and actual values #58

Open
carlca opened this issue Feb 28, 2017 · 3 comments
Open

Displaying expected and actual values #58

carlca opened this issue Feb 28, 2017 · 3 comments

Comments

@carlca
Copy link

carlca commented Feb 28, 2017

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!

@carlca
Copy link
Author

carlca commented Feb 28, 2017

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.

@marcosnils
Copy link
Member

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.

@carlca
Copy link
Author

carlca commented Mar 3, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants