github.com/pure-x-eth/consensus_tm@v0.0.0-20230502163723-e3c2ff987250/libs/fail/fail.go (about) 1 package fail 2 3 import ( 4 "fmt" 5 "os" 6 "strconv" 7 ) 8 9 func envSet() int { 10 callIndexToFailS := os.Getenv("FAIL_TEST_INDEX") 11 12 if callIndexToFailS == "" { 13 return -1 14 } 15 16 var err error 17 callIndexToFail, err := strconv.Atoi(callIndexToFailS) 18 if err != nil { 19 return -1 20 } 21 22 return callIndexToFail 23 } 24 25 // Fail when FAIL_TEST_INDEX == callIndex 26 var callIndex int // indexes Fail calls 27 28 func Fail() { 29 callIndexToFail := envSet() 30 if callIndexToFail < 0 { 31 return 32 } 33 34 if callIndex == callIndexToFail { 35 Exit() 36 } 37 38 callIndex++ 39 } 40 41 func Exit() { 42 fmt.Printf("*** fail-test %d ***\n", callIndex) 43 os.Exit(1) 44 // proc, _ := os.FindProcess(os.Getpid()) 45 // proc.Signal(os.Interrupt) 46 // panic(fmt.Sprintf("*** fail-test %d ***", callIndex)) 47 }