README.md
1cbehave - A Behavior Driven Development Framework for C
2=======
3[![Build Status](https://travis-ci.org/cxong/cbehave.svg?branch=master)](https://travis-ci.org/cxong/cbehave)
4
5A demonstration using real C code:
6
7 #include "cbehave.h"
8
9 // Step 1: define your functions
10 int add(int a, int b);
11
12 // Step 2: describe behaviour and the function calls
13 FEATURE(addition, "Addition")
14 SCENARIO("Add two numbers")
15 GIVEN("we have two numbers 50 and 70")
16 int a = 50;
17 int b = 70;
18 WHEN("we add them together")
19 int r = add(a, b);
20 THEN("the result should be 120")
21 SHOULD_INT_EQUAL(r, 120);
22 SCENARIO_END
23 FEATURE_END
24
25 // Step 3: write empty implementations of functions
26 int add(int a, int b)
27 {
28 // Step 5: write code to make the behaviour pass
29 return a + b;
30 }
31
32 // Step 4: run tests and watch them fail (and succeed later)
33 CBEHAVE_RUN("Calculator Features are as below:", TEST_FEATURE(addition))
34
35Introduction
36-------------
37CBehave - A Behavior Driven Development Framework for C.
38
39Main Features
40-------------
41
42 - use the "feature + scenario" structure (inspired by Cucumber)
43 - use classical "given-when-then" template to describe behavior scenarios
44 - support mock
45
46Example Output
47-------------
48
49 *******************************************************************
50 CBEHAVE -- A Behavior Driven Development Framework for C
51 By Tony Bai
52 *******************************************************************
53 Strstr Features are as belows:
54 Feature: strstr
55 Scenario: The strstr finds the first occurrence of the substring in the source string
56 Given A source string: Lionel Messi is a great football player
57 When we use strstr to find the first occurrence of [football]
58 Then We should get the string: [football player]
59 Scenario: If strstr could not find the first occurrence of the substring, it will return NULL
60 Given A source string: FC Barcelona is a great football club.
61 When we use strstr to find the first occurrence of [AC Milan]
62 Then We should get no string but a NULL
63 Summary:
64 features: [1/1]
65 scenarios: [2/2]
66
67Build
68------
69
70To run the examples:
71
72 - Clone the project
73 - cmake cbehave/examples
74
75To use cbehave in your CMake project:
76
77- include the cbehave directory
78- link against `cbehave`
79