Skip to content

Commit

Permalink
you shall not pass wrong arguments to provideLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
mg6maciej committed Dec 21, 2014
1 parent 61358e2 commit a08cd04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion location_provider_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ func testCallerInfo(skip int) (testName string, path string, line int) {
}

func callerInfo(skip int) (methodName string, path string, line int) {
pc, path, line, _ := runtime.Caller(skip + 1)
pc, path, line, ok := runtime.Caller(skip + 1)
if !ok {
panic("you shall not pass!")
}
methodName = methodNameFromPC(pc)
return
}
Expand Down
10 changes: 10 additions & 0 deletions location_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ func TestLocationProviderCalledFromAnotherFunction(t *testing.T) {
&location{"TestLocationProviderCalledFromAnotherFunction", "location_provider_test.go", 6},
)
}

func TestLocationProviderPanicsWhenUsedIncorrectly(t *testing.T) {
assert := Setup(t)
defer func() {
r := recover()
assert.That(r).IsEqualTo("you shall not pass!")
}()
provideLocation(1)
t.Fail()
}

0 comments on commit a08cd04

Please sign in to comment.