~gustav-hartvigsson/simpletypesystem/meson

« back to all changes in this revision

Viewing changes to tests/test_macros.h

  • Committer: Gustav Hartvigsson
  • Date: 2016-09-08 13:10:20 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20160908131020-sljicwzlrlhjvxgq
* fiddeled with the test macros to make them easyer to read
* Fixed spelling mistakes in utils.h
* Added s_current_time_full ()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
 
#ifndef __H_TEST_MACROS__
3
 
#define __H_TEST_MACROS__
 
2
#pragma once
4
3
 
5
4
#include <stdio.h>
6
5
#include <time.h>
27
26
#define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */
28
27
#endif
29
28
 
 
29
/*
 
30
 * http://stackoverflow.com/a/1551641
 
31
 */
 
32
static inline
 
33
char *
 
34
test_current_time () {
 
35
   char * ret_val = malloc (50);
 
36
   char fmt[50];
 
37
   time_t t = time (NULL);
 
38
   struct timeval tv;
 
39
   gettimeofday (&tv, NULL);
 
40
   strftime (fmt, 50,"%Y-%m-%d %H:%M:%S.%%06uZ%z", localtime (&t));
 
41
   snprintf(ret_val, 50, fmt, tv.tv_usec);
 
42
   return ret_val;
 
43
}
 
44
 
30
45
 
31
46
/******************************************************************************/
32
47
 
33
48
#define setup_suite(sn)                                         \
34
 
  char * current_time () {                                      \
35
 
     char * ret_val = s_malloc (21);                              \
36
 
     time_t t = time (NULL);                                    \
37
 
     strftime (ret_val, 50,"%F %T", localtime (&t));            \
38
 
     return ret_val;                                            \
39
 
  }                                                             \
40
49
  char * suit_name = sn;                                        \
41
 
  char * t_str = current_time();                                \
42
 
  fprintf (stdout, YELLOW "[%s]\n[STARTING TEST SUITE] %s\n"    \
 
50
  char * t_str = test_current_time ();                           \
 
51
  fprintf (stdout, MAGENTA "[%s]\n[STARTING TEST SUITE] %s\n"    \
43
52
  RESET, t_str, suit_name);                                     \
44
 
  s_free (t_str);                                                 \
 
53
  s_free (t_str);                                               \
45
54
  unsigned int total_fails = 0;                                 \
46
55
  unsigned int test_suites_failed = 0;                          \
47
56
  unsigned int tmp_val = 0;
80
89
/******************************************************************************/
81
90
 
82
91
 
83
 
#define test_unit(fun, name)                                    \
84
 
  t_str = current_time ();                                      \
85
 
  tmp_val = fun ();                                             \
86
 
  if (tmp_val > 0) {                                            \
87
 
    total_fails =+ tmp_val;                                     \
88
 
    test_suites_failed++;                                       \
89
 
    fprintf (stderr, RED "[%s]\n[TEST UNIT FAIL] %s\n" RESET,   \
90
 
     t_str, name);                                              \
91
 
  } else {                                                      \
92
 
    fprintf (stdout, GREEN "[%s]\n[TEST UNIT PASS] %s\n" RESET, \
93
 
      t_str, name);                                             \
94
 
  }                                                             \
95
 
  s_free (t_str);
 
92
#define test_unit(fun, name){                                             \
 
93
  t_str = test_current_time ();                                           \
 
94
  fprintf (stdout, BLUE "[%s]\n[STARTING TEST UNIT] %s\n" RESET, t_str, name);\
 
95
  tmp_val = fun ();                                                       \
 
96
  free (t_str); t_str = test_current_time ();                             \
 
97
  if (tmp_val > 0) {                                                      \
 
98
    total_fails =+ tmp_val;                                               \
 
99
    test_suites_failed++;                                                 \
 
100
    fprintf (stderr, RED "[%s]\n[TEST UNIT FAIL] %s\n" RESET,             \
 
101
     t_str, name);                                                        \
 
102
  } else {                                                                \
 
103
    fprintf (stdout, GREEN "[%s]\n[TEST UNIT PASS] %s\n" RESET,           \
 
104
      t_str, name);                                                       \
 
105
  }                                                                       \
 
106
  free (t_str);                                                           \
 
107
}
96
108
 
97
 
#endif /* __H_TEST__ */