File: testhelper.h

package info (click to toggle)
solvespace 3.1%2Bds1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,964 kB
  • sloc: cpp: 122,491; ansic: 11,375; javascript: 1,919; sh: 89; xml: 44; makefile: 25
file content (49 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* ----------------------------------------------------------------------------
Copyright (c) 2018-2020, Microsoft Research, Daan Leijen
This is free software; you can redistribute it and/or modify it under the
terms of the MIT license. A copy of the license can be found in the file
"LICENSE" at the root of this distribution.
-----------------------------------------------------------------------------*/
#ifndef TESTHELPER_H_
#define TESTHELPER_H_

#include <stdio.h>

// ---------------------------------------------------------------------------
// Test macros: CHECK(name,predicate) and CHECK_BODY(name,body)
// ---------------------------------------------------------------------------
static int ok = 0;
static int failed = 0;

#define CHECK_BODY(name,body) \
 do { \
  fprintf(stderr,"test: %s...  ", name ); \
  bool result = true;                                     \
  do { body } while(false);                                \
  if (!(result)) {                                        \
    failed++; \
    fprintf(stderr,                                       \
            "\n  FAILED: %s:%d:\n  %s\n",                 \
            __FILE__,                                     \
            __LINE__,                                     \
            #body);                                       \
    /* exit(1); */ \
  } \
  else { \
    ok++;                               \
    fprintf(stderr,"ok.\n");                    \
  }                                             \
 } while (false)

#define CHECK(name,expr)      CHECK_BODY(name,{ result = (expr); })

// Print summary of test. Return value can be directly use as a return value for main().
static inline int print_test_summary(void)
{
  fprintf(stderr,"\n\n---------------------------------------------\n"
                 "succeeded: %i\n"
                 "failed   : %i\n\n", ok, failed);
  return failed;
}

#endif // TESTHELPER_H_