Giter VIP home page Giter VIP logo

testament's Introduction

Testament

Build Status

Testament is a testing library for Janet. It takes inspiration from Joy's Tester library and Clojure's clojure.test library.

Installation

Add the dependency to your project.janet file:

(declare-project
  :dependencies ["https://github.com/pyrmont/testament"])

Usage

Testament can be used like this:

(import testament :prefix "" :exit true)

(deftest one-plus-one
  (is (= 2 (+ 1 1)) "1 + 1 = 2"))

(deftest two-plus-two
  (is (= 5 (+ 2 2)) "2 + 2 = 5"))

(run-tests!)

Put your tests in the test/ directory within your project and then run:

$ jpm test

If you do the above with a file saved to test/example.janet, you should see:

running test/example.janet ...

> Failed: two-plus-two
Assertion: 2 + 2 = 5
Expect (L): 5
Actual (R): 4

-----------------------------------
2 tests run containing 2 assertions
1 tests passed, 1 tests failed
-----------------------------------

In REPLs

To use Testament in a REPL, set the dynamic variable :testament-repl? to true:

(setdyn :testament-repl? true)

This will (a) stop Testament from exiting your REPL if a test fails, (b) reset the reports between runs and (c) empty the module/cache to prevent old code from running.

API

Documentation for Testament's API is in api.md.

Bugs

Found a bug? I'd love to know about it. The best way is to report your bug in the Issues section on GitHub.

Licence

Testament is licensed under the MIT Licence. See LICENSE for more details.

testament's People

Contributors

fancycade avatar goto-engineering avatar pyrmont avatar roobie avatar yumaikas 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

Watchers

 avatar  avatar  avatar

testament's Issues

Assert-matches succeeds when it should fail

So, assert-match doesn't actually work to fail matches.

Both tests below should fail, but pass instead.

(use testament)

# This is the 22nd of January, 2008, a Tuesday
(def mydate (os/mktime { :year 2008 :month 0 :month-day 21 } true))

(deftest can-assert-matches 
  (assert-matches { :year 2008 :month 0 :day 21 } mydate))

(deftest parse-ymdstr-parses
  (assert-matches { :year 2012 :month 3 :day 0 } nil))

run-tests! check for duplicate names?

It would be nice of run-tests! checked if all the deftest names were unique. I tend to copy and paste deftest and might forget to the change the name. No big deal if all the tests pass, but could be confusing if more than deftest with the same name and I'm looking in the wrong place.

I should point out that I made the decision to just number the assertions using note in assert-equal so I'm throwing away the more detailed output that would negate the need to have run-tests! check for unique names. I don't have a good reason for doing that other than the output is a little cleaner.

Change result descriptions from `expected/actual` to `left/right`

What do you think? I discovered this is how they do it in Elixir's ExUnit, and it feels way more intuitive to me. I can never tell which one is supposed to be "expected" or "actual," and it doesn't matter anyway - we're only testing for equality, not semantics. So I found the left/right much easier to read.

Add match-like assertion

@yumaikas has requested that Testament include a match-like assertion. The API would look like:

(assert-match expect-structure actual-value &opt note)

An example usage:

(assert-match { :month-day 28 } (os/date) "The date includes a `:month-day` key")

The assertion would pass if expect-structure partially matched the actual structure of actual-value (rather than an exact match).

Feature: `each-is`

Add a new macro, each-is:

each-is forms &opt note

forms should be a tuple or array of assertion forms, of the same kind understood by is.

(each-is @[foo bar baz] "note") is equivalent to:

(is foo "note")
(is bar "note")
(is baz "note")

original issue text:

(is @[foo bar baz] note) would be equivalent to (is foo note) (is bar note) ...

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.