Debian Codegraph @

src/tests/cbehave/README.md

raw symbols SCIP
1 cbehave - A Behavior Driven Development Framework for C
2 =======
3
4 A demonstration using real C code:
5
6 #include "cbehave.h"
7
8 // Step 1: define your functions
9 int add(int a, int b);
10
11 // Step 2: describe behaviour and the function calls
12 FEATURE(1, "Addition")
13 SCENARIO("Add two numbers")
14 GIVEN("we have two numbers 50 and 70")
15 int a = 50;
16 int b = 70;
17 GIVEN_END
18 WHEN("we add them together")
19 int r = add(a, b);
20 WHEN_END
21 THEN("the result should be 120")
22 SHOULD_INT_EQUAL(r, 120);
23 THEN_END
24 SCENARIO_END
25 FEATURE_END
26
27 // Step 3: write empty implementations of functions
28 int add(int a, int b)
29 {
30 // Step 5: write code to make the behaviour pass
31 return a + b;
32 }
33
34 // Step 4: run tests and watch them fail (and succeed later)
35 int main()
36 {
37 cbehave_feature calculator_features[] = {
38 {feature_idx(1)}
39 };
40
41 return cbehave_runner(
42 "Calculator Features are as belows:",
43 calculator_features);
44 }
45
46 Recent News
47 -----------
48 - 2013-04-02 fork a copy to https://github.com/bigwhite/cbehave.git.
49 - 2012-04-16 cbehave 0.2.0 released.
50 - 2011-08-14 cbehave 0.1.0 version released.
51
52 Introduction
53 -------------
54 CBehave - A Behavior Driven Development Framework for C.
55
56 Main Features
57 -------------
58
59 - use the "feature + scenario" structure (inspired by Cucumber)
60 - use classical "given-when-then" template to describe behavior scenarios
61 - support mock
62
63 A Typical Example
64 -------------
65
66 An example:
67
68 #include <stdio.h>
69 #include <errno.h>
70 #include "cbehave.h"
71
72 FEATURE(1, "strstr")
73 SCENARIO("The strstr finds the first occurrence of the substring in the source string")
74
75 GIVEN("A source string: [Lionel Messi is a great football player]")
76 char *str = "Lionel Messi is a great football player";
77 GIVEN_END
78
79 WHEN("we use strstr to find the first occurrence of [football]")
80 char *p = strstr(str, "football");
81 WHEN_END
82
83 THEN("We should get the string: [football player]")
84 SHOULD_STR_EQUAL(p, "football player");
85 THEN_END
86 SCENARIO_END
87
88 SCENARIO("If strstr could not find the first occurrence of the substring, it will return NULL")
89
90 GIVEN("A source string: FC Barcelona is a great football club.")
91 char *str = "FC Barcelona is a great football club";
92 GIVEN_END
93
94 WHEN("we use strstr to find the first occurrence of [AC Milan]")
95 char *p = strstr(buf, "AC Milan");
96 WHEN_END
97
98 THEN("We should get no string but a NULL")
99 SHOULD_STR_EQUAL(p, NULL);
100 THEN_END
101 SCENARIO_END
102 FEATURE_END
103
104 int main() {
105 cbehave_feature strstr_features[] = {
106 {feature_idx(1)},
107 };
108
109 return cbehave_runner("Strstr Features are as belows:", strstr_features);
110 }
111
112 The result of the example could be seen like:
113
114 *******************************************************************
115 CBEHAVE -- A Behavior Driven Development Framework for C
116 By Tony Bai
117 *******************************************************************
118 Strstr Features are as belows:
119 Feature: strstr
120 Scenario: The strstr finds the first occurrence of the substring in the source string
121 Given: A source string: Lionel Messi is a great football player
122 When: we use strstr to find the first occurrence of [football]
123 Then: We should get the string: [football player]
124 Scenario: If strstr could not find the first occurrence of the substring, it will return NULL
125 Given: A source string: FC Barcelona is a great football club.
126 When: we use strstr to find the first occurrence of [AC Milan]
127 Then: We should get no string but a NULL
128 Summary:
129 total features: [1]
130 failed features: [0]
131 total scenarios: [2]
132 failed scenarios: [0]
133
134 Build
135 ------
136 - Download the source code package
137 - unzip the package
138 - configure->make->make install
139
140 if you want to compile in 64-bit mode, pass "CPPFLAGS=-m64 LDFLAGS=-m64" to configure.
141
142 sometimes, you may encounter such error:
143
144 mv: cannot stat `.deps/cbehave.Tpo': No such file or directory
145 make[1]: *** [cbehave.lo] Error 1
146
147 a solution for this is execute "libtoolize -f" before "configure".
148
149
150 User Guide
151 -------------
152 For more information, please open and read the project wiki. cbehave user guide is ready for you.
153