lpabon / cmockery2 Goto Github PK
View Code? Open in Web Editor NEWReviving cmockery unit test framework from Google
License: Apache License 2.0
Reviving cmockery unit test framework from Google
License: Apache License 2.0
Interestingly, running "make install" with cmockery2 v1.3.8 works on OSX.
However, doing the same thing with git master barfs:
==> make install
./install-sh -c -d '/usr/lib'
./install-sh -c -d '/usr/include/cmockery'
/bin/sh ./libtool --mode=install /usr/bin/install -c libcmockery.la '/usr/lib'
/usr/bin/install -c -m 644 src/cmockery/cmockery_override.h src/cmockery/cmockery.h src/cmockery/pbc.h '/usr/include/cmockery'
install: /usr/include/cmockery/cmockery_override.h: Permission denied
make[1]: *** [install-cmockeryincludeHEADERS] Error 71
make[1]: *** Waiting for unfinished jobs....
libtool: install: /usr/bin/install -c .libs/libcmockery.0.dylib /usr/lib/libcmockery.0.dylib
install: /usr/lib/libcmockery.0.dylib: Permission denied
make[1]: *** [install-libLTLIBRARIES] Error 71
make: *** [install-am] Error 2
==> Configuration
HOMEBREW_VERSION: 0.9.5
HEAD: b70e6cad88af252c6b3d987fafb21a25d6bd35a5
CPU: dual-core 64-bit penryn
OS X: 10.8.5-x86_64
Xcode: 5.1.1
CLT: 5.1.0.0.1.1396320587
X11: N/A
==> ENV
HOMEBREW_CC: clang
HOMEBREW_CXX: clang++
MAKEFLAGS: -j2
CMAKE_PREFIX_PATH: /usr/local
CMAKE_INCLUDE_PATH: /usr/include/libxml2:/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers
CMAKE_LIBRARY_PATH: /System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries
PKG_CONFIG_LIBDIR: /usr/lib/pkgconfig:/usr/local/Library/ENV/pkgconfig/10.8
ACLOCAL_PATH: /usr/local/share/aclocal
PATH: /usr/local/Library/ENV/4.3:/usr/local/opt/automake/bin:/usr/local/opt/autoconf/bin:/usr/local/opt/libtool/bin:/usr/bin:/bin:/usr/sbin:/sbin
Error: cmockery2 HEAD did not build
Logs:
/Users/harsha/Library/Logs/Homebrew/cmockery2/01.autogen.sh
/Users/harsha/Library/Logs/Homebrew/cmockery2/02.configure
/Users/harsha/Library/Logs/Homebrew/cmockery2/02.configure.cc
/Users/harsha/Library/Logs/Homebrew/cmockery2/03.make
/Users/harsha/Library/Logs/Homebrew/cmockery2/03.make.cc
/Users/harsha/Library/Logs/Homebrew/cmockery2/04.make
/Users/harsha/Library/Logs/Homebrew/cmockery2/config.log
$
Any ideas?
It looks like the Fedora RPMs are being built with coverage enabled. This causes program to output the following warning when run:
profiling:/builddir:Cannot create directory
profiling:/builddir/build/BUILD/cmockery2-1.3.7/.libs/libcmockery_la-cmockery.gcda:Skip
With the sonar-cxx plugin (Community C++) we can get test reports inside SonarQube.
This works pretty well as long as you don't try to get more than metrics by using the sonar.cxx.xunit.provideDetails=True configuration. Keeping it basic will still give you number of failed/successful tests but that's pretty much it.
However, it would be pretty easy to add support for more than metrics, as explained here:
https://github.com/wenns/sonar-cxx/wiki/Get-test-execution-metrics
We only need to add a filename attribute to each testcase tag in the XML file.
I would have tried contributing myself to cmockery2... It seems we only need to add an extra attribute of type SourceLocation to the XunitTestCase structure but I cannot figure out where/how to obtain this information during the execution of a test case.
Correct me if I'm wrong, but there are no way currently to tie together the SourceLocation of a XUnitTestCase, right?
need to update distinfo to 1.3.9 release
I noticed that cmockery2 is in fedora but not Debian. Are there any plans to get the package to Debian? I would be willing to sponsor/help get it into Debian
CFakeLib is not a new unit testing framework. However, we could add this library to any existing framework(e.g. cmockery) to enhance the testing capability.
It mainly provide a solution about how to fake one func with another mock(i.e. stub func) during runtime.
With the library, the mock(stub func) may has any name and could be built with original func. And The stub func could be different for a same func in different case, i.e. dynamic stub.
Would you like to add the library or link it?
Thank you in advance!
Show that cmockery2 can now be installed using yum on centos and Fedora.
hi,
i do not know how to raise a question for help using cmockery2 in github, so i raise the question here. if it is not proper, please forgive me.
in my test, i wan to test that funa indeed called funcb successfully. i meet a puzzle in my test , the souce code(func.c test.c) is as follow:
//func.c
void funcb(int para)
{
para = para+10;
printf("real funcb\n");
}
void funca()
{
int msg = 10;
funcb(msg);
}
//test.c
//#include
//#define UNIT_TESTING 1
//#if UNIT_TESTING
//#include "cmockery_override.h"
//#endif
//#include
extern void funca();
//extern static void funcb(int para);
//mock funcb
static void funcb(int para)
{
printf("*************");
check_expected(para);
}
//test
void test_funca(void ** state)
{
expect_value(funcb, para, 10);
funca();
}
int main()
{
const UnitTest tests[]={unit_test(test_funca)};
return run_tests(tests,"report");
}
i want to test funca. when i run test, i found funca in test.c called the funcb in funcc.c, but not the mock funb. why?
thank you very much.
Document how to create a simple test using cmockery
Could be very interesting to add coveralls.io support to this repo.
You can use my repo Kerrigan29a/lua (look at .travis.yml) as example. It's very easy to use.
Hi @lpabon ,
Just noticed (and wanted to inform you) that there's been a little bit of activity over the last few years on the original Google repo.... The link on your markdown for the original google source (from code.google.com) now redirects to Google's github account here => https://github.com/google/cmockery.
I even noticed an issue I've reported was also reported against Google's repo ;-)
FYI...
When compiling on Windows, we use MinGW32, which compiles a 32-bit executable.
As such, the type "size_t" is 32-bit wide even thought the largest type supported (uintmax_t) is 64-bit wide.
So whenever we call "will_return" or "assert_int_equal" and similar macros, we cannot pass a 64-bit value as it gets stripped down to 32-bit by the first cast to size_t. I've copied the culprit macro below, notice the double casting happening there.
// Perform an unsigned cast to uintmax_t.
#define cast_to_largest_integral_type(value) \
((uintmax_t)((size_t)(value)))
We've thus far circumvented the problem by creating a local "cmockery.h" file with the following content:
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include_next "cmockery.h"
/* Needed because original function "will_return" does a call to cast_to_largest_integral_type(),
* which strips the upper 32-bits of a 64-bit integer. This happens because there is an intermediate
* cast using size_t
*/
#define will_return64(function, value) \
_will_return(#function, __FILE__, __LINE__, \
value, 1)
/* Needed because original function "assert_int_equal" does some call to cast_to_largest_integral_type(),
* which strips the upper 32-bits of a 64-bit integer. This happens because there is an intermediate
* cast using size_t
*/
#define assert_int_equal64(a, b) \
_assert_int_equal((uintmax_t) a, (uintmax_t) b, __FILE__, __LINE__)
The expect_check() and expect_in_set() don't work. They fail even when given the correct expected data.
Following is a patch that fixes both functions:
diff --git a/src/cmockery.c b/src/cmockery.c
index d651e9b..ca6d8b6 100755
--- a/src/cmockery.c
+++ b/src/cmockery.c
@@ -972,6 +972,7 @@ static void expect_set(
assert_true(number_of_values);
memcpy(set, values, number_of_values * sizeof(values[0]));
check_integer_set->set = set;
check_integer_set->size_of_set = number_of_values;
_expect_check(
function, parameter, file, line, check_function,
check_data.value, &check_integer_set->event, count);
diff --git a/src/cmockery/cmockery.h b/src/cmockery/cmockery.h
index 8354668..0de41f5 100755
--- a/src/cmockery/cmockery.h
+++ b/src/cmockery/cmockery.h
@@ -140,7 +140,7 @@ cast_to_largest_integral_type(cast_to_pointer_integral_type(value))
*/
#define expect_check(function, parameter, check_function, check_data)
_expect_check(#function, #parameter, FILE, LINE, check_function, \
cast_to_largest_integral_type(check_data), NULL, 0)
cast_to_largest_integral_type(check_data), NULL, 1)
/* Add an event to check a parameter, using check_expected(), against a set of
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.