Created
May 11, 2011 01:01
-
-
Save willf/965713 to your computer and use it in GitHub Desktop.
Writing a GO test to test for the presence of a failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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")
}