Skip to content

A simple, ergonomic test tool in Go (Amazingly small package)

License

Notifications You must be signed in to change notification settings

just-do-halee/lum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lum

Lum is a simple, ergonomic test tool in Go (Amazingly small package).

Go Reference CI Licensed Twitter

| Examples | Latest Note |

go get -u github.com/just-do-halee/lum@latest

Template

import (
    "testing"

    "github.com/just-do-halee/lum"
)

func TestFn(t *testing.T) {
    type Args struct {
        a, b int
    }
    type Ret = int
    type Ctx = *lum.Context[Args, Ret]
    lum.Batch[Args, Ret]{
        {
            Name: "description",
            Args: Args{0, 0},
            Pass: lum.Todo[Args, Ret]()
        },
    }.Run(t, "Fn", nil, nil)
}

How to use,

package example

func Sum(a, b int) int { return a + b }
package example

import (
    "testing"

    "github.com/just-do-halee/lum"
)

func TestSum(t *testing.T) {
    // ... Before All ...

    // Test Function Arguments
    type Args struct {
        a, b int
    }
    // Return Type
    type Ret = int 
    // Context Alias
    type Ctx = *lum.Context[Args, Ret]

    lum.Batch[Args, Ret]{
        {
            Name: "1 + 1 = 2",
            Args: Args{1, 1},
            Pass: func(c Ctx) {
                // ... Assert ...
                c.AssertResultEqual(2)
            },
        },
        {
            Name: "3 > 1 + 3 < 5",
            Args: Args{1, 3},
            Pass: func(c Ctx) {
                // ... Assert ...
                c.Log(c.Arguments)
                c.Logf("result: %v", c.Result)

                c.Assert(c.Result > 3, "should be more than 3")
                c.Assertf(c.Result < 5, "should be less than %v", 5)
            },
        },
        {
            Name: "3 + 5 ...?",
            Args: Args{3, 5},
            // This is unimplemented, so it won't occur any error
        },
        {
            Name: "2 + 4 != 7",
            Args: Args{2, 4},
            // This is todo, so it will occur an error has meta message
            Pass: lum.Todo[Args, Ret]("not equal testing"),
        },
    }.Run(t, "Sum", func(a Args) Ret {
        // ... Before Each ...

        // Call The Actual Function
        return Sum(a.a, a.b)

    }, func(c Ctx) {
        // ... After Each ...
    })
    
    // ... After All ...
}