hamlet

package
v0.0.0-...-a79fb06 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

This package hold simple unit testing helper used in rcc tests.

Package rcc/hamlet provides DSL for writing terse declarative runnable specifications.

When you want to use Hamlet for runnable specifications, first thing in your specifications should be wrapping *testing.T with "hamlet.Specifications(t)" and you get back two parts, one for positive declarations and one for negative ("to be" and "not to be"; "must be" and "wont be"; "be" and "not").

func TestWrapsTestingT(t *testing.T) {
	to_be, not_to_be := hamlet.Specifications(t)
	...
}

And then you have set of predicates to declare, how system should behave when used in code.

func TestToGetUnderstandingHowSystemWorks(t *testing.T) {
	must_be, wont_be := hamlet.Specifications(t)

	dirname, err := os.Getwd()
	must_be.Nil(err)
	wont_be.Nil(dirname)

	prefix, _ := path.Split(dirname)
	wont_be.Equal(prefix, dirname)
	must_be.True(strings.HasPrefix(dirname, prefix))
}

I like my specifications short and declarative, not longwindy and procedural code form. One line, one expectation!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Specifications

func Specifications(test Reporter) (*Hamlet, *Hamlet)

Types

type Hamlet

type Hamlet struct {
	// contains filtered or unexported fields
}

Structure to hold context sensitive material.

func (*Hamlet) All

func (it *Hamlet) All(property interface{})

func (*Hamlet) Equal

func (it *Hamlet) Equal(expected, actual interface{})

func (*Hamlet) Match

func (it *Hamlet) Match(expected string, actual interface{})

func (*Hamlet) Nil

func (it *Hamlet) Nil(actual interface{})

func (*Hamlet) Panic

func (it *Hamlet) Panic(function Panicable)

func (*Hamlet) Same

func (it *Hamlet) Same(expected, actual interface{})

func (*Hamlet) Text

func (it *Hamlet) Text(expected string, actual interface{})

func (*Hamlet) True

func (it *Hamlet) True(actual bool)

func (*Hamlet) Type

func (it *Hamlet) Type(expected string, actual interface{})

type Panicable

type Panicable func()

Function type used for testing panics.

type Reporter

type Reporter interface {
	Helper()
	Errorf(format string, args ...interface{})
}

Interface to capture relevant *testing.T methods.

Jump to

Keyboard shortcuts

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