3
3
* SPDX-License-Identifier: MIT
4
4
*/
5
5
6
+ #include <stdbool.h>
7
+ #include <string.h>
8
+
9
+ #include <dice/ensure.h>
6
10
#include <dice/interpose.h>
7
11
#include <dice/log.h>
8
- #include <string.h>
9
- #include <assert.h>
10
- #include <stdbool.h>
11
12
12
13
#define MAX_EXP 16
13
14
static char * strings [MAX_EXP ] = {0 };
14
- static char * * head = & strings [0 ];
15
- static char * * tail = & strings [0 ];
15
+ static char * * head = & strings [0 ];
16
+ static char * * tail = & strings [0 ];
16
17
17
- INTERPOSE (ssize_t , write , int fd , const void * buf , size_t count ) {
18
+ INTERPOSE (ssize_t , write , int fd , const void * buf , size_t count )
19
+ {
18
20
static int nest = 0 ;
19
21
if (nest == 1 ) {
20
22
return REAL (write , fd , buf , count );
21
23
}
22
- assert (nest == 0 );
24
+ ensure (nest == 0 );
23
25
nest ++ ;
24
- assert (* tail );
25
- assert (tail < head );
26
- if (strncmp ((char * ) buf , * tail , count ) != 0 ) {
26
+ ensure (* tail );
27
+ ensure (tail < head );
28
+ if (strncmp ((char * ) buf , * tail , count ) != 0 ) {
27
29
log_printf ("exp: %s\n" , * tail );
28
- log_printf ("buf: %s\n" , (char * )buf );
30
+ log_printf ("buf: %s\n" , (char * )buf );
29
31
abort ();
30
32
}
31
33
tail ++ ;
32
34
nest -- ;
33
35
return count ;
34
36
}
35
37
36
- static void expect (char * e ) {
37
- assert (head < strings + MAX_EXP );
38
+ static void
39
+ expect (char * e )
40
+ {
41
+ ensure (head < strings + MAX_EXP );
38
42
* head = e ;
39
43
head ++ ;
40
44
}
41
- static bool empty (void ) {
45
+ static bool
46
+ empty (void )
47
+ {
42
48
return head == tail ;
43
49
}
44
50
49
55
// this should always work
50
56
expect ("print" );
51
57
log_printf ("print" );
52
- assert (empty ());
58
+ ensure (empty ());
53
59
54
60
// this should always work, but we remove the abort to about actually
55
61
// aborting
@@ -60,15 +66,15 @@ main()
60
66
#define abort ()
61
67
log_fatal ("fatal" );
62
68
#undef abort
63
- assert (empty ());
69
+ ensure (empty ());
64
70
65
71
#if LOG_LEVEL_ >= LOG_LEVEL_INFO
66
72
printf ("level >= info\n" );
67
73
expect ("dice: " );
68
74
expect ("info" );
69
75
expect ("\n" );
70
76
log_info ("info" );
71
- assert (empty ());
77
+ ensure (empty ());
72
78
#endif
73
79
74
80
#if LOG_LEVEL_ >= LOG_LEVEL_DEBUG
77
83
expect ("debug" );
78
84
expect ("\n" );
79
85
log_debug ("debug" );
80
- assert (empty ());
86
+ ensure (empty ());
81
87
#endif
82
88
83
-
84
89
return 0 ;
85
90
}
0 commit comments