vegr

package
v0.7.1-pre4 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: Unlicense Imports: 6 Imported by: 0

Documentation

Overview

Package vegr (hel...vegr - the road to helheim) is a place to store library calls that hel mocks need in order to work. We put any non-trivial logic here so that it can have tests, and then allow hel mocks to import and use this properly-tested logic.

Since this is only intended for use by generated code, it eagerly panics for obviously incorrect usage.

Index

Constants

View Source
const (
	// MinVersion is the minimum version of hel that this library can work with.
	// Any version below v0.{MinVersion}.0 uses legacy code that is no longer
	// supported in this version of vegr.
	MinVersion = 7

	// MaxVersion is the maximum version of hel that this library can work with.
	// Any version above v0.{MaxVersion}.* may rely on new features in vegr that
	// don't exist in this version.
	MaxVersion = Version

	// Version is the current version of hel.
	Version = 7
)

Variables

This section is empty.

Functions

func BlockChan added in v0.5.0

func BlockChan() ret.Blocker

BlockChan initializes a channel for use when a method may want to block a return.

func PopulateReturns

func PopulateReturns[T any](t TestingT, timeout time.Duration, mock ReturnMethod[T], addrs ...any)

PopulateReturns handles populating return value addresses with values from channels in a mock.

func TupleDesc

func TupleDesc(t reflect.Type, forceParens bool, isVariadic bool, ignored ...int) string

Types

type EnforceVersion added in v0.6.0

type EnforceVersion uint

EnforceVersion is used by generated code to ensure that runtime code supports the version of the generated code. It relies on uint underflow to break if the version of hel that it was generated with is not supported by the imported version of this library.

The runtime can be updated with:

go get -u git.sr.ht/~nelsam/hel

The generated code can be updated with:

hel

Credit goes to github.com/protocol-buffers/protobuf-go for this idea.

type Method added in v0.7.0

type Method[T, U any] struct {
	// contains filtered or unexported fields
}

Method is a type which can track method call arguments and return values.

func NewMethod added in v0.7.0

func NewMethod[T, U any](receiver, name string, buffer int, opts ...Option) Method[T, U]

NewMethod creates a new method struct using buffer as the channel buffer for input and output channels.

func (Method[T, U]) Block added in v0.7.0

func (m Method[T, U]) Block() ret.Blocker

Block returns the blocking channel for m.

func (Method[T, U]) In added in v0.7.0

func (m Method[T, U]) In() chan T

In returns the input channel for m.

func (Method[T, U]) InDesc added in v0.7.0

func (m Method[T, U]) InDesc() string

InDesc describes the parameters for this method.

func (Method[T, U]) Out added in v0.7.0

func (m Method[T, U]) Out() chan U

Out returns the output channel for m.

func (Method[T, U]) OutDesc added in v0.7.0

func (m Method[T, U]) OutDesc() string

OutDesc describes the parameters for this method.

func (Method[T, U]) String added in v0.7.0

func (m Method[T, U]) String() string

String describes the method's type signature.

func (Method[T, U]) Variadic added in v0.7.0

func (m Method[T, U]) Variadic() bool

Variadic reports whether or not this method's final argument is a variadic argument.

type Option added in v0.7.0

type Option func(methodPrefs) methodPrefs

Option is an option used to construct a method.

func Variadic deprecated added in v0.7.0

func Variadic() Option

Variadic is used to tell vegr that a method is variadic.

Deprecated: In newer code, this is part of the type signature instead of a runtime option in. not a method is variadic is part of its input type signature instead of a runtime option. This means that in newer generated code, we can rely on Method[T, U]{}.Variadic().

type ReturnMethod added in v0.7.0

type ReturnMethod[T any] interface {
	Block() ret.Blocker
	Out() chan T
}

ReturnMethod represents the methods that PopulateReturns uses from a Method.

type TestingT added in v0.6.5

type TestingT interface {
	Helper()
	Failed() bool
	Logf(string, ...any)
	Fatalf(string, ...any)
	Cleanup(func())
}

TestingT represents the properties of *testing.T that vegr uses.

type VariadicIn

type VariadicIn interface {
	Variadic() bool
}

VariadicIn is a type of input struct that declares whether or not it has variadic parameters at compile time.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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