Skip to content

[English] METRIC_TEST

Luiz Felipe edited this page Aug 21, 2021 · 3 revisions
METRIC_TEST(test_name);
METRIC_TEST_END();
METRIC_TEST_FAIL(message);
METRIC_TEST_OK(message);

METRIC_TEST runs a test function and prints your status at the end. A test function returns the status, and the macros METRIC_TEST_FAIL and METRIC_TEST_OK can be used to set this status. The execution of theses macros do the function stops the execution. The macro METRIC_TEST_END can be used at the end of all tests to display status about tests' failures and successes. These macro returns from main the number of failed tests.

A test function should have test_t type of return and doesn't have parameters.

Example

#include <stdio.h>
#include "metric.h"

test_t test_go_fail(void)
{
  volatile int x = 3;

  if (x < 5) {
    METRIC_TEST_FAIL("x is less than 5");
  }

  METRIC_TEST_OK("x is the bigger \\o/");
}

test_t test_go_success(void)
{
  volatile int x = 9;
  
  if (x < 5) {
    METRIC_TEST_FAIL("x is less than 5");
  }

  METRIC_TEST_OK("x is the bigger \\o/");
}

int main(void)
{
  METRIC_TEST(test_go_fail);
  METRIC_TEST(test_go_success);
  METRIC_TEST_END();
}

Output:

<TEST> tst.c:28: test_go_fail
[FAIL] x is less than 5
<TEST> tst.c:29: test_go_success
[ OK ] x is the bigger \o/

Tests: 2 | Failures: 1 | Successes: 1