Giter Site home page Giter Site logo

cute's Introduction

Cute

Embedded unit testing for Love2d

Now with Love 11 support.

What?

Cute lets you write unit tests for your game code and run the tests inside of your game.

Cute is designed to be light weight, easy to use and focus on the minimum needed set of features to be confident your code works.

You can also run the tests headlessly on a CI server if that's your jam.

You can find an example of some tests here

Current Features

  • Simple test discovery
  • 'Spy' on hard to test side effects (e.g. graphics calls)
  • Display test results in an in-game GUI
  • Can also be run as part of an automate build process with the --cute-headless flag

What do tests look like?

local cute = require("cute")

notion("Foo is Zap", function ()
  local Foo = "Zap"
  check(Foo).is("Zap") -- passes
end)

notion("1000 circles get drawn", function ()
  minion("circle minion", love.graphics, circle)

  draw_circles(1000)

  check(report("circle minion").calls).is(1000)
end)

How to use

  • Download cute.lua and add it to your your source code.
  • Add cute.go(args) to love.load in your main.lua file - example
  • Optionaly add cute.draw() and cute.keypressed(key) to your love.draw and love.keypressed functions for sweet GUI action (also in main.lua)
  • Run your game with path/to/love game_directory --cute
  • Cute will detect and run any tests in the test directory and every subdirectory ending with _tests.lua

GUI Mode

By default GUI mode has the following controls:

  • h hide the test results
  • j scroll results up
  • k scroll results down

The controls can be remapped with cute.setKeys("hideKey","upKey","downKey")

Matchers

Cute currently has two matchers:

  • check("something", a).is(b) will test if a == b
  • check("some table", {1,2,3}).shallowMatches({1,2,3}) will check that table length and keys and values are the same for both tables

Minions

You can temporarily intercept and record calls to functions. This is useful when you want to test the result of drawing to the screen (or some other hard to test action).

You do this using minions...

local cute = require("cute")

notion("The circles are pink", function ()
  minion("color minion", love.graphics, setColor) -- creates a minion to inspect setColor

  draw_circles(1000)

  check(report("color minion").args).shallowMatches({255, 0, 255}) -- checks what the minion observed
end)

Note: unlike Jasmine or Busted spies minions always call through to the function they are inspecting.

Future Features

Very happy to receive feature requests and pull requests. Currently adding features as I need them.

cute's People

Contributors

dersticher avatar fluffy-critter avatar grizzlyenglish avatar gtrogers 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

Watchers

 avatar  avatar  avatar  avatar

cute's Issues

Add a mini-reporter GUI

Sometimes it's annoying if the tests cover the entire screen. Add the option to display a small widget showing a summary of the test results.

Install with Luarocks

Would be really nice to add a rockspec, so we can also install Cute from luarocks.

Support tagging or WIP tests

Sometimes it's nice to be able to write and commit tests that don't pass yet and not have them fail the build.

This could be achieved by either

notion("one day things will be better", function ()
    -- test code goes here
end, {"some", "tags"})

or...

wip_notion("one day things will be better", function ()
    -- test code goes here
end)

Where we find a suitably cute name for wip_notion... maybe whimsy?

Either way we'd need to add an additional overloaded argument to love.

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.