aboutsummaryrefslogtreecommitdiffstats
path: root/eztester.h
blob: d1fbe3c78d2c5ce957d8f4d361f7e6540609ed9c (plain) (blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef _EZTESTER_H
#define _EZTESTER_H

#include <stddef.h>
#include <stdio.h>

// possible results of a test.
// error is always fatal
typedef enum {
  TEST_PASS,
  TEST_WARNING,
  TEST_TIMEOUT,
  TEST_FAIL,
  TEST_ERROR
} ez_status;

/* how eztester should behave when encountering a non passing test.
 */
typedef enum {
  EXIT_NEVER = 0,
  EXIT_ON_WARNING = 1,
  EXIT_ON_TIMEOUT = 2,
  EXIT_ON_FAIL = 4
} ez_behavior;

// a single individual test to be ran
typedef ez_status(ez_runner)();

typedef struct {
  ez_runner *runner;
  const char *name;
  unsigned int max_time_ms;
} ez_test;

typedef struct {
  ez_test *tests;
  size_t length;
  size_t capacity;
} ez_list;

// create a list with a given capacity
ez_list *ez_create_list(const size_t capacity);
/* add a test to a list.
 * the same test can be registered multiple times.
 * will resize the list as necessary
 */
void ez_register(ez_list *test_list, const ez_test new_test);
// remove all tests from a list but do not free the list itself
void ez_clear_list(ez_list *test_list);
// clears a list and free's the list
void ez_destroy_list(ez_list *test_list);

// log info during a test
void ez_log(const char *__restrict format, ...);
// run all tests with a list with a given behavior
void ez_run(ez_list *test_list, const ez_behavior behavior);

/* Wrapper for `system` function
 *
 * if command is null return the availability of a shell (negated result of
 * system's behavior)
 *
 * If command is not null return the exit status of the process
 */
int ez_shell(const char *command);

// tests that always return an ez_status

// always return pass
ez_status ez_always_pass_test();
// always return warning
ez_status ez_always_warn_test();
// always return timeout
ez_status ez_always_timeout_test();
// always return fail
ez_status ez_always_fail_test();
// always return error
ez_status ez_always_error_test();

#endif