Minctest - tiny unit testing framework for ANSI C

Overview

Minctest

Minctest is a very minimal unit-testing "framework" written in ANSI C and implemented in a single header file. It's handy when you want some real simple unit tests for a small project.

Basically, it implements assertion and equal functions. It'll track and time how many tests pass and fail. Failed tests will also display which line the failing test code was on.

There is a Node.js port here and a Lua port here.

Features

  • C99 with no dependencies.
  • Single header file.
  • Reports file and line number for failed assertions.
  • Reports run time for each test.
  • Tests continue even after an assertion fails.
  • Has assertion for checking float equality.
  • Released under the zlib license - free for nearly any use.

Example

#include "minctest.h"

void test1() {
    lok('a' == 'a');
}

void test2() {
    lequal(5, 5);
    lfequal(5.5, 5.5);
    lsequal("abc", "abc");
}

int main(int argc, char *argv[])
{
    lrun("test1", test1);
    lrun("test2", test2);
    lresults();
    return lfails != 0;
}

That produces the following output:

        test1:
         -- pass: 1                    fail: 0                    time: 12ms
        test2:
         -- pass: 3                    fail: 0                    time: 0ms
ALL TESTS PASSED (4/4)

Hints

 All functions/variables start with the letter 'l'.

Users

Minctest is used in almost all of my C projects, including:

You can check those out to see how Minctest is used in practice.

If you're using Minctest in your project, let me know. I could add a link back.

You might also like...
Tiny OpenEXR image loader/saver library
Tiny OpenEXR image loader/saver library

Tiny OpenEXR image library. tinyexr is a small, single header-only library to load and save OpenEXR (.exr) images. tinyexr is written in portable C++

A tiny C++11 library for reading BVH motion capture data
A tiny C++11 library for reading BVH motion capture data

bvh11 A tiny C++11 library for reading (and writing) BVH motion capture data. Dependencies C++11 standard library Eigen 3 http://eigen.tuxfamily.org/

An Open Source Machine Learning Framework for Everyone
An Open Source Machine Learning Framework for Everyone

Documentation TensorFlow is an end-to-end open source platform for machine learning. It has a comprehensive, flexible ecosystem of tools, libraries, a

header only, dependency-free deep learning framework in C++14
header only, dependency-free deep learning framework in C++14

The project may be abandoned since the maintainer(s) are just looking to move on. In the case anyone is interested in continuing the project, let us k

OpenVSLAM: A Versatile Visual SLAM Framework
OpenVSLAM: A Versatile Visual SLAM Framework

OpenVSLAM: A Versatile Visual SLAM Framework NOTE: This is a community fork of xdspacelab/openvslam. It was created to continue active development of

Caffe: a fast open framework for deep learning.

Caffe Caffe is a deep learning framework made with expression, speed, and modularity in mind. It is developed by Berkeley AI Research (BAIR)/The Berke

A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework based on decision tree algorithms, used for ranking, classification and many other machine learning tasks.

Light Gradient Boosting Machine LightGBM is a gradient boosting framework that uses tree based learning algorithms. It is designed to be distributed a

CNStream is a streaming framework for building Cambricon  machine learning pipelines
CNStream is a streaming framework for building Cambricon machine learning pipelines

CNStream is a streaming framework for building Cambricon machine learning pipelines

Want a faster ML processor? Do it yourself! -- A framework for playing with custom opcodes to accelerate TensorFlow Lite for Microcontrollers (TFLM).

CFU Playground Want a faster ML processor? Do it yourself! This project provides a framework that an engineer, intern, or student can use to design an

