github.com/bytedance/mockey@v1.2.10/internal/monkey/fn/copy_darwin_amd64_test.go (about) 1 /* 2 * Copyright 2022 ByteDance Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package fn 18 19 import ( 20 "math" 21 "testing" 22 23 "github.com/smartystreets/goconvey/convey" 24 ) 25 26 func callSystemFunc(msg string) int 27 28 func callTwoGoFunc(a int) int { 29 b := math.Abs(float64(a)) 30 c := math.Ilogb(b) 31 return c 32 } 33 34 func callTwoAsmFunc() (uint, uint) 35 36 func asmFunc1() uint 37 38 func asmFunc2() uint 39 40 var ( 41 callSystemFuncStub = func(string) int { return 0 } 42 callTwoGoFuncStub = func(int) int { return 0 } 43 callTwoAsmFuncStub = func() (uint, uint) { return 0, 0 } 44 ) 45 46 func TestCopy(t *testing.T) { 47 Copy(&callSystemFuncStub, callSystemFunc) 48 Copy(&callTwoGoFuncStub, callTwoGoFunc) 49 Copy(&callTwoAsmFuncStub, callTwoAsmFunc) 50 51 convey.Convey("TestCopy", t, func() { 52 callSystemFunc("hello ") 53 callSystemFuncStub("world!\n") 54 55 a1 := callTwoGoFunc(-10) 56 a2 := callTwoGoFuncStub(-10) 57 convey.So(a1, convey.ShouldEqual, 3) 58 convey.So(a2, convey.ShouldEqual, 3) 59 60 b1, c1 := callTwoAsmFunc() 61 b2, c2 := callTwoAsmFuncStub() 62 convey.So(b1, convey.ShouldEqual, 1) 63 convey.So(c1, convey.ShouldEqual, 2) 64 convey.So(b2, convey.ShouldEqual, 1) 65 convey.So(c2, convey.ShouldEqual, 2) 66 }) 67 }