Now, I know assert.h is not meant for unit testing, I know it's got alot of limitations (like stopping the process on error, no easy way to organize, isolate or initialize test cases alone and so on). But for small function test driven development it's rather decent, here's an example of a function that checks if the first string (s) end with the same chars as the second string (t):

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
#include <assert.h>
#ifndef NULL
#define __DEF_NULL
#define NULL 0
#endif

/**
  * Takes 2 strings, if s ends with t, returns 1, else 0.
  */
int strend(const char *s, const char *t);

int main() {
  assert(strend(NULL, NULL) == 0);
  assert(strend(NULL, "test") == 0);
  assert(strend("test", NULL) == 0);
  assert(strend("hej", "dav") == 0);
  assert(strend("hejsa", "jsa") == 1);
  assert(strend("hej", "davhej") == 0);
  assert(strend("davs", "davs") == 1);
  assert(strend("hejsa", "hejsb") == 0);
  assert(strend("hejsa", "heisa") == 0);
  assert(strend("hejsa", "hejba") == 0);
  assert(strend("jeg er glad", "r glad") == 1);
  assert(strend("hejsa", "ejs") == 0);
  return 0;
}

int strend(const char *s, const char *t) {
  const char *ptrs = s, *ptrt = t;
  if (s == NULL || t == NULL)
    return 0;
  while (*ptrs != '<pre wp-pre-tag-0></pre>')
    ptrs++;
  while (*ptrt != '<pre wp-pre-tag-0></pre>')
    ptrt++;
  while (*ptrs == *ptrt) {
    if (ptrs == s)
      return ptrt == t ? 1 : 0;
    else if (ptrt == t)
      return 1;
    else {
      ptrt--;
      ptrs--;
    }
  }
  return 0;
}

#ifdef __DEF_NULL
#undef NULL
#endif

For real unit testing capabilities in c, I'll have a loop at cunit or similar.