# Cgreen Cheat Sheet ## Pre-amble #include #include Describe( ); BeforeEach( ) {} AfterEach( ) {} ## Tests Ensure( , ) { assert_that( ); assert_that( , ); assert_that_double(...); } xEnsure( ... ) ... // Skip this test ## Constraints is_true is_false is_null is_non_null is_equal_to( ) is_equal_to_hex( ) is_not_equal_to( ) is_greater_than( ) is_less_than( ) ### Structs and general data is_equal_to_contents_of( , ) is_not_equal_to_contents_of( , ) ### Strings is_equal_to_string( ) is_not_equal_to_string( ) contains_string( ) does_not_contain_string( ) begins_with_string( ) does_not_begin_with_string( ) ends_with_string( ) does_not_end_with_string( ) ### Floating point values (Doubles) is_equal_to_double( ) is_not_equal_to_double( ) is_less_than_double( ) is_greater_than_double( ) significant_figures_for_assert_double_are( ) ## Mocks ( ) { mock( ); mock( box_double( ) ); return ( ) mock( ); return mock_double( ); } Ensure( ) { expect( {, when(, ) } [, ] [, times( ) ] ); always_expect(...); never_expect(...); } cgreen_mocks_are( strict_mocks | loose_mocks | learning_mocks ); ### Returns will_return( ) will_return_double( ) will_return_by_value( [, ] ) with_side_effect( , ) will_set_scalar_output_parameter( , ) will_set_contents_of_output_parameter( , , ) ## C++ namespace cgreen; assert_throws( , ); ## Minimal Makefile all: $(UNIT)_tests.so cgreen-runner $^ $(UNIT)_tests.so: $(UNIT)_tests.o $(UNIT).o $(CC) -shared -o $@ $^ -lcgreen %.o: %.c $(CC) $(CFLAGS) -fPIC -c -o $@ $^ ## Programmatic control of result fail_test(char *message); pass_test(void); skip_test(void);