// ExpectThat confirms that the supplied matcher matches the value x, adding a
// failure record to the currently running test if it does not. If additional
// parameters are supplied, the first will be used as a format string for the
// later ones, and the user-supplied error message will be added to the test
// output in the event of a failure.
//
// For example:
//
//     ExpectThat(userName, Equals("jacobsa"))
//     ExpectThat(users[i], Equals("jacobsa"), "while processing user %d", i)
//
ExpectThat confirms that the supplied matcher matches the value x, adding a
failure record to the currently running test if it does not. If additional
parameters are supplied, the first will be used as a format string for the
later ones, and the user-supplied error message will be added to the test
output in the event of a failure.

For example.

ExpectThat(userName, Equals("jacobsa"))
ExpectThat(users[i], Equals("jacobsa"), "while processing user %d", i)
// ExpectThat confirms that the supplied matcher matches the value x adding a // failure record to the currently running test if it does not . If additional // parameters are supplied the first will be used as a format string for the // later ones and the user - supplied error message will be added to the test // output in the event of a failure . // // For example : // // ExpectThat ( userName Equals ( " jacobsa " )) // ExpectThat ( users [ i ] Equals ( " jacobsa " ) " while processing user %d " i ) //
func ExpectThat(
	x interface{},
	m oglematchers.Matcher,
	errorParts ...interface{}) ExpectationResult {
	res := &expectationResultImpl{}
	_, file, lineNumber, ok := runtime.Caller(1)
	if !ok {
		panic("ExpectThat: runtime.Caller")
	}
	userError := ""
	if len(errorParts) != 0 {
		v := reflect.ValueOf(errorParts[0])
		if v.Kind() != reflect.String {
			panic(fmt.Sprintf("ExpectThat: invalid format string type %v", v.Kind()))
		}
		userError = fmt.Sprintf(v.String(), errorParts[1:]...)
	}
	info := currentlyRunningTest
	if info == nil {
		panic("ExpectThat: no test info.")
	}
	matcherErr := m.Matches(x)
	res.matchError = matcherErr
	if matcherErr == nil {
		return res
	}
	var record failureRecord
	relativeClause := ""
	if matcherErr.Error() != "" {
		relativeClause = fmt.Sprintf(", %s", matcherErr.Error())
	}
	record.GeneratedError = fmt.Sprintf(
		"Expected: %s\nActual:   %v%s",
		m.Description(),
		x,
		relativeClause)
	record.FileName = path.Base(file)
	record.LineNumber = lineNumber
	record.UserError = userError
	info.mutex.Lock()
	defer info.mutex.Unlock()
	info.failureRecords = append(info.failureRecords, &record)
	res.failureRecord = &record
	return res
}
func ExpectThat ( x interface { } , m oglematchers . Matcher , errorParts ... interface { } ) ExpectationResult { res := & expectationResultImpl { } _ , file , lineNumber , ok := runtime . Caller ( 1 ) if ! ok { panic ( " " ) } userError := " " if len ( errorParts ) != 0 { v := reflect . ValueOf ( errorParts [ 0 ] ) if v . Kind ( ) != reflect . String { panic ( fmt . Sprintf ( " " , v . Kind ( ) ) ) } userError = fmt . Sprintf ( v . String ( ) , errorParts [ 1 : ] ... ) } info := currentlyRunningTest if info == nil { panic ( " " ) } matcherErr := m . Matches ( x ) res . matchError = matcherErr if matcherErr == nil { return res } var record failureRecord relativeClause := " " if matcherErr . Error ( ) != " " { relativeClause = fmt . Sprintf ( " " , matcherErr . Error ( ) ) } record . GeneratedError = fmt . Sprintf ( " \n " , m . Description ( ) , x , relativeClause ) record . FileName = path . Base ( file ) record . LineNumber = lineNumber record . UserError = userError info . mutex . Lock ( ) defer info . mutex . Unlock ( ) info . failureRecords = append ( info . failureRecords , & record ) res . failureRecord = & record return res }
ExpectThat confirms that the supplied matcher matches the value x, adding a
failure record to the currently running test if it does not.
ExpectThat confirms that the supplied matcher matches the value x adding a failure record to the currently running test if it does not .
// Get information about the call site. // Assemble the user error, if any. // Grab the current test info. // Check whether the value matches. // Return immediately on success. // Form an appropriate failure message. Make sure that the expected and // actual values align properly. // Record additional failure info. // Store the failure.