Skip to content

Commit fd024de

Browse files
committed
README fix
1 parent 993d76c commit fd024de

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

README.md

+16-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ C Mock - Google Mock Extension
66
Overview
77
--------
88

9-
C Mock is [Google Mock][1]'s extension allowing a function mocking.
9+
C Mock is [Google Mock][1]'s extension allowing a function mocking. Only global (non-static) functions mocking is supported.
1010

1111
This is neither a patch to nor fork of Google Mock. This is just a set of headers providing a way to use tools for mock methods with mock functions in tests.
1212

@@ -159,7 +159,7 @@ foo(1, 2); // calling the real function
159159
160160
C Mock uses specific GNU/Linux features internally and a test build requires a few additional steps.
161161
162-
Firstly, all functions you want to mock must be compiled into a dynamic library. If it includes your project-specific functions you must put them into a dynamic library as well. In such circumstances, it seems reasonable to build all code under test as a dynamic library. Selecting only those parts that you are going to mock might be tedious and cumbersome.
162+
Firstly, all functions you want to mock must be compiled into a dynamic library. If it includes your project-specific functions you must put them into a dynamic library as well.
163163
164164
Secondly, you must pass the following options to a linker when building a test executable:
165165
@@ -183,24 +183,27 @@ to get the compilations and linker options, respectively.
183183

184184
Since [it is not recommended to install a pre-compiled version of Google Test][4] many distributions don't provide pre-compiled Google Test anymore. You need to download and compile Google Test manually as described in [Google Test][1]. The optional second command argument is a path to a directory containing downloaded and built Google Test.
185185

186-
Suppose you have `foo.c` and `bar.c` files containing a code under a test and a `foobar_test.cc` file containing the tests. To build your test executable:
186+
Suppose you have `foo.c` and `bar.c` files containing a code to test, a `spam.c` file containing project functions to mock, and a `foobar_test.cc` file containing the tests. To build your test executable:
187187

188-
1. Compile a code under test.
188+
1. Compile the code to test.
189189

190190
```sh
191-
cc -c -fPIC foo.c -o foo.o
192-
cc -c -fPIC bar.c -o bar.o
191+
cc -c foo.c -o foo.o
192+
cc -c bar.c -o bar.o
193193
```
194194

195195
Note that C-Mock does not require a code under test to be compiled with a C++ compiler. In the example above, a code under a test is compiled with a C compiler and the tests themselves are compiled with a C++ compiler.
196196

197-
2. Build a shared library containing a code under test.
197+
2. Build a shared library containing project functions to mock.
198198

199199
```sh
200-
cc -shared -Wl,-soname,$(pwd)/libfoobar.so -o libfoobar.so foo.o bar.o
200+
cc -c -fPIC spam.c -o spam.o
201+
cc -shared -Wl,-soname,$(pwd)/libspam.so -o libspam.so spam.o
201202
```
202203

203-
When building code under test as a dynamic library it is handy to specify *soname* as an absolute pathname. Then when the test executable is run no additional environment setup is required for the dynamic linking loader to locate your library (i.e. setting `LD_LIBRARY_PATH`).
204+
In general, this step is optional if the functions to mock are already provided by a dynamic library (i.e. third-party library).
205+
206+
When building a dynamic library it is handy to specify *soname* as an absolute pathname. Then when the test executable is run no additional environment setup is required for the dynamic linking loader to locate your library (i.e. setting `LD_LIBRARY_PATH`).
204207

205208
3. Compile the tests.
206209

@@ -209,11 +212,13 @@ Suppose you have `foo.c` and `bar.c` files containing a code under a test and a
209212
```
210213

211214
4. Build a test executable.
212-
215+
213216
```sh
214-
g++ `cmock-config --libs` -pthread -lfoobar foobar_test.o -o foobar_test # Google Test requires -pthread
217+
g++ `cmock-config --libs` -pthread -lspam foobar_test.o foo.o bar.o -o foobar_test
215218
```
216219

220+
Google Test requires -pthread.
221+
217222
Installation
218223
------------
219224

0 commit comments

Comments
 (0)