All Projects → jozanza → pico-test

jozanza / pico-test

Licence: MIT license
⚡ PICO-8 testing framework

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to pico-test

PICO-EC
A tiny scene-entity-component library created for the PICO-8 fantasty console.
Stars: ✭ 37 (+12.12%)
Mutual labels:  pico-8
Online-Book-Store
An online Book Store createed with Python / Flask rest, MySql,Angular and Bootstrap
Stars: ✭ 76 (+130.3%)
Mutual labels:  cart
mytek
Django e-commerce web application with advanced features
Stars: ✭ 27 (-18.18%)
Mutual labels:  cart
Awesome Pico 8
A curated list of awesome PICO-8 resources, carts, tools and more
Stars: ✭ 1,955 (+5824.24%)
Mutual labels:  pico-8
pico2tic
PICO-8 Wrapper for the TIC-80
Stars: ✭ 48 (+45.45%)
Mutual labels:  pico-8
PICO-8.vim
A vim plugin package for PICO-8 programming.
Stars: ✭ 42 (+27.27%)
Mutual labels:  pico-8
tac08
tac08 is an an emulation of the runtime part of the Pico-8 fantasy console. It takes a .p8 (text format) pico-8 cart file and runs it as closely posible
Stars: ✭ 144 (+336.36%)
Mutual labels:  pico-8
react-use-cart
React hook library for managing cart state
Stars: ✭ 297 (+800%)
Mutual labels:  cart
P8Coder
A programming tool that replaces the lua code in pico-8 cartridges (p8) with the code you write in P8Coder.
Stars: ✭ 89 (+169.7%)
Mutual labels:  pico-8
Frontend-Learning-Journey
Tutorials, definitions, frameworks and some of the projects i made when starting to learn frontend web developement
Stars: ✭ 28 (-15.15%)
Mutual labels:  cart
p8
👾 PICO-8 dependency manager
Stars: ✭ 44 (+33.33%)
Mutual labels:  pico-8
decision-trees-for-ml
Building Decision Trees From Scratch In Python
Stars: ✭ 61 (+84.85%)
Mutual labels:  cart
checkout
Laravel Cart, Checkout, Orders and Coupons API with Nova Management
Stars: ✭ 36 (+9.09%)
Mutual labels:  cart
Pyxel
A retro game engine for Python
Stars: ✭ 9,133 (+27575.76%)
Mutual labels:  pico-8
ng-shopping-cart
🛒 An Angular component library to create shopping carts
Stars: ✭ 46 (+39.39%)
Mutual labels:  cart
pico8-emmylua-definitions
EmmyLua intellisense definitions for PICO-8
Stars: ✭ 25 (-24.24%)
Mutual labels:  pico-8
pico-8-adventure
An open-world adventure game written in Pico-8, including full tutorial.
Stars: ✭ 24 (-27.27%)
Mutual labels:  pico-8
E-learning-Django-
edurekanet.herokuapp.com/
Stars: ✭ 68 (+106.06%)
Mutual labels:  cart
cart
Shopping cart composer package
Stars: ✭ 109 (+230.3%)
Mutual labels:  cart
magento-2-sticky-cart
Magento 2 Sticky add to cart displayed as a sticky scroll bar summary of the product information, helps customers can quickly add products without going back to the top of the page.
Stars: ✭ 14 (-57.58%)
Mutual labels:  cart

pico-test

npm version build status code style

Note: This project is still in its initial stages, so I'd love feedback about the API and issue reports.

Intro

PICO-8 is great but debugging your code in this little vm can be a chore.

If you're tired of riddling your carts with prinths or have given up on test-driven development, this tool should help you out.

Installation

npm i -g pico-test

Note: you can also download it directly from the releases section

Usage

Copy/paste the following snippet into the cart you wish to test:

function test(title,f)
local desc=function(msg,f)
 printh('⚡:desc:'..msg)
 f()
end
local it=function(msg,f)
 printh('⚡:it:'..msg)
 local xs={f()}
 for i=1,#xs do
  if xs[i] == true then
   printh('⚡:assert:true')
  else
   printh('⚡:assert:false')
  end
 end
 printh('⚡:it_end')
end
printh('⚡:test:'..title)
f(desc,it)
printh('⚡:test_end')
end

Next, be sure PICO-8 is aliased properly in your terminal. You may have to do something like the following:

alias pico-8='/Applications/PICO-8.app/Contents/MacOS/pico8'

Last, run Pico-8 from your terminal and pipe its output to pico-test.

pico-8 | pico-test

Each time your run your cart, test results will be printed to stdout. Now, you just have to write some tests! :)

API

pico-test's api is will be pretty familiar if you've ever used mocha. There are only 3 functions to learn: test(), desc(), and it()

test(title:string, fn:function)

initiates testing, wraps around test descriptions and tests, providing the callback fn with two args: desc and it – the other two functions in this API.

Type Param Description
String title title of test suite
Function fn callback to call with desc and it

desc(description:string, fn:function)

Describes a set of tests. This function is applied as the first argument of the callback function passed to test

Type Param Description
String description description for tests to be run inside of param fn
Function fn callback to call with desc and it

it(message:string, fn:function)

Returns one or more boolean values representing test assertions. all returned values must be true or your test will fail. This function is applied as the second argument of the callback function passed to test

Type Param Description
String message message starting with "should"
Function fn callback to return assertions from

Example

Here's what it looks like in action:

-- here's an object with methods we want to test
local math={
  gt=function(a,b) return a>b end,
  lt=function(a,b) return a<b end,
  mul=function(a,b) return a*b end,
  div=function(a,b) return a/b end
}

test('math functions', function(desc,it)
  desc('math.gt()', function()
    local gt = math.gt
    it('should return type boolean', function()
      return 'boolean' == type(gt(1,0))
    end)
    it('should give same result as > operator', function()
      return gt(1,0)
    end)
  end)

  desc('math.lt()', function()
    local lt = math.lt
    it('should return type boolean',function()
      return 'boolean' == type(lt(1,0))
    end)
    it('should give same result as < operator',function()
      return lt(1, 0) == false
    end)
  end)

  desc('math.mul()', function()
    local mul = math.mul
    it('should return type number', function()
      local a = rnd(time())
      local b = rnd(time())
      return 'number' == type(mul(a,b))
    end)
    it('should give same result as * operator', function()
      local x=rnd(time())
      return
        x*1 == mul(x,1),
        x*2 == mul(x,2),
        x*3 == mul(x,3)
   end)
  end)

  desc('math.div()', function()
    local div = math.div
    it('should return type number', function()
      local a = rnd(time())
      local b = rnd(time())
      return 'number' == type(div(a,b))
    end)
    it('should give same result as / operator', function()
      local x=1+rnd(time())
      return
        x/1 == div(x,1),
        x/2 == div(x,2),
        x/3 == div(x,3)
    end)
  end)

end)

License

Copyright (c) 2015 Josiah Savary. Made available under The MIT License (MIT).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].