"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/github.com/stretchr/testify/assert/assertions.go" between
gitea-1.9.3.tar.gz and gitea-1.9.4.tar.gz

About: Gitea allows to set up a self-hosted code hosting Git service (a fork of Gogs).

assertions.go  (gitea-1.9.3):assertions.go  (gitea-1.9.4)
skipping to change at line 21 skipping to change at line 21
"reflect" "reflect"
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
"time" "time"
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/pmezard/go-difflib/difflib" "github.com/pmezard/go-difflib/difflib"
yaml "gopkg.in/yaml.v2"
) )
//go:generate go run ../_codegen/main.go -output-package=assert -template=assert ion_format.go.tmpl //go:generate go run ../_codegen/main.go -output-package=assert -template=assert ion_format.go.tmpl
// TestingT is an interface wrapper around *testing.T // TestingT is an interface wrapper around *testing.T
type TestingT interface { type TestingT interface {
Errorf(format string, args ...interface{}) Errorf(format string, args ...interface{})
} }
// ComparisonAssertionFunc is a common function prototype when comparing two val ues. Can be useful // ComparisonAssertionFunc is a common function prototype when comparing two val ues. Can be useful
skipping to change at line 353 skipping to change at line 354
expected, actual = formatUnequalValues(expected, actual) expected, actual = formatUnequalValues(expected, actual)
return Fail(t, fmt.Sprintf("Not equal: \n"+ return Fail(t, fmt.Sprintf("Not equal: \n"+
"expected: %s\n"+ "expected: %s\n"+
"actual : %s%s", expected, actual, diff), msgAndArgs...) "actual : %s%s", expected, actual, diff), msgAndArgs...)
} }
return true return true
} }
// Same asserts that two pointers reference the same object.
//
// assert.Same(t, ptr1, ptr2)
//
// Both arguments must be pointer variables. Pointer variable sameness is
// determined based on the equality of both type and value.
func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) b
ool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
expectedPtr, actualPtr := reflect.ValueOf(expected), reflect.ValueOf(actu
al)
if expectedPtr.Kind() != reflect.Ptr || actualPtr.Kind() != reflect.Ptr {
return Fail(t, "Invalid operation: both arguments must be pointer
s", msgAndArgs...)
}
expectedType, actualType := reflect.TypeOf(expected), reflect.TypeOf(actu
al)
if expectedType != actualType {
return Fail(t, fmt.Sprintf("Pointer expected to be of type %v, bu
t was %v",
expectedType, actualType), msgAndArgs...)
}
if expected != actual {
return Fail(t, fmt.Sprintf("Not same: \n"+
"expected: %p %#v\n"+
"actual : %p %#v", expected, expected, actual, actual),
msgAndArgs...)
}
return true
}
// formatUnequalValues takes two values of arbitrary types and returns string // formatUnequalValues takes two values of arbitrary types and returns string
// representations appropriate to be presented to the user. // representations appropriate to be presented to the user.
// //
// If the values are not of like type, the returned strings will be prefixed // If the values are not of like type, the returned strings will be prefixed
// with the type name, and the value will be enclosed in parenthesis similar // with the type name, and the value will be enclosed in parenthesis similar
// to a type conversion in the Go grammar. // to a type conversion in the Go grammar.
func formatUnequalValues(expected, actual interface{}) (e string, a string) { func formatUnequalValues(expected, actual interface{}) (e string, a string) {
if reflect.TypeOf(expected) != reflect.TypeOf(actual) { if reflect.TypeOf(expected) != reflect.TypeOf(actual) {
return fmt.Sprintf("%T(%#v)", expected, expected), return fmt.Sprintf("%T(%#v)", expected, expected),
fmt.Sprintf("%T(%#v)", actual, actual) fmt.Sprintf("%T(%#v)", actual, actual)
skipping to change at line 482 skipping to change at line 514
if object == nil { if object == nil {
return true return true
} }
objValue := reflect.ValueOf(object) objValue := reflect.ValueOf(object)
switch objValue.Kind() { switch objValue.Kind() {
// collection types are empty when they have no element // collection types are empty when they have no element
case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice: case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:
return objValue.Len() == 0 return objValue.Len() == 0
// pointers are empty if nil or if the value they point to is empty // pointers are empty if nil or if the value they point to is emp ty
case reflect.Ptr: case reflect.Ptr:
if objValue.IsNil() { if objValue.IsNil() {
return true return true
} }
deref := objValue.Elem().Interface() deref := objValue.Elem().Interface()
return isEmpty(deref) return isEmpty(deref)
// for all other types, compare against the zero value // for all other types, compare against the zero value
default: default:
zero := reflect.Zero(objValue.Type()) zero := reflect.Zero(objValue.Type())
return reflect.DeepEqual(object, zero.Interface()) return reflect.DeepEqual(object, zero.Interface())
} }
} }
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
// a slice or a channel with len == 0. // a slice or a channel with len == 0.
// //
// assert.Empty(t, obj) // assert.Empty(t, obj)
skipping to change at line 632 skipping to change at line 664
} }
// containsElement try loop over the list check if the list includes the element . // containsElement try loop over the list check if the list includes the element .
// return (false, false) if impossible. // return (false, false) if impossible.
// return (true, false) if element was not found. // return (true, false) if element was not found.
// return (true, true) if element was found. // return (true, true) if element was found.
func includeElement(list interface{}, element interface{}) (ok, found bool) { func includeElement(list interface{}, element interface{}) (ok, found bool) {
listValue := reflect.ValueOf(list) listValue := reflect.ValueOf(list)
elementValue := reflect.ValueOf(element) listKind := reflect.TypeOf(list).Kind()
defer func() { defer func() {
if e := recover(); e != nil { if e := recover(); e != nil {
ok = false ok = false
found = false found = false
} }
}() }()
if reflect.TypeOf(list).Kind() == reflect.String { if listKind == reflect.String {
elementValue := reflect.ValueOf(element)
return true, strings.Contains(listValue.String(), elementValue.St ring()) return true, strings.Contains(listValue.String(), elementValue.St ring())
} }
if reflect.TypeOf(list).Kind() == reflect.Map { if listKind == reflect.Map {
mapKeys := listValue.MapKeys() mapKeys := listValue.MapKeys()
for i := 0; i < len(mapKeys); i++ { for i := 0; i < len(mapKeys); i++ {
if ObjectsAreEqual(mapKeys[i].Interface(), element) { if ObjectsAreEqual(mapKeys[i].Interface(), element) {
return true, true return true, true
} }
} }
return true, false return true, false
} }
for i := 0; i < listValue.Len(); i++ { for i := 0; i < listValue.Len(); i++ {
skipping to change at line 1340 skipping to change at line 1373
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid js on.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...) return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid js on.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...)
} }
if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil { if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil {
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\ nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...) return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\ nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...)
} }
return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArg s...) return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArg s...)
} }
// YAMLEq asserts that two YAML strings are equivalent.
func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
var expectedYAMLAsInterface, actualYAMLAsInterface interface{}
if err := yaml.Unmarshal([]byte(expected), &expectedYAMLAsInterface); err
!= nil {
return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid ya
ml.\nYAML parsing error: '%s'", expected, err.Error()), msgAndArgs...)
}
if err := yaml.Unmarshal([]byte(actual), &actualYAMLAsInterface); err !=
nil {
return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid yaml.\
nYAML error: '%s'", actual, err.Error()), msgAndArgs...)
}
return Equal(t, expectedYAMLAsInterface, actualYAMLAsInterface, msgAndArg
s...)
}
func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) { func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) {
t := reflect.TypeOf(v) t := reflect.TypeOf(v)
k := t.Kind() k := t.Kind()
if k == reflect.Ptr { if k == reflect.Ptr {
t = t.Elem() t = t.Elem()
k = t.Kind() k = t.Kind()
} }
return t, k return t, k
} }
skipping to change at line 1374 skipping to change at line 1425
if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array && ek != reflect.String { if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array && ek != reflect.String {
return "" return ""
} }
var e, a string var e, a string
if et != reflect.TypeOf("") { if et != reflect.TypeOf("") {
e = spewConfig.Sdump(expected) e = spewConfig.Sdump(expected)
a = spewConfig.Sdump(actual) a = spewConfig.Sdump(actual)
} else { } else {
e = expected.(string) e = reflect.ValueOf(expected).String()
a = actual.(string) a = reflect.ValueOf(actual).String()
} }
diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: difflib.SplitLines(e), A: difflib.SplitLines(e),
B: difflib.SplitLines(a), B: difflib.SplitLines(a),
FromFile: "Expected", FromFile: "Expected",
FromDate: "", FromDate: "",
ToFile: "Actual", ToFile: "Actual",
ToDate: "", ToDate: "",
Context: 1, Context: 1,
skipping to change at line 1417 skipping to change at line 1468
var spewConfig = spew.ConfigState{ var spewConfig = spew.ConfigState{
Indent: " ", Indent: " ",
DisablePointerAddresses: true, DisablePointerAddresses: true,
DisableCapacities: true, DisableCapacities: true,
SortKeys: true, SortKeys: true,
} }
type tHelper interface { type tHelper interface {
Helper() Helper()
} }
// Eventually asserts that given condition will be met in waitFor time,
// periodically checking target function each tick.
//
// assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Mi
llisecond)
func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t
ime.Duration, msgAndArgs ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
timer := time.NewTimer(waitFor)
ticker := time.NewTicker(tick)
checkPassed := make(chan bool)
defer timer.Stop()
defer ticker.Stop()
defer close(checkPassed)
for {
select {
case <-timer.C:
return Fail(t, "Condition never satisfied", msgAndArgs...
)
case result := <-checkPassed:
if result {
return true
}
case <-ticker.C:
go func() {
checkPassed <- condition()
}()
}
}
}
 End of changes. 10 change blocks. 
7 lines changed or deleted 70 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)