// Run the supplied function, catching panics (including AssertThat errors) and
// reporting them to the currently-running test as appropriate. Return true iff
// the function panicked.
Run the supplied function, catching panics (including AssertThat errors) and
reporting them to the currently-running test as appropriate. Return true iff
the function panicked.
// Run the supplied function catching panics ( including AssertThat errors ) and // reporting them to the currently - running test as appropriate . Return true iff // the function panicked .
func runWithProtection(f func()) (panicked bool) {
	defer func() {
		r := recover()
		if r == nil {
			return
		}
		panicked = true
		currentlyRunningTest.mutex.Lock()
		defer currentlyRunningTest.mutex.Unlock()
		if !isAssertThatError(r) {
			     <this deferred function>
			     panic(r)
			     <function that called panic>
			_, fileName, lineNumber, ok := runtime.Caller(2)
			var panicRecord failureRecord
			if ok {
				panicRecord.FileName = path.Base(fileName)
				panicRecord.LineNumber = lineNumber
			}
			panicRecord.GeneratedError = fmt.Sprintf(
				"panic: %v\n\n%s", r, formatPanicStack())
			currentlyRunningTest.failureRecords = append(
				currentlyRunningTest.failureRecords,
				&panicRecord)
		}
	}()
	f()
	return
}
func runWithProtection ( f func ( ) ) ( panicked bool ) { defer func ( ) { r := recover ( ) if r == nil { return } panicked = true currentlyRunningTest . mutex . Lock ( ) defer currentlyRunningTest . mutex . Unlock ( ) if ! isAssertThatError ( r ) { _ , fileName , lineNumber , ok := runtime . Caller ( 2 ) var panicRecord failureRecord if ok { panicRecord . FileName = path . Base ( fileName ) panicRecord . LineNumber = lineNumber } panicRecord . GeneratedError = fmt . Sprintf ( " \n \n " , r , formatPanicStack ( ) ) currentlyRunningTest . failureRecords = append ( currentlyRunningTest . failureRecords , & panicRecord ) } } ( ) f ( ) return }
Run the supplied function, catching panics (including AssertThat errors) and
reporting them to the currently-running test as appropriate.
Run the supplied function catching panics ( including AssertThat errors ) and reporting them to the currently - running test as appropriate .
// If the test didn't panic, we're done. // We modify the currently running test below. // If the function panicked (and the panic was not due to an AssertThat // failure), add a failure for the panic. // The stack looks like this: // //     <this deferred function> //     panic(r) //     <function that called panic> //