blob: 9498bb0432f523034957e3272567e7104766795e [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package assert
import "android.googlesource.com/platform/tools/gpu/framework/compare"
// OnError is the result of calling ThatError on an Assertion.
// It provides assertion tests that are specific to error types.
type OnError struct {
Assertion
err error
}
// Succeeded asserts that the error value was nil.
func (o OnError) Succeeded() bool {
return o.Assertion.test(o.err == nil, expected, o.err, "success")
}
// Failed asserts that the error value was not nil.
func (o OnError) Failed() bool {
return o.Assertion.test(o.err != nil, expected, "nil", "failure")
}
// Equals asserts that the error value matches the expected error.
func (o OnError) Equals(expect error) bool {
return o.Assertion.test(o.err == expect, expected, o.err, expect)
}
// DeepEquals asserts that the error value matches the expected error using compare.DeepEqual.
func (o OnError) DeepEquals(expect error) bool {
return o.Assertion.test(compare.DeepEqual(o.err, expect), expected, o.err, expect)
}
// HasMessage asserts that the error string matches the expected message.
func (o OnError) HasMessage(expect string) bool {
return o.Assertion.test(o.err != nil && o.err.Error() == expect, expected, o.err, expect)
}