...

Source file src/github.com/dsoprea/go-utility/v2/testing/handled_exit.go

Documentation: github.com/dsoprea/go-utility/v2/testing

     1  package ritesting
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/dsoprea/go-logging"
     7  )
     8  
     9  var (
    10  	exitsAreMarshaled = false
    11  )
    12  
    13  // EnableMarshaledExits enables exit marshaling.
    14  func EnableMarshaledExits() {
    15  	exitsAreMarshaled = true
    16  }
    17  
    18  // DisableMarshaledExits disables exit marshaling.
    19  func DisableMarshaledExits() {
    20  	exitsAreMarshaled = false
    21  }
    22  
    23  // Exit will marshal an exit into a panic if marshaling is turned on. If not
    24  // turned on, forward through to `os.Exit()`.
    25  func Exit(returnCode int) {
    26  	if exitsAreMarshaled == false {
    27  		os.Exit(returnCode)
    28  	}
    29  
    30  	// NOTE(dustin): If we need non-zero success-codes later, we can add a new function for it. Since this is the common case, we'd like this function to have the simplest signature.
    31  
    32  	if returnCode == 0 {
    33  		return
    34  	}
    35  
    36  	log.Panicf("marshaled exit of (%d)", returnCode)
    37  }
    38  

View as plain text