Skip to main content

.

Project description

buildstatus

About

A C test framework.

Based on https://github.com/vberlier/nala.

Features

  • Automatic test discovery

  • Use the same generic assertions everywhere

  • Assertion failures reported as diffs

  • Easy-to-use output capturing utilities

  • Amalgamated source file and header ready to drop in your project

  • Mocking support

  • Works well with errors reported by sanitizers

Installation

Nala is distributed as an amalgamated source file and header:

Drop the two files in your project, make sure nala.c is compiled and linked just like the other source files of your test program and you should be good to go.

Example

First of all, download nala.[hc].

$ wget https://raw.githubusercontent.com/eerimoq/nala/master/dist/nala.h
$ wget https://raw.githubusercontent.com/eerimoq/nala/master/dist/nala.c

Create main.c and write a test case using all assertions and capturing output.

#include "nala.h"

TEST(assertions)
{
    ASSERT_EQ(NULL, NULL);
    ASSERT_NE(1, 2);
    ASSERT_LT(1.0, 2.0);
    ASSERT_LE(1, 1);
    ASSERT_GT(2L, 1L);
    ASSERT_GE(1, 1);
    ASSERT_SUBSTRING("12345", "34");
    ASSERT_NOT_SUBSTRING("12345", "4567");
    ASSERT_MEMORY("abcd", "abcd", 5);
    ASSERT(1 == 1);

    CAPTURE_OUTPUT(stdoutput, stderrput) {
        printf("std!\n");
        fprintf(stderr, "err!\n");
    }

    ASSERT_EQ(stdoutput, "std!\n");
    ASSERT_EQ(stderrput, "err!\n");
}

Build and run the test.

$ gcc *.c && ./a.out
std!
err!

Test results:

  PASSED assertions (0.38 ms)

Tests: 1 passed, 1 total
Time: 0.38 ms

Debugging tips

Nala executes each test in its own process. This means that following the execution of a test with a debugger can be a bit tricky because debuggers like GDB can only follow a single process at a time.

If you’re using GDB, set a breakpoint at <test>_before_fork and then run the program until it stops at the breakpoint. Before continuing the program execution, tell GDB to follow the forked test process by setting follow-fork-mode to child.

All commands are shown below for the test called foo.

$ gdb ./a.out
(gdb) b foo_before_fork
(gdb) r
(gdb) set follow-fork-mode child
(gdb) c

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nala-0.3.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nala-0.3.0-py2.py3-none-any.whl (10.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file nala-0.3.0.tar.gz.

File metadata

  • Download URL: nala-0.3.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for nala-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d607576254b032a3afcd97401e3414c93506735ac59eb9b2abb62f07a8909de6
MD5 9d7bdef13ff39078728ad135b65defcf
BLAKE2b-256 15b9b75deea31453b9ee10803cba40e34914330d9ab687e5bec58fb521efe20d

See more details on using hashes here.

File details

Details for the file nala-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: nala-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for nala-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4fc185f62715d4715afe1f15d83623ce716ba58ac4853d2b2cd5851b1d01d3fc
MD5 645a6335e05a7e992325baa74859e912
BLAKE2b-256 65fb9bd0ca9eec937bc8fa33d4544849830179b311b71c3960c0126832685263

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page