Giter Site home page Giter Site logo

orsinium-labs / tinytest Goto Github PK

View Code? Open in Web Editor NEW
32.0 2.0 0.0 10 KB

✅ The only assertion library that works with TinyGo

Home Page: https://pkg.go.dev/github.com/orsinium-labs/tinytest/is

License: MIT License

Go 100.00%
assert assertions framework generics go golang test testify testing tinygo

tinytest's Introduction

tinytest

The only assertion library that works with TinyGo.

  • Why does nothing else work? All assertion libraries use reflect to compare values and to generate error messages. However, TinyGo has very limited support for reflection which is not enough for any of the assertion libraries, including testify and is.
  • How does this work? Instead of reflection, tinytest uses generics for comparing values and fmt for generating error messages.
  • Why would I need an assertion library? Testing with just the standard library is quite verbose. Tests should be easy to write (people already don't like writing tests, don't make it even more difficult) and easy to read and understand.
  • Is it stable? What is already here is pretty stable and reliable. The API might change slightly if I come up with a better one. New features and assertions might be added over time if there is demand. Error messages can change in any release.

Features:

  • 🪶 Zero dependencies
  • 🐹 Pure Go
  • ✅ Works both with Go and TinyGo
  • 🧠 A simple API inspired by is and testify

📦 Installation

go get github.com/orsinium-labs/tinytest

🔧 Usage

import (
    "testing"
    "github.com/orsinium-labs/tinytest/is"
)

func TestHello(t *testing.T) {
    c := is.NewRelaxed(t)
    is.Equal(c, hello(), "Hello world!")
}

Running tests:

tinygo test ./...

If you want to negate the check, wrap c into is.Not:

// asserts that the string is not empty
is.Equal(is.Not(c), hello(), "")

If you want to provide an additional error message, use t.Log or t.Logf:

t.Log("greet Joe")
is.Equal(c, Greet("Joe"), "Hello, Joe")

Or t.Run to run a subtest with the given name:

t.Run("greet_joe", func(t *testing.T) {
    is.Equal(c, Greet("Joe"), "Hello, Joe")
})

📚 Check out documentation for the list of available assertions.

🙅 Known limitations

If you try to call t.FailNow from TinyGo tests, you'll get the following error message:

FailNow is incomplete, requires runtime.Goexit()

Which means that currently calling FailNow does not interrupt the tests. For this reason, tinytest provides only NewRelaxed function that configures all assertions to use Fail instead of FailNow and do not interrupt tests on failures. In future versions, we might to find a workaround for this limitation and then tinytest will also provide a New function that interrupts the tests immediately.

As a workaround, you can explicitly check at critical points if the test has failed and interrupt execution:

if t.Failed() {
    return
}

tinytest's People

Contributors

orsinium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.