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

Is calling c.Check in TearDownTest supposed to be supported? #65

Open
rillig opened this issue Nov 20, 2015 · 2 comments
Open

Is calling c.Check in TearDownTest supposed to be supported? #65

rillig opened this issue Nov 20, 2015 · 2 comments

Comments

@rillig
Copy link

rillig commented Nov 20, 2015

I have a suite of unit tests that check the output of my program. To ensure that there is no unchecked output, I use the following code:

type Suite struct {
  output bytes.Buffer
}
func (s *Suite) Output() string {
  defer s.output.Reset()
  return s.output.String()
}
func (s *Suite) TearDownTest(c *check.C) {
  if out := s.Output(); out != "" {
    c.Logf("Unchecked output; check with: c.Check(s.Output(), check.Equals, %q)", out)
  }
}

Using c.LogF hides the output though, since successful tests don’t log anything. Using c.ErrorF instead of c.LogF reports that the fixture panicked, which is also not what I intended when I wrote that code. I had expected that I can use c.ErrorF in the TearDownTest exactly as I can use it in the actual unit test, having it print the nice “obtained—expected” message.

The current API doesn’t allow me to query whether the test panicked, I can only ask c.Failed().

Is the above code something that check should support?

@rillig
Copy link
Author

rillig commented Dec 11, 2016

Related to #41 and #22.

@aronatkins
Copy link

Using either check.Equals against an empty string or check.HasLen against zero is fine.

func (s *Suite) TearDownTest(c *check.C) {
	// Either is fine.
	c.Check(s.Output(), check.HasLen, 0)
	c.Check(s.Output(), check.Equals, "")
}

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