bee

package module
v0.0.0-...-5764c14 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 8 Imported by: 0

README

bee

A simple Go test library with colorful output and easily locatable error locations.

Methods

func Test(t *testing.T) {
    bee := bee.New(t)
    bee.Nil(errors.New("whoopsie"))  // whoopsie != <nil>
    bee.NotNil(nil)                  // <nil> == <nil>
    bee.True(false)                  // false != true
    bee.False(true)                  // true != false
    bee.Equal(1, 2)                  // 1 != 2
}

Configure

func Test(t *testing.T) {
    bee := bee.New(
        t,
        bee.ActualColor(191, 29, 245),    // set <actual> color to rgb(191, 29, 245)
        bee.ExpectedColor(50, 168, 127),  // set <expected> color to rgb(50, 168, 127)
        bee.WhatColor(224, 154, 22),      // set <what> color to rgb(224, 154, 22)
        bee.ColumnWidth(60),              // set column width to 60
    )
}
Disable color
  1. set the bee.NoColor() option in bee.New()
  2. pass the -nocolor flag to go test

Output

Basic types
  • Format: <actual> != <expected>
func Test(t *testing.T) {
    bee := bee.New(t)
    bee.Equal(1, 2)
    // 1 != 2
}
Complex types
  • Format: <actual> != <expected> (<what>)
type Person struct {
    Name string
}

func Test(t *testing.T) {
    bee := bee.New(t)
    actual := []Person{{Name: "Obi-Wan Kenobi"}}
    expected := []Person{{Name: "Jar Jar Binks"}}
    bee.Equal(actual, expected)
    // Obi-Wan Kenobi != Jar Jar Binks ([0].Name)
}
Expand

The length of <actual> and <expected> is limited to the column width.

If the output would be longer than twice the column width, the values of <actual> and <expected> are expanded side-by-side in an additional log message.

type Book struct {
    Chapters []Chapter
}

type Chapter struct {
    Text string
}

func Test(t *testing.T) {
    bee := bee.New(t, bee.ColumnWidth(30))
    actual := Book{
        Chapters: []Chapter{
            {
                Text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vehicula volutpat justo, scelerisque egestas nisl volutpat.",
            },
        },
    }
    expected := Book{
        Chapters: []Chapter{
            {
                Text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur scelerisque, sapien eget mattis mattis, eros mi nisi.",
            },
        },
    }
    bee.Equal(actual, expected)
    // Lorem ipsum dolor sit amet,... != Lorem ipsum dolor sit amet,... (.Chapters[0].Text)
    //  
    //    Lorem ipsum dolor sit amet,    Lorem ipsum dolor sit amet,  
    //    consectetur adipiscing elit.   consectetur adipiscing elit. 
    //    Nam vehicula volutpat justo,   Curabitur scelerisque, sapien
    //    scelerisque egestas nisl       eget mattis mattis, eros mi  
    //    volutpat.                      nisi.
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActualColor

func ActualColor(r, g, b uint8) option

func ColumnWidth

func ColumnWidth(w int) option

func ExpectedColor

func ExpectedColor(r, g, b uint8) option

func NoColor

func NoColor() option

func WhatColor

func WhatColor(r, g, b uint8) option

Types

type Bee

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

func New

func New(tb testing.TB, opts ...option) *Bee

func (*Bee) Equal

func (b *Bee) Equal(actual, expected any)

func (*Bee) False

func (b *Bee) False(actual bool)

func (*Bee) Nil

func (b *Bee) Nil(actual any)

func (*Bee) NotNil

func (b *Bee) NotNil(actual any)

func (*Bee) True

func (b *Bee) True(actual bool)

Jump to

Keyboard shortcuts

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