Skip to main content

testest

To run Factor tests, Codewars currently uses a custom test vocabulary, published and available in this GitHub repository.

Basic Usage

USING: solution-vocabulary tools.testest ;
IN: solution-vocabulary.tests

: run-tests ( -- )
  "Example Tests" describe#{
    "Example test case" it#{
      <{ 1 1 add -> 2 }>
    }#

    "Another test case" it#{
     <{ 3 double -> 6 }>
     <{ 0 double -> 0 }>
    }#
  }#

MAIN: run-tests
USING: solution-vocabulary tools.testest ;
IN: solution-vocabulary.tests

: run-tests ( -- )
  "Example Tests" describe#{
    "Example test case" it#{
      <{ 1 1 add -> 2 }>
    }#

    "Another test case" it#{
     <{ 3 double -> 6 }>
     <{ 0 double -> 0 }>
    }#
  }#

MAIN: run-tests

Words and Syntax

describe#{

Starts a new block of tests, taking a string off the stack as the title of the block. Terminated with the }# word.

it#{

Starts a new test group, taking a string off the stack as the title of the block. Terminated with the }# word.

<{ ...inputs -> ...expected }>

Creates a unit test, by executing the values in ...inputs, then executing the values in ...expected and comparing the resulting stacks. If they match, the test is passed, otherwise the test is failed. On failure, the stacks are packed into a tuple (under got and expected slots, respectively) and pushed onto the stack to be available for the test-failed. quotation.

test-passed.

test-passed. is a symbol which is bound to a quotation with stack effect ( -- ). When a unit test passes, this quotation will be called. This can be used to create custom result messages.

test-failed.

test-passed. is a symbol which is bound to a quotation with stack effect ( assert-sequence -- ). When a unit test fails, the values on the left and right side of the test will be collected into sequences, and stored in tuple under slots got and expected respectively. This tuple will be pushed onto the stack, and then this quotation will be called. This can be used to create custom result messages.

Acknowledgements

testest was authored by @nomennescio.