github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/internal/testlog/exit.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package testlog 6 7 import "sync" 8 9 // PanicOnExit0 reports whether to panic on a call to os.Exit(0). 10 // This is in the testlog package because, like other definitions in 11 // package testlog, it is a hook between the testing package and the 12 // os package. This is used to ensure that an early call to os.Exit(0) 13 // does not cause a test to pass. 14 func PanicOnExit0() bool { 15 panicOnExit0.mu.Lock() 16 defer panicOnExit0.mu.Unlock() 17 return panicOnExit0.val 18 } 19 20 // panicOnExit0 is the flag used for PanicOnExit0. This uses a lock 21 // because the value can be cleared via a timer call that may race 22 // with calls to os.Exit 23 var panicOnExit0 struct { 24 mu sync.Mutex 25 val bool 26 } 27 28 // SetPanicOnExit0 sets panicOnExit0 to v. 29 func SetPanicOnExit0(v bool) { 30 panicOnExit0.mu.Lock() 31 defer panicOnExit0.mu.Unlock() 32 panicOnExit0.val = v 33 }