Skip to content

Instantly share code, notes, and snippets.

@willf
Created May 11, 2011 01:01
Show Gist options
  • Save willf/965713 to your computer and use it in GitHub Desktop.
Save willf/965713 to your computer and use it in GitHub Desktop.
Writing a GO test to test for the presence of a failure
func TestOutOfBoundsBad(t *testing.T) {
v := MakeBitSet(64)
defer func() {
if r := recover(); r == nil {
t.Error("Out of index error within the next set of bits should have caused a panic")
}
}()
v.SetBit(1000)
}
func TestOutOfBoundsOK(t *testing.T) {
v := MakeBitSet(65)
defer func() {
if r := recover(); r != nil {
t.Error("Out of index error within the next set of bits should not caused a panic")
}
}()
v.SetBit(66)
}
@willf
Copy link
Author

willf commented May 11, 2011

This might supposed to work, but doesn't seem to:

func TestOutOfBounds(t *testing.T) {
v := MakeBitSet(65)
defer recover()
v.SetBit(100)
t.Error("Out of index error should have been caused a panic")
}

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