assert

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package assert is a helper to allow assert tests in a more standardized and simple manner. Using it makes it clear the this is an assertion used in non production setting.

Index

Constants

View Source
const DEBUG = false

DEBUG if this is set to "true" asserts are evaluated.

Variables

This section is empty.

Functions

func Assert

func Assert(test bool, msg string, a ...interface{})

Assert runs the provided function and throws panic with the given message if the test evaluates to false. Unfortunately GO still executes parameters (e.g. value.String() of calls to this even if the function is a null function when DEBUG is set to false. So it is necessary to also have a if assert.DEBUG {} wrapper around calls to this to really avoid any run time impact. The GO compiler will then eliminate the whole statement if DEBUG as a const is set to false. Example:

 if assert.DEBUG {
	  assert.Assert(value > 0, "Error message if test fails %s", value.String())
 }

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL