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

tournament: Improve error-handling behavior #308

Closed
petertseng opened this issue Apr 9, 2016 · 0 comments
Closed

tournament: Improve error-handling behavior #308

petertseng opened this issue Apr 9, 2016 · 0 comments

Comments

@petertseng
Copy link
Member

As part of #275, we'd like to more closely follow idiomatic Go behavior in the face of errors.

If the tournament exercise does not have error handling, then this ticket can be closed immediately.

If it does, then follow the below steps:

Ensure err return value is of type error

It's idiomatic for the error return value to be of type error.

Most tests simply check whether err == nil or not. If we don't verify the type of err, it could be any type that has nils.

To lean on the type system, add the following line after assigning err:

var _ error = err

See the hamming tests for an example.

Ignore the normal return value when an error expected

The contract in Go is "if there's an error, assume nothing about the normal return value". Thus, we should only check the non-error return value when there is no error.

In some exercises we found that we were checking the normal return value, even when there was an error.

See the binary tests for an example of the behavior that we want.

Increment the test version

These changes break backwards compatibility. Bump the test version to let reviewers know that the exercise has changed.

This requires changing two constants:

  • targetTestVersion in the test file (*_test.go)
  • testVersion in the reference solution (example.go)

If the exercise does not have a test version, then add one, setting the value to 1.

See the version test in leap for an example.

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

No branches or pull requests

1 participant