Comments
  • Change output format

    Change output format

    For issue #2, I changed output format.

    New format output example:

            Basic equalitypass:
             -- pass: 4092                 fail: 0                    time: 0ms
            Indexing:
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
    c:\users\mothe\documents\github\the-theory-of-automata-and-formal-languages-5-semester\minctest\example.c:18 (a != b)
             -- pass: 9223372036854775837  fail: 10                   time: 5ms
    SOME TESTS FAILED (9223372036854779929/9223372036854779939)
    

    image

    opened by SGmuwa 2
  • Output is badly-aligned for long test names or large numbers of tests

    Output is badly-aligned for long test names or large numbers of tests

    For example:

    [koz@Sebastian bdd-memetic]$ ./test-bitvector 
            Basic equalitypass:4092   fail: 0      1ms
            Indexing      pass:100564992   fail: 0     87ms
    ALL TESTS PASSED (100569084/100569084)
    
    opened by kozross 1
The PULP Ara is a 64-bit Vector Unit, compatible with the RISC-V Vector Extension Version 0.9, working as a coprocessor to CORE-V's CVA6 core

Ara Ara is a vector unit working as a coprocessor for the CVA6 core. It supports the RISC-V Vector Extension, version 0.9. Dependencies Check DEPENDEN

null 185 Dec 24, 2022
Provide sample code of efficient operator implementation based on the Cambrian Machine Learning Unit (MLU) .

Cambricon CNNL-Example CNNL-Example 提供基于寒武纪机器学习单元(Machine Learning Unit,MLU)开发高性能算子、C 接口封装的示例代码。 依赖条件 操作系统: 目前只支持 Ubuntu 16.04 x86_64 寒武纪 MLU SDK: 编译和

Cambricon Technologies 1 Mar 7, 2022
TengineGst is a streaming media analytics framework, based on GStreamer multimedia framework, for creating varied complex media analytics pipelines.

TengineGst is a streaming media analytics framework, based on GStreamer multimedia framework, for creating varied complex media analytics pipelines. It ensures pipeline interoperability and provides optimized media, and inference operations using Tengine Toolkit Inference Engine backend, across varied architecture - CPU, iGPU and VPU.

OAID 69 Dec 17, 2022
Pipy is a tiny, high performance, highly stable, programmable proxy.

Pipy Pipy is a tiny, high performance, highly stable, programmable proxy. Written in C++, built on top of Asio asynchronous I/O library, Pipy is extre

null 539 Dec 28, 2022
Training and fine-tuning YOLOv4 Tiny on custom object detection dataset for Taiwanese traffic

Object Detection on Taiwanese Traffic using YOLOv4 Tiny Exploration of YOLOv4 Tiny on custom Taiwanese traffic dataset Trained and tested AlexeyAB's D

Andrew Chen 5 Dec 14, 2022
YOLOV4 tiny + lane detection on Android with 8 FPS!

YOLOV4 Tiny + Ultra fast lane detection on Android with 8 FPS! Tested with HONOR 20PRO Kirin 980

yq-pan 3 Dec 28, 2022
In this tutorial, we will use machine learning to build a gesture recognition system that runs on a tiny microcontroller, the RP2040.

Pico-Motion-Recognition This Repository has the code used on the 2 parts tutorial TinyML - Motion Recognition Using Raspberry Pi Pico The first part i

Marcelo Rovai 19 Nov 3, 2022
Tiny CUDA Neural Networks

This is a small, self-contained framework for training and querying neural networks. Most notably, it contains a lightning fast "fully fused" multi-layer perceptron as well as support for various advanced input encodings, losses, and optimizers.

NVIDIA Research Projects 1.9k Jan 7, 2023
C++ trainable detection library based on libtorch (or pytorch c++). Yolov4 tiny provided now.

C++ Library with Neural Networks for Object Detection Based on LibTorch. ?? Libtorch Tutorials ?? Visit Libtorch Tutorials Project if you want to know

null 62 Dec 29, 2022
Tiny library for C++ enum introspection and more!

#smart_enum Tiny library for C++ enum introspection... and more! (Sorry for this readme being incomplete, I'm working on updating it. For now, please

Jarda 32 Jan 19, 2022