nanomsg.org/go/mangos/v2@v2.0.9-0.20200203084354-8a092611e461/test/util.go (about) 1 // Copyright 2019 The Mangos Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use file except in compliance with the License. 5 // You may obtain a copy of the license at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES O R CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package test 16 17 import ( 18 "reflect" 19 "testing" 20 ) 21 22 // MustSucceed verifies that that the supplied error is nil. 23 // If it is not nil, we call t.Fatalf() to fail the test immediately. 24 func MustSucceed(t *testing.T, e error) { 25 if e != nil { 26 t.Fatalf("Error is not nil: %v", e) 27 } 28 } 29 30 // MustFail verifies that the error is not nil. 31 // If it is nil, the test is a fatal failure. 32 func MustFail(t *testing.T, e error) { 33 if e == nil { 34 t.Fatalf("Error is nil") 35 } 36 } 37 38 // MustBeTrue verifies that the condition is true. 39 func MustBeTrue(t *testing.T, b bool) { 40 if !b { 41 t.Fatalf("Condition is false") 42 } 43 } 44 45 // MustBeFalse verifies that the condition is true. 46 func MustBeFalse(t *testing.T, b bool) { 47 if b { 48 t.Fatalf("Condition is true") 49 } 50 } 51 52 // MustNotBeNil verifies that the provided value is not nil 53 func MustNotBeNil(t *testing.T, v interface{}) { 54 if reflect.ValueOf(v).IsNil() { 55 t.Fatalf("Value is nil") 56 } 57 } 58 59 // MustBeNil verifies that the provided value is nil 60 func MustBeNil(t *testing.T, v interface{}) { 61 if !reflect.ValueOf(v).IsNil() { 62 t.Fatalf("Value is not nil: %v", v) 63 } 64 }