GithubHelp home page GithubHelp logo

test.h's Introduction

test.h

A minimalistic test harness for c code.

npm Build Status

Usage

#include "test.h"

BEGIN_TEST();

#define true 1
#define false 0

void test_bools()
{
  ASSERT(1 == true);
  ASSERT(0 == false);
}

void test_ints()
{
  ASSERT(1 == 1);
  ASSERT(0 == 1);
}

int main(void)
{
  TEST(bools);
  TEST(ints);
  TEST_REPORT();
  return TEST_RESULT();
}

Output:

# Testing bools
[OK] 1 == true
[OK] 0 == false

# Testing ints
[OK] 1 == 1
[FAIL] 0 == 1 (at line 17)

# Result
[OK]    3
[FAIL]  1

Api

Exposes the following set of macros:

BEGIN_TEST();

Call this macro at file scope. This sets up test counters.

TEST(function);

Print out a text and call function test_function().

ASSERT(expr);

Evaluate an expression. Does the following:

  • Evaluate expr
  • If expr is true print out message and increment counter for successful tests
  • If expr is false print out message (using __LINE__) and increment counter for failed tests

ABORT(expr);

Like ASSERT(expr) but exits process directly. Useful if you don't want to continue testing for some reason to not end up in infinite loops etc.

TEST_REPORT();

Print out test report.

TEST_RESULT();

Return this in your main (or use with exit()) for proper exit code.

License

MIT

test.h's People

Contributors

ralphtheninja avatar

Stargazers

Jack avatar Yosh avatar

Watchers

 avatar James Cloos 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.