Debian Codegraph @

doc/cheat-sheet.md

raw symbols SCIP
1 # Cgreen Cheat Sheet
2
3 ## Pre-amble
4
5 #include <cgreen/cgreen.h>
6 #include <cgreen/mocks.h>
7
8 Describe( <sut> );
9 BeforeEach( <sut> ) {}
10 AfterEach( <sut> ) {}
11
12 ## Tests
13
14 Ensure( <sut>, <test_name> ) {
15 assert_that( <expression> );
16 assert_that( <expression>, <constraint> );
17 assert_that_double(...);
18 }
19
20 xEnsure( ... ) ... // Skip this test
21
22 ## Constraints
23
24 is_true
25 is_false
26 is_null
27 is_non_null
28 is_equal_to( <value> )
29 is_equal_to_hex( <value> )
30 is_not_equal_to( <value> )
31 is_greater_than( <value> )
32 is_less_than( <value> )
33
34 ### Structs and general data
35
36 is_equal_to_contents_of( <pointer>, <size> )
37 is_not_equal_to_contents_of( <pointer>, <size> )
38
39 ### Strings
40
41 is_equal_to_string( <value> )
42 is_not_equal_to_string( <value> )
43 contains_string( <value> )
44 does_not_contain_string( <value> )
45 begins_with_string( <value> )
46 does_not_begin_with_string( <value> )
47 ends_with_string( <value> )
48 does_not_end_with_string( <value> )
49
50 ### Floating point values (Doubles)
51
52 is_equal_to_double( <value> )
53 is_not_equal_to_double( <value> )
54 is_less_than_double( <value> )
55 is_greater_than_double( <value> )
56
57 significant_figures_for_assert_double_are( <figures> )
58
59 ## Mocks
60
61 <qualifiers> <function_name> ( <parameters> ) {
62 mock( <parameters> );
63 mock( box_double( <parameter> ) );
64 return ( <type> ) mock( <parameters> );
65 return mock_double( <parameters> );
66 }
67
68 Ensure( <sut> ) {
69 expect(<function> {, when(<parameter>, <constraint> ) }
70 [, <returns> ]
71 [, times( <n> ) ] );
72 always_expect(...);
73 never_expect(...);
74 }
75
76 cgreen_mocks_are( strict_mocks | loose_mocks | learning_mocks );
77
78 ### Returns
79
80 will_return( <value> )
81 will_return_double( <value> )
82 will_return_by_value( <value> [, <size>] )
83 with_side_effect( <function>, <pointer_to_data> )
84 will_set_scalar_output_parameter( <parameter_name>, <scalar_value> )
85 will_set_contents_of_output_parameter( <parameter_name>, <value>, <size> )
86
87 ## C++
88
89 namespace cgreen;
90 assert_throws( <exception>, <expression>);
91
92 ## Minimal Makefile
93
94 all: $(UNIT)_tests.so
95 cgreen-runner $^
96
97 $(UNIT)_tests.so: $(UNIT)_tests.o $(UNIT).o
98 $(CC) -shared -o $@ $^ -lcgreen
99
100 %.o: %.c
101 $(CC) $(CFLAGS) -fPIC -c -o $@ $^
102
103 ## Programmatic control of result
104
105 fail_test(char *message);
106 pass_test(void);
107 skip_test(void);