mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-23 14:00:33 +00:00
Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 677d02e43e | |||
| 168da7c418 | |||
| fbcffe65a3 | |||
| f1789ba633 | |||
| 392a5537d9 | |||
| bfdfe944b9 | |||
| 07d6714fe2 | |||
| 2af7c7de43 | |||
| abd526d585 | |||
| dfc1955c51 | |||
| 1939bbe666 | |||
| dcd6fe44af | |||
| 8b73bf3835 | |||
| 648f3960ff | |||
| f4f149792f | |||
| b666bf05c1 | |||
| a139775672 | |||
| 660c342fc6 | |||
| 1bb97ff2a8 | |||
| d2fc813b51 | |||
| a182e33a9a | |||
| dd791fe407 | |||
| 06b9f23054 | |||
| 9be03c215a | |||
| ebf4ae274a | |||
| a55efdba19 | |||
| 42a937a097 | |||
| 9e49bace32 | |||
| eddfb75d59 | |||
| 39e99e9803 | |||
| 30064aa63c | |||
| c719dff1ad | |||
| dda0351471 | |||
| 29541c1e46 | |||
| 8c8c2a2292 | |||
| 29c1d07f25 | |||
| be70af1297 | |||
| cfe52ba90f | |||
| b0264f68f4 | |||
| 242fd73d3e | |||
| d59ec41c52 | |||
| 52e89e9507 |
+23
-2
@@ -1,8 +1,29 @@
|
||||
language: ruby
|
||||
|
||||
os:
|
||||
- osx
|
||||
- linux
|
||||
|
||||
rvm:
|
||||
- "1.9.3"
|
||||
- "2.0.0"
|
||||
- "2.2.2"
|
||||
|
||||
before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.1 && rvm use 2.1 && ruby -v; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi
|
||||
|
||||
install:
|
||||
- bundle install
|
||||
- gem install rspec
|
||||
- gem install rubocop
|
||||
|
||||
script:
|
||||
- bundle exec rake ci
|
||||
- cd test && rake ci
|
||||
- cd ..
|
||||
- cd examples && cd make_example
|
||||
- make clean
|
||||
- make setup
|
||||
- make test
|
||||
- cd ..
|
||||
- cd temp_sensor
|
||||
- rake ci
|
||||
|
||||
@@ -6,10 +6,19 @@ CMock - Mock/stub generator for C
|
||||
Getting Started
|
||||
================
|
||||
|
||||
If you're using Ceedling, there is no need to install CMock. It will handle it for you.
|
||||
For everyone else, the simplest way is to grab it off github. You can also download it
|
||||
as a zip if you prefer. The Github method looks something like this:
|
||||
|
||||
> git clone --recursive https://github.com/throwtheswitch/cmock.git
|
||||
> cd cmock
|
||||
> bundle install # Ensures you have all RubyGems needed
|
||||
> bundle exec rake # Run all CMock library tests
|
||||
|
||||
If you plan to help with the development of CMock (or just want to verify that it can
|
||||
perform its self tests on your system) then you can enter the test directory and then
|
||||
ask it to test:
|
||||
|
||||
> rake # Run all CMock self tests
|
||||
|
||||
API Documentation
|
||||
=================
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
# ==========================================
|
||||
|
||||
# Setup our load path:
|
||||
[
|
||||
'lib',
|
||||
'vendor/behaviors/lib',
|
||||
'vendor/hardmock/lib',
|
||||
'vendor/unity/auto/',
|
||||
'test/system/'
|
||||
[
|
||||
'./lib',
|
||||
'./vendor/behaviors/lib',
|
||||
'./vendor/hardmock/lib',
|
||||
'./vendor/unity/auto/',
|
||||
'./test/system/'
|
||||
].each do |dir|
|
||||
$LOAD_PATH.unshift( File.join( File.expand_path(File.dirname(__FILE__) + "/../"), dir) )
|
||||
end
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+317
-120
@@ -1,15 +1,16 @@
|
||||
[All code is copyright © 2007-2014 Cmock Project
|
||||
by Mike Karlesky, Mark VanderVoord, and Greg Williams.
|
||||
CMock: A Summary
|
||||
================
|
||||
|
||||
This Documentation Is Released Under a Creative Commons 3.0
|
||||
Attribution Share-Alike License]
|
||||
*[ThrowTheSwitch.org](http://throwtheswitch.org)*
|
||||
|
||||
*This documentation is released under a Creative Commons 3.0 Attribution Share-Alike License*
|
||||
|
||||
|
||||
What the What?
|
||||
==============
|
||||
What Exactly Are We Talking About Here?
|
||||
---------------------------------------
|
||||
|
||||
CMock is a nice little tool which takes your header files and creates
|
||||
a Mock interface for it so that you can more easily Unit test modules
|
||||
a Mock interface for it so that you can more easily unit test modules
|
||||
that touch other modules. For each function prototype in your
|
||||
header, like this one:
|
||||
|
||||
@@ -60,7 +61,29 @@ call DoesSomething enough, or too much, or with the wrong arguments,
|
||||
or in the wrong order.
|
||||
|
||||
CMock is based on Unity, which it uses for all internal testing.
|
||||
It uses Ruby to do all the main work (versions 1.8.6 through 1.9.2).
|
||||
It uses Ruby to do all the main work (versions 2.0.0 and above).
|
||||
|
||||
|
||||
Installing
|
||||
==========
|
||||
|
||||
The first thing you need to do to install CMock is to get yourself
|
||||
a copy of Ruby. If you're on linux or osx, you probably already
|
||||
have it. You can prove it by typing the following:
|
||||
|
||||
ruby --version
|
||||
|
||||
|
||||
If it replied in a way that implies ignorance, then you're going to
|
||||
need to install it. You can go to [ruby-lang](https://ruby-lang.org)
|
||||
to get the latest version. You're also going to need to do that if it
|
||||
replied with a version that is older than 2.0.0. Go ahead. We'll wait.
|
||||
|
||||
Once you have Ruby, you have three options:
|
||||
|
||||
* Clone the latest [CMock repo on github](https://github.com/ThrowTheSwitch/CMock/)
|
||||
* Download the latest [CMock zip from github](https://github.com/ThrowTheSwitch/CMock/)
|
||||
* Install Ceedling (which has it built in!) through your commandline using `gem install ceedling`.
|
||||
|
||||
|
||||
Generated Mock Module Summary
|
||||
@@ -76,7 +99,11 @@ Expect:
|
||||
-------
|
||||
|
||||
Your basic staple Expects which will be used for most of your day
|
||||
to day CMock work.
|
||||
to day CMock work. By calling this, you are telling CMock that you
|
||||
expect that function to be called during your test. It also specifies
|
||||
which arguments you expect it to be called with, and what return
|
||||
value you want returned when that happens. You can call this function
|
||||
multiple times back to back in order to queue up multiple calls.
|
||||
|
||||
* `void func(void)` => `void func_Expect(void)`
|
||||
* `void func(params)` => `void func_Expect(expected_params)`
|
||||
@@ -84,10 +111,30 @@ to day CMock work.
|
||||
* `retval func(params)` => `void func_ExpectAndReturn(expected_params, retval_to_return)`
|
||||
|
||||
|
||||
ExpectAnyArgs:
|
||||
--------------
|
||||
|
||||
This behaves just like the Expects calls, except that it doesn't really
|
||||
care what the arguments are that the mock gets called with. It still counts
|
||||
the number of times the mock is called and it still handles return values
|
||||
if there are some.
|
||||
|
||||
* `void func(void)` => `void func_ExpectAnyArgs(void)`
|
||||
* `void func(params)` => `void func_ExpectAnyArgs(void)`
|
||||
* `retval func(void)` => `void func_ExpectAnyArgsAndReturn(retval_to_return)`
|
||||
* `retval func(params)` => `void func_ExpectAnyArgsAndReturn(retval_to_return)`
|
||||
|
||||
|
||||
Array:
|
||||
------
|
||||
|
||||
An ExpectWithArray will check as many elements as you specify.
|
||||
An ExpectWithArray is another variant of Expect. Like expect, it cares about
|
||||
the number of times a mock is called, the arguments it is called with, and the
|
||||
values it is to return. This variant has another feature, though. For anything
|
||||
that resembles a pointer or array, it breaks the argument into TWO arguments.
|
||||
The first is the original pointer. The second specify the number of elements
|
||||
it is to verify of that array. If you specify 1, it'll check one object. If 2,
|
||||
it'll assume your pointer is pointing at the first of two elements in an array.
|
||||
If you specify zero elements, it will check just the pointer if
|
||||
`:smart` mode is configured or fail if `:compare_data` is set.
|
||||
|
||||
@@ -97,14 +144,59 @@ If you specify zero elements, it will check just the pointer if
|
||||
* `retval func(other, ptr* param)` => `void func_ExpectWithArrayAndReturn(other, ptr* param, int param_depth, retval_to_return)`
|
||||
|
||||
|
||||
Ignore:
|
||||
-------
|
||||
|
||||
Maybe you don't care about the number of times a particular function is called or
|
||||
the actual arguments it is called with. In that case, you want to use Ignore. Ignore
|
||||
only needs to be called once per test. It will then ignore any further calls to that
|
||||
particular mock. The IgnoreAndReturn works similarly, except that it has the added
|
||||
benefit of knowing what to return when that call happens. If the mock is called more
|
||||
times than IgnoreAndReturn was called, it will keep returning the last value without
|
||||
complaint. If it's called less times, it will also ignore that. You SAID you didn't
|
||||
care how many times it was called, right?
|
||||
|
||||
* `void func(void)` => `void func_Ignore(void)`
|
||||
* `void func(params)` => `void func_Ignore(void)`
|
||||
* `retval func(void)` => `void func_IgnoreAndReturn(retval_to_return)`
|
||||
* `retval func(params)` => `void func_IgnoreAndReturn(retval_to_return)`
|
||||
|
||||
|
||||
Ignore Arg:
|
||||
------------
|
||||
|
||||
Maybe you overall want to use Expect and its similar variations, but you don't care
|
||||
what is passed to a particular argument. This is particularly useful when that argument
|
||||
is a pointer to a value that is supposed to be filled in by the function. You don't want
|
||||
to use ExpectAnyArgs, because you still care about the other arguments. Instead, before
|
||||
any of your Expect calls are made, you can call this function. It tells CMock to ignore
|
||||
a particular argument for the rest of this test, for this mock function.
|
||||
|
||||
* `void func(params)` => `void func_IgnoreArg_paramName(void)`
|
||||
|
||||
|
||||
ReturnThruPtr:
|
||||
--------------
|
||||
|
||||
Another option which operates on a particular argument of a function is the ReturnThruPtr
|
||||
plugin. For every argument that resembles a pointer or reference, CMock generates an
|
||||
instance of this function. Just as the AndReturn functions support injecting one or more
|
||||
return values into a queue, this function lets you specify one or more return values which
|
||||
are queued up and copied into the space being pointed at each time the mock is called.
|
||||
|
||||
* `void func(param1)` => `void func_ReturnThruPtr_paramName(val_to_return)`
|
||||
* => `void func_ReturnArrayThruPtr_paramName(cal_to_return, len)`
|
||||
* => `void func_ReturnMemThruPtr_paramName(val_to_return, size)`
|
||||
|
||||
|
||||
Callback:
|
||||
---------
|
||||
|
||||
As soon as you stub a callback in a test, it will call the callback
|
||||
whenever the mock is encountered and return the retval returned
|
||||
from the callback (if any) instead of performing the usual expect
|
||||
checks. It can be configured to check the arguments first (like
|
||||
expects) or just jump directly to the callback.
|
||||
If all those other options don't work, and you really need to do something custom, you
|
||||
still have a choice. As soon as you stub a callback in a test, it will call the callback
|
||||
whenever the mock is encountered and return the retval returned from the callback (if any)
|
||||
instead of performing the usual expect checks. It can be configured to check the arguments
|
||||
first (like expects) or just jump directly to the callback.
|
||||
|
||||
* `void func(void)` => `void func_StubWithCallback(CMOCK_func_CALLBACK callback)`
|
||||
where `CMOCK_func_CALLBACK` looks like: `void func(int NumCalls)`
|
||||
@@ -119,10 +211,9 @@ where `CMOCK_func_CALLBACK` looks like: `retval func(params, int NumCalls)`
|
||||
Cexception:
|
||||
-----------
|
||||
|
||||
If you are using Cexception for error handling, you can use this
|
||||
to throw errors from inside mocks. Like Expects, it remembers
|
||||
which call was supposed to throw the error, and it still checks
|
||||
parameters.
|
||||
Finally, if you are using Cexception for error handling, you can use this to throw errors
|
||||
from inside mocks. Like Expects, it remembers which call was supposed to throw the error,
|
||||
and it still checks parameters first.
|
||||
|
||||
* `void func(void)` => `void func_ExpectAndThrow(value_to_throw)`
|
||||
* `void func(params)` => `void func_ExpectAndThrow(expected_params, value_to_throw)`
|
||||
@@ -130,43 +221,6 @@ parameters.
|
||||
* `retval func(params)` => `void func_ExpectAndThrow(expected_params, value_to_throw)`
|
||||
|
||||
|
||||
Ignore:
|
||||
-------
|
||||
|
||||
This plugin supports two modes. You can use it to force CMock to
|
||||
ignore calls to specific functions or to just ignore the arguments
|
||||
passed to those functions. Either way you can specify multiple
|
||||
returns or a single value to always return, whichever you prefer.
|
||||
|
||||
* `void func(void)` => `void func_Ignore(void)`
|
||||
* `void func(params)` => `void func_Ignore(void)`
|
||||
* `retval func(void)` => `void func_IgnoreAndReturn(retval_to_return)`
|
||||
* `retval func(params)` => `void func_IgnoreAndReturn(retval_to_return)`
|
||||
|
||||
|
||||
Ignore Args:
|
||||
------------
|
||||
|
||||
This plugin adds the ability to specify specifc arguments to ignore
|
||||
for a function, instead of ignoring all the arguments or the entire
|
||||
function call, as the Ignore plugin supports. This will create a function
|
||||
for each argument and each function.
|
||||
|
||||
* `void func(params)` => `void func_IgnoreArg_paramName(void)`
|
||||
|
||||
|
||||
ReturnThruPtr:
|
||||
--------------
|
||||
|
||||
This plugin adds a number of options for returning data through arguments
|
||||
that are pointers. This is fled separately from the Expect/Ignore call, so
|
||||
you will want to issue one of those calls each time as well. This will only
|
||||
create an extra call for arguments that are pointers. It will create one per
|
||||
pointer argument.
|
||||
|
||||
* `void func(param1)` => `void func_ReturnThruPtr_paramName(val_to_return)`
|
||||
* => `void func_ReturnArrayThruPtr_paramName(cal_to_return, len)`
|
||||
* => `void func_ReturnMemThruPtr_paramName(val_to_return, size)`
|
||||
|
||||
Running CMock
|
||||
=============
|
||||
@@ -174,10 +228,11 @@ Running CMock
|
||||
CMock is a Ruby script and class. You can therefore use it directly
|
||||
from the command line, or include it in your own scripts or rakefiles.
|
||||
|
||||
|
||||
Mocking from the Command Line
|
||||
-----------------------------
|
||||
|
||||
After unpacking CMock, you will find CMock.rb in the 'lib' directory.
|
||||
After unpacking CMock, you will find cmock.rb in the 'lib' directory.
|
||||
This is the file that you want to run. It takes a list of header files
|
||||
to be mocked, as well as an optional yaml file for a more detailed
|
||||
configuration (see config options below).
|
||||
@@ -191,6 +246,7 @@ And this will create two mocks using the default configuration:
|
||||
|
||||
ruby cmock.rb ../mocking/stuff/is/fun.h ../try/it/yourself.h
|
||||
|
||||
|
||||
Mocking From Scripts or Rake
|
||||
----------------------------
|
||||
|
||||
@@ -201,6 +257,7 @@ three ways.
|
||||
|
||||
You may specify nothing, allowing it to run with default settings:
|
||||
|
||||
require 'cmock.rb'
|
||||
cmock = CMock.new
|
||||
|
||||
You may specify a YAML file containing the configuration options
|
||||
@@ -212,7 +269,9 @@ You may specify the options explicitly:
|
||||
|
||||
cmock = Cmock.new(:plugins => [:cexception, :ignore], :mock_path => 'my/mocks/')
|
||||
|
||||
|
||||
Config Options:
|
||||
---------------
|
||||
|
||||
The following configuration options can be specified in the
|
||||
yaml file or directly when instantiating.
|
||||
@@ -229,81 +288,141 @@ Defined in the yaml file, they look more like this:
|
||||
- __intrinsic
|
||||
:when_ptr: :compare
|
||||
|
||||
In all cases, you can just include the things that you want to override
|
||||
from the defaults. We've tried to specify what the defaults are below.
|
||||
|
||||
* `:attributes`:
|
||||
These are attributes that CMock should ignore for you for testing
|
||||
purposes. Custom compiler extensions and externs are handy things to
|
||||
put here.
|
||||
put here. If your compiler is choking on some extended syntax, this
|
||||
is often a good place to look.
|
||||
|
||||
* defaults: ['__ramfunc', '__irq', '__fiq', 'register', 'extern']
|
||||
* **note:** this option will reinsert these attributes onto the mock's calls.
|
||||
If that isn't what you are looking for, check out :strippables.
|
||||
|
||||
* `:c_calling_conventions`:
|
||||
Similarly, CMock may need to understand which C calling conventions
|
||||
might show up in your codebase. If it encounters something it doesn't
|
||||
recognize, it's not going to mock it. We have the most common covered,
|
||||
but there are many compilers out there, and therefore many other options.
|
||||
|
||||
* defaults: ['__stdcall', '__cdecl', '__fastcall']
|
||||
* **note:** this option will reinsert these attributes onto the mock's calls.
|
||||
If that isn't what you are looking for, check out :strippables.
|
||||
|
||||
* `:callback_after_arg_check`:
|
||||
Tell `:callback` plugin to do the normal argument checking before it
|
||||
calls the callback function. This defaults to false, where the
|
||||
callback function is called instead of the argument verification.
|
||||
Tell `:callback` plugin to do the normal argument checking **before** it
|
||||
calls the callback function by setting this to true. WHen false, the
|
||||
callback function is called **instead** of the argument verification.
|
||||
|
||||
* default: false
|
||||
|
||||
* `:callback_include_count`:
|
||||
Tell `:callback` plugin to include an extra parameter to specify the
|
||||
number of times the callback has been called. If set to false, the
|
||||
callback has the same interface as the mocked function. This can be
|
||||
handy when you're wanting to use callback as a stub.
|
||||
|
||||
* default: true
|
||||
|
||||
* `:cexception_include`:
|
||||
Tell `:cexception` plugin where to find CException.h... only need to
|
||||
define if it's not in your build path already.
|
||||
Tell `:cexception` plugin where to find CException.h... You only need to
|
||||
define this if it's not in your build path already... which it usually
|
||||
will be for the purpose of your builds.
|
||||
|
||||
* default: *nil*
|
||||
|
||||
* `:enforce_strict_ordering`:
|
||||
CMock always enforces the order that you call a particular function,
|
||||
so if you expect GrabNabber(int size) to be called three times, it
|
||||
will verify that the sizes are in the order you specified. You might
|
||||
also want to make sure that all different functions are called in a
|
||||
*also* want to make sure that all different functions are called in a
|
||||
particular order. If so, set this to true.
|
||||
|
||||
* default: false
|
||||
|
||||
* `:framework`:
|
||||
Currently the only option is `:unity.` Eventually if we support other
|
||||
unity test frameworks (or if you write one for us), they'll get added
|
||||
here.
|
||||
|
||||
: default: :unity
|
||||
|
||||
* `:includes`:
|
||||
An array of additional include files which should be added to the
|
||||
mocks. Useful for global types and definitions used in your project.
|
||||
There are more specific versions if you care WHERE in the mock files
|
||||
the includes get placed. You can define any or all of
|
||||
`:includes_h_pre_orig_header,` `:includes_h_post_orig_header, `
|
||||
`:includes_c_pre_header,` `:includes_c_post_header
|
||||
the includes get placed. You can define any or all of these options.
|
||||
|
||||
* `:includes`
|
||||
* `:includes_h_pre_orig_header`
|
||||
* `:includes_h_post_orig_header`
|
||||
* `:includes_c_pre_header`
|
||||
* `:includes_c_post_header`
|
||||
* default: nil #for all 5 options
|
||||
|
||||
* `:memcmp_if_unknown`:
|
||||
This is true by default. When true, CMock will just do a memory
|
||||
comparison of types that it doesn't recognize (not standard types, not
|
||||
in `:treat_as,` and not in a unity helper). If you instead want it to
|
||||
throw an error, just set this to false.
|
||||
C developers create a lot of types, either through typedef or preprocessor
|
||||
macros. CMock isn't going to automatically know what you were thinking all
|
||||
the time (though it tries its best). If it comes across a type it doesn't
|
||||
recognize, you have a choice on how you want it to handle it. It can either
|
||||
perform a raw memory comparison and report any differences, or it can fail
|
||||
with a meaningful message. Either way, this feature will only happen after
|
||||
all other mechanisms have failed (The thing encountered isn't a standard
|
||||
type. It isn't in the :treat_as list. It isn't in a custom unity_helper).
|
||||
|
||||
* default: true
|
||||
|
||||
* `:mock_path`:
|
||||
The directory where you would like the mock files generated to be
|
||||
placed.
|
||||
|
||||
* default: mocks
|
||||
|
||||
* `:mock_prefix`:
|
||||
The prefix to append to your mock files. Defaults to “Mock”, so a file
|
||||
“USART.h” will get a mock called “MockUSART.c”
|
||||
The prefix to prepend to your mock files. For example, if it's “Mock”, a file
|
||||
“USART.h” will get a mock called “MockUSART.c”. This CAN be used with a suffix
|
||||
at the same time.
|
||||
|
||||
* default: Mock
|
||||
|
||||
* `:mock_suffix`:
|
||||
The suffix to append to your mock files. Defaults to “”.
|
||||
|
||||
* `:weak`:
|
||||
When set to some value, the generated mocks are defined as weak symbols using the configured format. Defaults to ''.
|
||||
Set to '__attribute ((weak))' for weak mocks when using GCC. Set to any non-empty string for weak mocks when using IAR.
|
||||
|
||||
* `:subdir`:
|
||||
Relative subdir for your mocks. Set this to e.g. "sys" in order to
|
||||
create mock for `sys/types.h` in `:mock_path`/sys/
|
||||
The suffix to append to your mock files. For example, it it's "_Mock", a file
|
||||
"USART.h" will get a mock called "USART_Mock.h". This CAN be used with a prefix
|
||||
at the same time.
|
||||
|
||||
* default: ""
|
||||
|
||||
* `:plugins`:
|
||||
An array of which plugins to enable. 'expect' is always active. Also
|
||||
available currently are `:ignore,` `:ignore_arg,` `:array,`
|
||||
`:cexception,` `:callback,` and `:return_thru_ptr`
|
||||
An array of which plugins to enable. ':expect' is always active. Also
|
||||
available currently:
|
||||
|
||||
* `:ignore`
|
||||
* `:ignore_arg`
|
||||
* `:expect_any_args`
|
||||
* `:array`
|
||||
* `:cexception`
|
||||
* `:callback`
|
||||
* `:return_thru_ptr`
|
||||
|
||||
* `:strippables`:
|
||||
An array containing a list of items to remove from the mocked header.
|
||||
For example, use `:strippables: ['(?:functionName\s*\(+.*?\)+)']`
|
||||
to prevent a function from being mocked.
|
||||
An array containing a list of items to remove from the header
|
||||
before deciding what should be mocked. This can be something simple
|
||||
like a compiler extension CMock wouldn't recognize, or could be a
|
||||
regex to reject certain function name patterns. This is a great way to
|
||||
get rid of compiler extensions when your test compiler doesn't support
|
||||
them. For example, use `:strippables: ['(?:functionName\s*\(+.*?\)+)']`
|
||||
to prevent a function `functionName` from being mocked. By default, it
|
||||
is ignoring all gcc attribute extensions.
|
||||
|
||||
* default: ['(?:__attribute__\s*\(+.*?\)+)']
|
||||
|
||||
* `:subdir`:
|
||||
This is a relative subdirectory for your mocks. Set this to e.g. "sys" in
|
||||
order to create a mock for `sys/types.h` in `(:mock_path)/sys/`.
|
||||
|
||||
* default: ""
|
||||
|
||||
* `:treat_as`:
|
||||
The `:treat_as` list is a shortcut for when you have created typedefs
|
||||
@@ -313,36 +432,105 @@ Defined in the yaml file, they look more like this:
|
||||
did that one for you). Maybe you have a type that is a pointer to an
|
||||
array of unsigned characters? No problem, just add 'UINT8_T*' =>
|
||||
'HEX8*'
|
||||
|
||||
* NOTE: unlike the other options, your specifications MERGE with the
|
||||
default list. Therefore, if you want to override something, you must
|
||||
reassign it to something else (or to *nil* if you don't want it)
|
||||
|
||||
* default:
|
||||
* 'int': 'INT'
|
||||
* 'char': 'INT8'
|
||||
* 'short': 'INT16'
|
||||
* 'long': 'INT'
|
||||
* 'int8': 'INT8'
|
||||
* 'int16': 'INT16'
|
||||
* 'int32': 'INT'
|
||||
* 'int8_t': 'INT8'
|
||||
* 'int16_t': 'INT16'
|
||||
* 'int32_t': 'INT'
|
||||
* 'INT8_T': 'INT8'
|
||||
* 'INT16_T': 'INT16'
|
||||
* 'INT32_T': 'INT'
|
||||
* 'bool': 'INT'
|
||||
* 'bool_t': 'INT'
|
||||
* 'BOOL': 'INT'
|
||||
* 'BOOL_T': 'INT'
|
||||
* 'unsigned int': 'HEX32'
|
||||
* 'unsigned long': 'HEX32'
|
||||
* 'uint32': 'HEX32'
|
||||
* 'uint32_t': 'HEX32'
|
||||
* 'UINT32': 'HEX32'
|
||||
* 'UINT32_T': 'HEX32'
|
||||
* 'void*': 'HEX8_ARRAY'
|
||||
* 'unsigned short': 'HEX16'
|
||||
* 'uint16': 'HEX16'
|
||||
* 'uint16_t': 'HEX16'
|
||||
* 'UINT16': 'HEX16'
|
||||
* 'UINT16_T': 'HEX16'
|
||||
* 'unsigned char': 'HEX8'
|
||||
* 'uint8': 'HEX8'
|
||||
* 'uint8_t': 'HEX8'
|
||||
* 'UINT8': 'HEX8'
|
||||
* 'UINT8_T': 'HEX8'
|
||||
* 'char*': 'STRING'
|
||||
* 'pCHAR': 'STRING'
|
||||
* 'cstring': 'STRING'
|
||||
* 'CSTRING': 'STRING'
|
||||
* 'float': 'FLOAT'
|
||||
* 'double': 'FLOAT'
|
||||
|
||||
* `:treat_as_void`:
|
||||
We've seen "fun" legacy systems typedef 'void' with a custom type,
|
||||
like MY_VOID. Add any instances of those to this list to help CMock
|
||||
understand how to deal with your code.
|
||||
|
||||
* default: []
|
||||
|
||||
* `:treat_externs`:
|
||||
Set to `:include` to mock externed functions or `:exclude` to ignore
|
||||
them (the default).
|
||||
This specifies how you want CMock to handle functions that have been
|
||||
marked as extern in the header file. Should it mock them?
|
||||
|
||||
* `:include` will mock externed functions
|
||||
* `:exclude` will ignore externed functions (default).
|
||||
|
||||
* `:unity_helper_path`:
|
||||
If you have created a header with your own extensions to unity to
|
||||
handle your own types, you can set this argument to that path. CMock
|
||||
will then automagically pull in your helpers and use them. The only
|
||||
trick is that you make sure you follow the naming convention:
|
||||
UNITY_TEST_ASSERT_EQUAL_YourType
|
||||
`UNITY_TEST_ASSERT_EQUAL_YourType`. If it finds macros of the right
|
||||
shape that match that pattern, it'll use them.
|
||||
|
||||
* default: []
|
||||
|
||||
* `:verbosity`:
|
||||
0 for errors only. 1 for errors and warnings. 2 for normal. 3 for
|
||||
verbose
|
||||
How loud shoudl CMock be?
|
||||
|
||||
* 0 for errors only
|
||||
* 1 for errors and warnings
|
||||
* 2 for normal (default)
|
||||
* 3 for verbose
|
||||
|
||||
* `:weak`:
|
||||
When set this to some value, the generated mocks are defined as weak
|
||||
symbols using the configured format. This allows them to be overridden
|
||||
in particular tests.
|
||||
|
||||
* Set to '__attribute ((weak))' for weak mocks when using GCC.
|
||||
* Set to any non-empty string for weak mocks when using IAR.
|
||||
* default: ""
|
||||
|
||||
* `:when_no_prototypes`:
|
||||
When you give CMock a header file and ask it to create a mock out of
|
||||
it, it usually contains function prototypes (otherwise what was the
|
||||
point?). You can control what happens when this isn't true. You can
|
||||
set this to `:warn,` `:ignore,` or `:error
|
||||
set this to `:warn,` `:ignore,` or `:error`
|
||||
|
||||
* default: :warn
|
||||
|
||||
* `:when_ptr`:
|
||||
You can customize how CMock deals with pointers (c strings result in
|
||||
string comparisons... we're talking about other pointers here). Your
|
||||
string comparisons... we're talking about **other** pointers here). Your
|
||||
options are `:compare_ptr` to just verify the pointers are the same,
|
||||
`:compare_data` or `:smart` to verify that the data is the same.
|
||||
`:compare_data` and `:smart` behaviors will change slightly based on
|
||||
@@ -350,42 +538,51 @@ Defined in the yaml file, they look more like this:
|
||||
single element of what is being pointed to. So if you have a pointer
|
||||
to a struct called ORGAN_T, it will compare one ORGAN_T (whatever that
|
||||
is).
|
||||
|
||||
* default: :smart
|
||||
|
||||
|
||||
Compiled Options:
|
||||
-----------------
|
||||
|
||||
A number of #defines also exist for customizing the cmock experience.
|
||||
Feel free to pass these into your compiler or whatever is most
|
||||
convenient. CMock will otherwise do its best to guess what you want
|
||||
based on other settings, particularly Unity's settings.
|
||||
|
||||
CMOCK_MEM_STATIC or CMOCK_MEM_DYNAMIC
|
||||
* `CMOCK_MEM_STATIC` or `CMOCK_MEM_DYNAMIC`
|
||||
Define one of these to determine if you want to dynamically add
|
||||
memory during tests as required from the heap. If static, you
|
||||
can control the total footprint of Cmock. If dynamic, you will
|
||||
need to make sure you make some heap space available for Cmock.
|
||||
|
||||
Define one of these to determine if you want to dynamically add
|
||||
memory during tests as required from the heap. If static, you
|
||||
can control the total footprint of Cmock. If dynamic, you will
|
||||
need to make sure you make some heap space available for Cmock.
|
||||
* `CMOCK_MEM_SIZE`
|
||||
In static mode this is the total amount of memory you are allocating
|
||||
to Cmock. In Dynamic mode this is the size of each chunk allocated
|
||||
at once (larger numbers grab more memory but require less mallocs).
|
||||
|
||||
CMOCK_MEM_SIZE
|
||||
* `CMOCK_MEM_ALIGN`
|
||||
The way to align your data to. Not everything is as flexible as
|
||||
a PC, as most embedded designers know. This defaults to 2, meaning
|
||||
align to the closest 2^2 -> 4 bytes (32 bits). You can turn off alignment
|
||||
by setting 0, force alignment to the closest uint16 with 1 or even
|
||||
to the closest uint64 with 3.
|
||||
|
||||
In static mode this is the total amount of memory you are allocating
|
||||
to Cmock. In Dynamic mode this is the size of each chunk allocated
|
||||
at once (larger numbers grab more memory but require less mallocs).
|
||||
* `CMOCK_MEM_PTR_AS_INT`
|
||||
This is used internally to hold pointers... it needs to be big
|
||||
enough. On most processors a pointer is the same as an unsigned
|
||||
long... but maybe that's not true for yours?
|
||||
|
||||
CMOCK_MEM_ALIGN
|
||||
* `CMOCK_MEM_INDEX_TYPE`
|
||||
This needs to be something big enough to point anywhere in Cmock's
|
||||
memory space... usually it's an unsigned int.
|
||||
|
||||
The way to align your data to. Not everything is as flexible as
|
||||
a PC, as most embedded designers know. This defaults to 2, meaning
|
||||
align to the closest 2^2 -> 4 bytes (32 bits). You can turn off alignment
|
||||
by setting 0, force alignment to the closest uint16 with 1 or even
|
||||
to the closest uint64 with 3.
|
||||
Examples
|
||||
========
|
||||
|
||||
CMOCK_MEM_PTR_AS_INT
|
||||
|
||||
This is used internally to hold pointers... it needs to be big
|
||||
enough. On most processors a pointer is the same as an unsigned
|
||||
long... but maybe that's not true for yours?
|
||||
|
||||
CMOCK_MEM_INDEX_TYPE
|
||||
|
||||
This needs to be something big enough to point anywhere in Cmock's
|
||||
memory space... usually it's an unsigned int.
|
||||
You can look in the examples directory for a couple of examples on how
|
||||
you might tool CMock into your build process. You may also want to consider
|
||||
using [Ceedling](https://throwtheswitch.org/Ceedling). Please note that
|
||||
these examples are meant to show how the build process works. They have
|
||||
failing tests ON PURPOSE to show what that would look like. Don't be alarmed. ;)
|
||||
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
# ThrowTheSwitch.org Coding Standard
|
||||
|
||||
Hi. Welcome to the coding standard for ThrowTheSwitch.org. For the most part,
|
||||
we try to follow these standards to unify our contributors' code into a cohesive
|
||||
unit (puns intended). You might find places where these standards aren't
|
||||
followed. We're not perfect. Please be polite where you notice these discrepancies
|
||||
and we'll try to be polite when we notice yours.
|
||||
|
||||
;)
|
||||
|
||||
|
||||
## Why Have A Coding Standard?
|
||||
|
||||
Being consistent makes code easier to understand. We've made an attempt to keep
|
||||
our standard simple because we also believe that we can only expect someone to
|
||||
follow something that is understandable. Please do your best.
|
||||
|
||||
|
||||
## Our Philosophy
|
||||
|
||||
Before we get into details on syntax, let's take a moment to talk about our
|
||||
vision for these tools. We're C developers and embedded software developers.
|
||||
These tools are great to test any C code, but catering to embedded software has
|
||||
made us more tolerant of compiler quirks. There are a LOT of quirky compilers
|
||||
out there. By quirky I mean "doesn't follow standards because they feel like
|
||||
they have a license to do as they wish."
|
||||
|
||||
Our philosophy is "support every compiler we can". Most often, this means that
|
||||
we aim for writing C code that is standards compliant (often C89... that seems
|
||||
to be a sweet spot that is almost always compatible). But it also means these
|
||||
tools are tolerant of things that aren't common. Some that aren't even
|
||||
compliant. There are configuration options to override the size of standard
|
||||
types. There are configuration options to force Unity to not use certain
|
||||
standard library functions. A lot of Unity is configurable and we have worked
|
||||
hard to make it not TOO ugly in the process.
|
||||
|
||||
Similarly, our tools that parse C do their best. They aren't full C parsers
|
||||
(yet) and, even if they were, they would still have to accept non-standard
|
||||
additions like gcc extensions or specifying `@0x1000` to force a variable to
|
||||
compile to a particular location. It's just what we do, because we like
|
||||
everything to Just Work™.
|
||||
|
||||
Speaking of having things Just Work™, that's our second philosophy. By that, we
|
||||
mean that we do our best to have EVERY configuration option have a logical
|
||||
default. We believe that if you're working with a simple compiler and target,
|
||||
you shouldn't need to configure very much... we try to make the tools guess as
|
||||
much as they can, but give the user the power to override it when it's wrong.
|
||||
|
||||
|
||||
## Naming Things
|
||||
|
||||
Let's talk about naming things. Programming is all about naming things. We name
|
||||
files, functions, variables, and so much more. While we're not always going to
|
||||
find the best name for something, we actually put quite a bit of effort into
|
||||
finding *What Something WANTS to be Called*™.
|
||||
|
||||
When naming things, we more or less follow this hierarchy, the first being the
|
||||
most important to us (but we do all four whenever possible):
|
||||
1. Readable
|
||||
2. Descriptive
|
||||
3. Consistent
|
||||
4. Memorable
|
||||
|
||||
|
||||
#### Readable
|
||||
|
||||
We want to read our code. This means we like names and flow that are more
|
||||
naturally read. We try to avoid double negatives. We try to avoid cryptic
|
||||
abbreviations (sticking to ones we feel are common).
|
||||
|
||||
|
||||
#### Descriptive
|
||||
|
||||
We like descriptive names for things, especially functions and variables.
|
||||
Finding the right name for something is an important endeavor. You might notice
|
||||
from poking around our code that this often results in names that are a little
|
||||
longer than the average. Guilty. We're okay with a tiny bit more typing if it
|
||||
means our code is easier to understand.
|
||||
|
||||
There are two exceptions to this rule that we also stick to as religiously as
|
||||
possible:
|
||||
|
||||
First, while we realize hungarian notation (and similar systems for encoding
|
||||
type information into variable names) is providing a more descriptive name, we
|
||||
feel that (for the average developer) it takes away from readability and
|
||||
therefore is to be avoided.
|
||||
|
||||
Second, loop counters and other local throw-away variables often have a purpose
|
||||
which is obvious. There's no need, therefore, to get carried away with complex
|
||||
naming. We find i, j, and k are better loop counters than loopCounterVar or
|
||||
whatnot. We only break this rule when we see that more description could improve
|
||||
understanding of an algorithm.
|
||||
|
||||
|
||||
#### Consistent
|
||||
|
||||
We like consistency, but we're not really obsessed with it. We try to name our
|
||||
configuration macros in a consistent fashion... you'll notice a repeated use of
|
||||
UNITY_EXCLUDE_BLAH or UNITY_USES_BLAH macros. This helps users avoid having to
|
||||
remember each macro's details.
|
||||
|
||||
|
||||
#### Memorable
|
||||
|
||||
Where ever it doesn't violate the above principles, we try to apply memorable
|
||||
names. Sometimes this means using something that is simply descriptive, but
|
||||
often we strive for descriptive AND unique... we like quirky names that stand
|
||||
out in our memory and are easier to search for. Take a look through the file
|
||||
names in Ceedling and you'll get a good idea of what we are talking about here.
|
||||
Why use preprocess when you can use preprocessinator? Or what better describes a
|
||||
module in charge of invoking tasks during releases than release_invoker? Don't
|
||||
get carried away. The names are still descriptive and fulfill the above
|
||||
requirements, but they don't feel stale.
|
||||
|
||||
|
||||
## C and C++ Details
|
||||
|
||||
We don't really want to add to the style battles out there. Tabs or spaces?
|
||||
How many spaces? Where do the braces go? These are age-old questions that will
|
||||
never be answered... or at least not answered in a way that will make everyone
|
||||
happy.
|
||||
|
||||
We've decided on our own style preferences. If you'd like to contribute to these
|
||||
projects (and we hope that you do), then we ask if you do your best to follow
|
||||
the same. It will only hurt a little. We promise.
|
||||
|
||||
|
||||
#### Whitespace
|
||||
|
||||
Our C-style is to use spaces and to use 4 of them per indent level. It's a nice
|
||||
power-of-2 number that looks decent on a wide screen. We have no more reason
|
||||
than that. We break that rule when we have lines that wrap (macros or function
|
||||
arguments or whatnot). When that happens, we like to indent further to line
|
||||
things up in nice tidy columns.
|
||||
|
||||
```C
|
||||
if (stuff_happened)
|
||||
{
|
||||
do_something();
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### Case
|
||||
|
||||
- Files - all lower case with underscores.
|
||||
- Variables - all lower case with underscores
|
||||
- Macros - all caps with underscores.
|
||||
- Typedefs - all caps with underscores. (also ends with _T).
|
||||
- Functions - camel cased. Usually named ModuleName_FuncName
|
||||
- Constants and Globals - camel cased.
|
||||
|
||||
|
||||
#### Braces
|
||||
|
||||
The left brace is on the next line after the declaration. The right brace is
|
||||
directly below that. Everything in between in indented one level. If you're
|
||||
catching an error and you have a one-line, go ahead and to it on the same line.
|
||||
|
||||
```C
|
||||
while (blah)
|
||||
{
|
||||
//Like so. Even if only one line, we use braces.
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### Comments
|
||||
|
||||
Do you know what we hate? Old-school C block comments. BUT, we're using them
|
||||
anyway. As we mentioned, our goal is to support every compiler we can,
|
||||
especially embedded compilers. There are STILL C compilers out there that only
|
||||
support old-school block comments. So that is what we're using. We apologize. We
|
||||
think they are ugly too.
|
||||
|
||||
|
||||
## Ruby Details
|
||||
|
||||
Is there really such thing as a Ruby coding standard? Ruby is such a free form
|
||||
language, it seems almost sacrilegious to suggest that people should comply to
|
||||
one method! We'll keep it really brief!
|
||||
|
||||
|
||||
#### Whitespace
|
||||
|
||||
Our Ruby style is to use spaces and to use 2 of them per indent level. It's a
|
||||
nice power-of-2 number that really grooves with Ruby's compact style. We have no
|
||||
more reason than that. We break that rule when we have lines that wrap. When
|
||||
that happens, we like to indent further to line things up in nice tidy columns.
|
||||
|
||||
|
||||
#### Case
|
||||
|
||||
- Files - all lower case with underscores.
|
||||
- Variables - all lower case with underscores
|
||||
- Classes, Modules, etc - Camel cased.
|
||||
- Functions - all lower case with underscores
|
||||
- Constants - all upper case with underscores
|
||||
|
||||
|
||||
## Documentation
|
||||
|
||||
Egad. Really? We use markdown and we like pdf files because they can be made to
|
||||
look nice while still being portable. Good enough?
|
||||
|
||||
|
||||
*Find The Latest of This And More at [ThrowTheSwitch.org](https://throwtheswitch.org)*
|
||||
@@ -14,7 +14,7 @@ all: setup test ${BUILD_DIR}/main run
|
||||
setup:
|
||||
mkdir -p ${BUILD_DIR}
|
||||
mkdir -p ${OBJ}
|
||||
ruby ../../scripts/create_makefile.rb
|
||||
ruby ../../scripts/create_makefile.rb --silent
|
||||
|
||||
clean:
|
||||
rm -rf ${BUILD_DIR}
|
||||
@@ -23,7 +23,7 @@ ${BUILD_DIR}/main: ${SRC_DIR}/main.c ${SRC_DIR}/foo.c
|
||||
${CC} $< -o $@
|
||||
|
||||
run:
|
||||
./build/main
|
||||
./build/main || true
|
||||
|
||||
test: setup
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ compiler:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- '../../src/'
|
||||
- '../../vendor/unity/src/'
|
||||
- '../../vendor/unity/examples/example_3/helper/'
|
||||
- './build/mocks/'
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
@@ -39,5 +39,6 @@ linker:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
:mock_path: ./build/mocks
|
||||
|
||||
colour: true
|
||||
|
||||
@@ -30,10 +30,10 @@ compiler:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- '../../src/'
|
||||
- '../../vendor/unity/src/'
|
||||
- '../../vendor/unity/examples/example_3/helper/'
|
||||
- './build/mocks/'
|
||||
- [*tools_root, 'arm\inc\']
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
@@ -88,4 +88,5 @@ simulator:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
:mock_path: ./build/mocks
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ compiler:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- '../../src/'
|
||||
- '../../vendor/unity/src/'
|
||||
- '../../vendor/unity/examples/example_3/helper/'
|
||||
- './build/mocks/'
|
||||
- [*tools_root, 'arm\inc\']
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
@@ -77,4 +77,5 @@ simulator:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
:mock_path: ./build/mocks
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@ require './rakefile_helper'
|
||||
|
||||
include RakefileHelpers
|
||||
|
||||
REQUIRED_DIRS = [ './build', './build/mocks' ]
|
||||
REQUIRED_DIRS.each do |v|
|
||||
directory v
|
||||
end
|
||||
|
||||
# Load default configuration, for now
|
||||
DEFAULT_CONFIG_FILE = 'gcc.yml'
|
||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||
@@ -22,7 +27,7 @@ end
|
||||
|
||||
desc "Build and test Unity"
|
||||
task :all => [:clean, :unit, :summary]
|
||||
task :default => [:clobber, :all]
|
||||
task :default => REQUIRED_DIRS + [:clobber, :all]
|
||||
task :ci => [:default]
|
||||
task :cruise => [:default]
|
||||
|
||||
@@ -30,3 +35,8 @@ desc "Load configuration"
|
||||
task :config, :config_file do |t, args|
|
||||
configure_toolchain(args[:config_file])
|
||||
end
|
||||
|
||||
desc "Return error on Failures"
|
||||
task :strict do
|
||||
$return_error_on_failures = true
|
||||
end
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
require '../vendor/unity/auto/unity_test_summary'
|
||||
require '../vendor/unity/auto/generate_test_runner'
|
||||
require '../vendor/unity/auto/colour_reporter'
|
||||
require '../../vendor/unity/auto/unity_test_summary'
|
||||
require '../../vendor/unity/auto/generate_test_runner'
|
||||
require '../../vendor/unity/auto/colour_reporter'
|
||||
|
||||
module RakefileHelpers
|
||||
|
||||
$return_error_on_failures = false
|
||||
|
||||
C_EXTENSION = '.c'
|
||||
|
||||
def load_configuration(config_file)
|
||||
@@ -145,11 +147,11 @@ module RakefileHelpers
|
||||
return {:command => command, :pre_support => pre_support, :post_support => post_support}
|
||||
end
|
||||
|
||||
def execute(command_string, verbose=true)
|
||||
def execute(command_string, verbose=true, ok_to_fail=false)
|
||||
report command_string
|
||||
output = `#{command_string}`.chomp
|
||||
report(output) if (verbose && !output.nil? && (output.length > 0))
|
||||
if $?.exitstatus != 0
|
||||
unless $?.exitstatus.zero? || ok_to_fail
|
||||
raise "Command failed. (Returned #{$?.exitstatus})"
|
||||
end
|
||||
return output
|
||||
@@ -157,13 +159,13 @@ module RakefileHelpers
|
||||
|
||||
def report_summary
|
||||
summary = UnityTestSummary.new
|
||||
summary.set_root_path(HERE)
|
||||
summary.root = HERE
|
||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||
results_glob.gsub!(/\\/, '/')
|
||||
results = Dir[results_glob]
|
||||
summary.set_targets(results)
|
||||
summary.targets = results
|
||||
report summary.run
|
||||
raise "There were failures" if (summary.failures > 0)
|
||||
raise "There were failures" if (summary.failures > 0) && $return_error_on_failures
|
||||
end
|
||||
|
||||
def run_tests(test_files)
|
||||
@@ -188,7 +190,7 @@ module RakefileHelpers
|
||||
|
||||
#create mocks if needed
|
||||
if (header =~ /Mock/)
|
||||
require "../lib/cmock.rb"
|
||||
require "../../lib/cmock.rb"
|
||||
@cmock ||= CMock.new($cfg_file)
|
||||
@cmock.setup_mocks([$cfg['compiler']['source_path']+header.gsub('Mock','')])
|
||||
end
|
||||
@@ -231,7 +233,7 @@ module RakefileHelpers
|
||||
else
|
||||
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
|
||||
end
|
||||
output = execute(cmd_str)
|
||||
output = execute(cmd_str, true, true)
|
||||
test_results = $cfg['compiler']['build_path'] + test_base
|
||||
if output.match(/OK$/m).nil?
|
||||
test_results += '.testfail'
|
||||
|
||||
@@ -13,9 +13,6 @@
|
||||
"cmock_generator_utils",
|
||||
"cmock_unityhelper_parser"].each {|req| require "#{File.expand_path(File.dirname(__FILE__))}/#{req}"}
|
||||
|
||||
|
||||
$QUICK_RUBY_VERSION = RUBY_VERSION.split('.').inject(0){|vv,v| vv * 100 + v.to_i }
|
||||
|
||||
class CMock
|
||||
|
||||
def initialize(options=nil)
|
||||
|
||||
@@ -222,8 +222,9 @@ class CMockGenerator
|
||||
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
|
||||
file << "{\n"
|
||||
file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n"
|
||||
file << " CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance;\n"
|
||||
file << " UNITY_SET_DETAIL(CMockString_#{function[:name]});\n"
|
||||
file << " CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{function[:name]}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.#{function[:name]}_CallInstance);\n"
|
||||
file << " cmock_call_instance = (CMOCK_#{function[:name]}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.#{function[:name]}_CallInstance);\n"
|
||||
file << " Mock.#{function[:name]}_CallInstance = CMock_Guts_MemNext(Mock.#{function[:name]}_CallInstance);\n"
|
||||
file << @plugins.run(:mock_implementation_precheck, function)
|
||||
file << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n"
|
||||
|
||||
@@ -79,8 +79,12 @@ class CMockGeneratorPluginCallback
|
||||
|
||||
def mock_interfaces(function)
|
||||
func_name = function[:name]
|
||||
"void #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n" +
|
||||
" Mock.#{func_name}_CallbackFunctionPointer = Callback;\n}\n\n"
|
||||
lines = ""
|
||||
lines << "void #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n"
|
||||
if @config.plugins.include? :ignore
|
||||
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n"
|
||||
end
|
||||
lines << " Mock.#{func_name}_CallbackFunctionPointer = Callback;\n}\n\n"
|
||||
end
|
||||
|
||||
def mock_destroy(function)
|
||||
|
||||
@@ -64,7 +64,8 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
if (@utils.ptr_or_str?(arg[:type]) and not arg[:const?])
|
||||
lines << " if (cmock_call_instance->ReturnThruPtr_#{arg_name}_Used)\n"
|
||||
lines << " {\n"
|
||||
lines << " memcpy(#{arg_name}, cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n"
|
||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(#{arg_name}, cmock_line, CMockStringPtrIsNULL);\n"
|
||||
lines << " memcpy((void*)#{arg_name}, (void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n"
|
||||
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size);\n"
|
||||
lines << " }\n"
|
||||
end
|
||||
|
||||
@@ -48,7 +48,7 @@ class CMockHeaderParser
|
||||
def import_source(source)
|
||||
|
||||
# let's clean up the encoding in case they've done anything weird with the characters we might find
|
||||
source = source.force_encoding("ISO-8859-1").encode("utf-8", :replace => nil) if ($QUICK_RUBY_VERSION > 10900)
|
||||
source = source.force_encoding("ISO-8859-1").encode("utf-8", :replace => nil)
|
||||
|
||||
# void must be void for cmock _ExpectAndReturn calls to process properly, not some weird typedef which equates to void
|
||||
# to a certain extent, this action assumes we're chewing on pre-processed header files, otherwise we'll most likely just get stuff from @treat_as_void
|
||||
@@ -94,8 +94,7 @@ class CMockHeaderParser
|
||||
end
|
||||
|
||||
# remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection)
|
||||
while source.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
|
||||
end
|
||||
source.gsub!(/\{([^\{\}]*|\g<0>)*\}/m, '{ }')
|
||||
|
||||
# remove function definitions by stripping off the arguments right now
|
||||
source.gsub!(/\([^\)]*\)\s*\{[^\}]*\}/m, ";")
|
||||
@@ -187,9 +186,9 @@ class CMockHeaderParser
|
||||
return 'void'
|
||||
else
|
||||
c=0
|
||||
arg_list.gsub!(/(\w+)(?:\s*\[[\s\d\w+-]*\])+/,'*\1') # magically turn brackets into asterisks
|
||||
arg_list.gsub!(/\s+\*/,'*') # remove space to place asterisks with type (where they belong)
|
||||
arg_list.gsub!(/\*(\w)/,'* \1') # pull asterisks away from arg to place asterisks with type (where they belong)
|
||||
arg_list.gsub!(/(\w+)(?:\s*\[\s*\(*[\s\d\w+-]*\)*\s*\])+/,'*\1') # magically turn brackets into asterisks, also match for parentheses that come from macros
|
||||
arg_list.gsub!(/\s+\*/,'*') # remove space to place asterisks with type (where they belong)
|
||||
arg_list.gsub!(/\*(\w)/,'* \1') # pull asterisks away from arg to place asterisks with type (where they belong)
|
||||
|
||||
#scan argument list for function pointers and replace them with custom types
|
||||
arg_list.gsub!(/([\w\s\*]+)\(+\s*\*[\*\s]*([\w\s]*)\s*\)+\s*\(((?:[\w\s\*]*,?)*)\s*\)*/) do |m|
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
2.4.3
|
||||
2.4.4
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ end
|
||||
|
||||
all_headers_to_mock = []
|
||||
|
||||
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT")
|
||||
|
||||
File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
|
||||
# Define make variables
|
||||
@@ -103,7 +105,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
end
|
||||
end
|
||||
raise "Module header '#{name}' not found to mock!" unless header_to_mock
|
||||
headers_to_mock << header_to_mock
|
||||
headers_to_mock << header_to_mock
|
||||
end
|
||||
all_headers_to_mock += headers_to_mock
|
||||
mock_objs = headers_to_mock.map do |hdr|
|
||||
@@ -149,7 +151,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
|
||||
# Create test summary task
|
||||
mkfile.puts "test_summary:"
|
||||
mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/test_summary.rb"
|
||||
mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/test_summary.rb #{suppress_error ? '--silent' : ''}"
|
||||
mkfile.puts ""
|
||||
mkfile.puts ".PHONY: test_summary"
|
||||
mkfile.puts ""
|
||||
|
||||
+17
-9
@@ -1,11 +1,19 @@
|
||||
require "#{ENV['UNITY_DIR']}/auto/unity_test_summary.rb"
|
||||
|
||||
build_dir = ENV.fetch('BUILD_DIR', './build')
|
||||
test_build_dir = ENV.fetch('TEST_BUILD_DIR', File.join(build_dir, 'test'))
|
||||
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT")
|
||||
|
||||
results = Dir["#{test_build_dir}/*.result"]
|
||||
parser = UnityTestSummary.new
|
||||
parser.set_targets(results)
|
||||
parser.run
|
||||
puts parser.report
|
||||
exit(parser.failures)
|
||||
begin
|
||||
require "#{ENV['UNITY_DIR']}/auto/unity_test_summary.rb"
|
||||
|
||||
build_dir = ENV.fetch('BUILD_DIR', './build')
|
||||
test_build_dir = ENV.fetch('TEST_BUILD_DIR', File.join(build_dir, 'test'))
|
||||
|
||||
results = Dir["#{test_build_dir}/*.result"]
|
||||
parser = UnityTestSummary.new
|
||||
parser.targets = results
|
||||
parser.run
|
||||
puts parser.report
|
||||
rescue StandardError => e
|
||||
raise e unless suppress_error
|
||||
end
|
||||
|
||||
exit(parser.failures) unless suppress_error
|
||||
|
||||
@@ -16,6 +16,7 @@ const char* CMockStringCalledLate = "Called later than expected.";
|
||||
const char* CMockStringCallOrder = "Called out of order.";
|
||||
const char* CMockStringIgnPreExp = "IgnoreArg called before Expect.";
|
||||
const char* CMockStringPtrPreExp = "ReturnThruPtr called before Expect.";
|
||||
const char* CMockStringPtrIsNULL = "Pointer is NULL.";
|
||||
const char* CMockStringExpNULL = "Expected NULL.";
|
||||
const char* CMockStringMismatch = "Function called with unexpected argument value.";
|
||||
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
|
||||
#define CMOCK_ARG_MODE CMOCK_MEM_INDEX_TYPE
|
||||
#define CMOCK_ARG_ALL 0
|
||||
#define CMOCK_ARG_NONE ((CMOCK_MEM_INDEX_TYPE)(~0))
|
||||
#define CMOCK_ARG_NONE ((CMOCK_MEM_INDEX_TYPE)(~0U))
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Memory API
|
||||
|
||||
+14
-1
@@ -16,6 +16,7 @@ extern const char* CMockStringCalledLate;
|
||||
extern const char* CMockStringCallOrder;
|
||||
extern const char* CMockStringIgnPreExp;
|
||||
extern const char* CMockStringPtrPreExp;
|
||||
extern const char* CMockStringPtrIsNULL;
|
||||
extern const char* CMockStringExpNULL;
|
||||
extern const char* CMockStringMismatch;
|
||||
|
||||
@@ -59,7 +60,19 @@ extern const char* CMockStringMismatch;
|
||||
|
||||
//0 for no alignment, 1 for 16-bit, 2 for 32-bit, 3 for 64-bit
|
||||
#ifndef CMOCK_MEM_ALIGN
|
||||
#define CMOCK_MEM_ALIGN (2)
|
||||
#ifdef UNITY_LONG_WIDTH
|
||||
#if (UNITY_LONG_WIDTH == 16)
|
||||
#define CMOCK_MEM_ALIGN (1)
|
||||
#elif (UNITY_LONG_WIDTH == 32)
|
||||
#define CMOCK_MEM_ALIGN (2)
|
||||
#elif (UNITY_LONG_WIDTH == 64)
|
||||
#define CMOCK_MEM_ALIGN (3)
|
||||
#else
|
||||
#define CMOCK_MEM_ALIGN (2)
|
||||
#endif
|
||||
#else
|
||||
#define CMOCK_MEM_ALIGN (2)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//amount of memory to allow cmock to use in its internal heap
|
||||
|
||||
+1
-1
@@ -179,7 +179,7 @@ void test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory(void)
|
||||
}
|
||||
|
||||
//there aren't any after that
|
||||
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, (_UU32)next);
|
||||
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, (UNITY_UINT32)next);
|
||||
}
|
||||
|
||||
void test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd(void)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
:files:
|
||||
- 'src/cmock.c'
|
||||
- 'test/c/TestCMockC.c'
|
||||
- 'test/c/TestCMockC_Runner.c'
|
||||
- 'vendor/unity/src/unity.c'
|
||||
- '../src/cmock.c'
|
||||
- './c/TestCMockC.c'
|
||||
- './c/TestCMockC_Runner.c'
|
||||
- '../vendor/unity/src/unity.c'
|
||||
:options:
|
||||
- 'TEST'
|
||||
- 'CMOCK_MEM_STATIC'
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
:files:
|
||||
- 'src/cmock.c'
|
||||
- 'test/c/TestCMockCDynamic.c'
|
||||
- 'test/c/TestCMockCDynamic_Runner.c'
|
||||
- 'vendor/unity/src/unity.c'
|
||||
- '../src/cmock.c'
|
||||
- './c/TestCMockCDynamic.c'
|
||||
- './c/TestCMockCDynamic_Runner.c'
|
||||
- '../vendor/unity/src/unity.c'
|
||||
:options:
|
||||
- 'TEST'
|
||||
- 'CMOCK_MEM_DYNAMIC'
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==============================================================================
|
||||
|
||||
require './config/test_environment'
|
||||
require '../config/test_environment'
|
||||
require 'rake'
|
||||
require 'rake/clean'
|
||||
require 'rake/testtask'
|
||||
@@ -13,11 +13,11 @@ require './rakefile_helper'
|
||||
include RakefileHelpers
|
||||
|
||||
DEFAULT_CONFIG_FILE = 'gcc.yml'
|
||||
CMOCK_ROOT = File.expand_path(File.dirname(__FILE__))
|
||||
CMOCK_TEST_ROOT = File.expand_path(File.dirname(__FILE__))
|
||||
|
||||
SYSTEM_TEST_SUPPORT_DIRS = [
|
||||
File.join(CMOCK_ROOT, 'test/system/generated'),
|
||||
File.join(CMOCK_ROOT, 'test/system/build')
|
||||
File.join(CMOCK_TEST_ROOT, 'system/generated'),
|
||||
File.join(CMOCK_TEST_ROOT, 'system/build')
|
||||
]
|
||||
|
||||
SYSTEM_TEST_SUPPORT_DIRS.each do |dir|
|
||||
@@ -48,12 +48,12 @@ task :test => [:clobber, :prep_system_tests, 'test:units', 'test:c', 'test:syste
|
||||
namespace :test do
|
||||
desc "Run Unit Tests"
|
||||
Rake::TestTask.new('units') do |t|
|
||||
t.pattern = 'test/unit/*_test.rb'
|
||||
t.pattern = 'unit/*_test.rb'
|
||||
t.verbose = true
|
||||
end
|
||||
|
||||
#individual unit tests
|
||||
FileList['test/unit/*_test.rb'].each do |test|
|
||||
FileList['unit/*_test.rb'].each do |test|
|
||||
Rake::TestTask.new(File.basename(test,'.*').sub('_test','')) do |t|
|
||||
t.pattern = test
|
||||
t.verbose = true
|
||||
@@ -70,8 +70,8 @@ namespace :test do
|
||||
desc "Run System Tests"
|
||||
task :system => [:clobber, :prep_system_tests] do
|
||||
#get a list of all system tests, removing unsupported tests for this compiler
|
||||
sys_unsupported = $cfg['unsupported'].map {|a| 'test/system/test_interactions/'+a+'.yml'}
|
||||
sys_tests_to_run = FileList['test/system/test_interactions/*.yml'] - sys_unsupported
|
||||
sys_unsupported = $cfg['unsupported'].map {|a| 'system/test_interactions/'+a+'.yml'}
|
||||
sys_tests_to_run = FileList['system/test_interactions/*.yml'] - sys_unsupported
|
||||
compile_unsupported = $cfg['unsupported'].map {|a| SYSTEST_COMPILE_MOCKABLES_PATH+a+'.h'}
|
||||
compile_tests_to_run = FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'] - compile_unsupported
|
||||
unless (sys_unsupported.empty? and compile_unsupported.empty?)
|
||||
@@ -87,7 +87,7 @@ namespace :test do
|
||||
end
|
||||
|
||||
#individual system tests
|
||||
FileList['test/system/test_interactions/*.yml'].each do |test|
|
||||
FileList['system/test_interactions/*.yml'].each do |test|
|
||||
basename = File.basename(test,'.*')
|
||||
desc "Run system test #{basename}"
|
||||
task basename do
|
||||
@@ -6,16 +6,16 @@
|
||||
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
require './vendor/unity/auto/generate_test_runner'
|
||||
require './vendor/unity/auto/unity_test_summary'
|
||||
require './test/system/systest_generator'
|
||||
require './vendor/unity/auto/colour_reporter.rb'
|
||||
require '../vendor/unity/auto/generate_test_runner'
|
||||
require '../vendor/unity/auto/unity_test_summary'
|
||||
require '../vendor/unity/auto/colour_reporter.rb'
|
||||
require './system/systest_generator'
|
||||
|
||||
module RakefileHelpers
|
||||
|
||||
SYSTEST_GENERATED_FILES_PATH = 'test/system/generated/'
|
||||
SYSTEST_BUILD_FILES_PATH = 'test/system/build/'
|
||||
SYSTEST_COMPILE_MOCKABLES_PATH = 'test/system/test_compilation/'
|
||||
SYSTEST_GENERATED_FILES_PATH = './system/generated/'
|
||||
SYSTEST_BUILD_FILES_PATH = './system/build/'
|
||||
SYSTEST_COMPILE_MOCKABLES_PATH = './system/test_compilation/'
|
||||
C_EXTENSION = '.c'
|
||||
RESULT_EXTENSION = '.result'
|
||||
|
||||
@@ -162,17 +162,17 @@ module RakefileHelpers
|
||||
|
||||
def report_summary
|
||||
summary = UnityTestSummary.new
|
||||
summary.set_root_path(File.expand_path(File.dirname(__FILE__)) + '/')
|
||||
summary.root = File.expand_path(File.dirname(__FILE__)) + '/'
|
||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||
results_glob.gsub!(/\\/, '/')
|
||||
results = Dir[results_glob]
|
||||
summary.set_targets(results)
|
||||
summary.targets = results
|
||||
summary.run
|
||||
fail_out "FAIL: There were failures" if (summary.failures > 0)
|
||||
end
|
||||
|
||||
def run_system_test_interactions(test_case_files)
|
||||
load './lib/cmock.rb'
|
||||
load '../lib/cmock.rb'
|
||||
|
||||
SystemTestGenerator.new.generate_files(test_case_files)
|
||||
test_files = FileList.new(SYSTEST_GENERATED_FILES_PATH + 'test*.c')
|
||||
@@ -308,7 +308,7 @@ module RakefileHelpers
|
||||
end
|
||||
|
||||
def run_system_test_compilations(mockables)
|
||||
load './lib/cmock.rb'
|
||||
load '../lib/cmock.rb'
|
||||
|
||||
load_configuration($cfg_file)
|
||||
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
|
||||
@@ -326,7 +326,7 @@ module RakefileHelpers
|
||||
end
|
||||
|
||||
def run_system_test_profiles(mockables)
|
||||
load './lib/cmock.rb'
|
||||
load '../lib/cmock.rb'
|
||||
|
||||
load_configuration($cfg_file)
|
||||
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
|
||||
@@ -353,7 +353,7 @@ module RakefileHelpers
|
||||
report "UNIT TEST C CODE\n"
|
||||
report "----------------\n"
|
||||
errors = false
|
||||
FileList.new("test/c/*.yml").each do |yaml_file|
|
||||
FileList.new("c/*.yml").each do |yaml_file|
|
||||
test = YAML.load(File.read(yaml_file))
|
||||
report "\nTesting #{yaml_file.sub('.yml','')}"
|
||||
report "(#{test[:options].join(', ')})"
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
:cmock:
|
||||
---
|
||||
:cmock:
|
||||
:plugins: []
|
||||
:includes: []
|
||||
:mock_path: test/system/generated/
|
||||
:mock_path: ./system/generated/
|
||||
:mock_prefix: mock_
|
||||
:treat_as_void:
|
||||
:treat_as_void:
|
||||
- OSEK_TASK
|
||||
- VOID_TYPE_CRAZINESS
|
||||
|
||||
@@ -64,6 +64,8 @@
|
||||
|
||||
void oh_brackets1(int fudge[5]);
|
||||
void oh_brackets2(int caramel[]);
|
||||
void oh_brackets3(int toffee[(32)]);
|
||||
void oh_brackets4(int taffy[ (64) ]);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
:systest:
|
||||
:types: |
|
||||
#include "unity_internals.h"
|
||||
typedef _UU64 TEST64;
|
||||
|
||||
typedef UNITY_UINT64 TEST64;
|
||||
|
||||
:mockable: |
|
||||
TEST64 foo(TEST64 a);
|
||||
TEST64* bar(TEST64* b);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
:source:
|
||||
:header: |
|
||||
TEST64 function_a(void);
|
||||
|
||||
:code: |
|
||||
@@ -23,17 +23,17 @@
|
||||
TEST64 a = 0x1234567890123456;
|
||||
TEST64 b;
|
||||
TEST64* c;
|
||||
|
||||
|
||||
b = foo(a);
|
||||
c = bar(&b);
|
||||
return *c;
|
||||
}
|
||||
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'handle a straightforward 64-bit series of calls'
|
||||
@@ -44,10 +44,10 @@
|
||||
TEST64 b = 0x5a5a5a5a5a5a5a5a;
|
||||
foo_ExpectAndReturn(0x1234567890123456, 0x0987654321543210);
|
||||
bar_ExpectAndReturn(&a, &b);
|
||||
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX64(b, function_a());
|
||||
}
|
||||
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle a straightforward 64-bit series of calls with a failure'
|
||||
:code: |
|
||||
@@ -57,10 +57,10 @@
|
||||
TEST64 b = 0x5a5a5a5a5a5a5a5a;
|
||||
foo_ExpectAndReturn(0x1234567890123456, 0x0987654321543211);
|
||||
bar_ExpectAndReturn(&a, &b);
|
||||
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX64(b, function_a());
|
||||
}
|
||||
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle a straightforward 64-bit series of calls returning a failure'
|
||||
:code: |
|
||||
@@ -70,8 +70,8 @@
|
||||
TEST64 b = 0x5a5a5a5a5a5a5a5a;
|
||||
foo_ExpectAndReturn(0x1234567890123456, 0x0987654321543210);
|
||||
bar_ExpectAndReturn(&a, &b);
|
||||
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX64(b+1, function_a());
|
||||
}
|
||||
|
||||
|
||||
...
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
---
|
||||
compiler:
|
||||
path: clang
|
||||
source_path: &systest_generated_path 'test/system/generated/'
|
||||
unit_tests_path: &unit_tests_path 'examples/test/'
|
||||
mocks_path: &systest_mocks_path 'test/system/generated/'
|
||||
build_path: &systest_build_path 'test/system/build/'
|
||||
source_path: &systest_generated_path './system/generated/'
|
||||
unit_tests_path: &unit_tests_path '../examples/test/'
|
||||
mocks_path: &systest_mocks_path './system/generated/'
|
||||
build_path: &systest_build_path './system/build/'
|
||||
options:
|
||||
- '-c'
|
||||
- '-Wall'
|
||||
- '-Wextra'
|
||||
- '-Werror'
|
||||
- '-Wcast-qual'
|
||||
#- '-Wcast-qual'
|
||||
- '-Wconversion'
|
||||
- '-Wtautological-compare'
|
||||
#- '-Wtautological-pointer-compare'
|
||||
@@ -41,7 +41,7 @@ compiler:
|
||||
- '-Wno-invalid-token-paste'
|
||||
- '-fms-extensions'
|
||||
- '-fno-omit-frame-pointer'
|
||||
- '-ffloat-store'
|
||||
#- '-ffloat-store'
|
||||
- '-fno-common'
|
||||
- '-fstrict-aliasing'
|
||||
- '-std=gnu99'
|
||||
@@ -53,11 +53,11 @@ compiler:
|
||||
- *systest_generated_path
|
||||
- *unit_tests_path
|
||||
- *systest_mocks_path
|
||||
- 'src/'
|
||||
- 'vendor/unity/src/'
|
||||
- 'vendor/c_exception/lib/'
|
||||
- 'test/system/test_compilation/'
|
||||
- 'test/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/c_exception/lib/'
|
||||
- './system/test_compilation/'
|
||||
- './'
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
@@ -1,10 +1,10 @@
|
||||
---
|
||||
compiler:
|
||||
path: gcc
|
||||
source_path: &systest_generated_path 'test/system/generated/'
|
||||
unit_tests_path: &unit_tests_path 'examples/test/'
|
||||
mocks_path: &systest_mocks_path 'test/system/generated/'
|
||||
build_path: &systest_build_path 'test/system/build/'
|
||||
source_path: &systest_generated_path './system/generated/'
|
||||
unit_tests_path: &unit_tests_path '../examples/test/'
|
||||
mocks_path: &systest_mocks_path './system/generated/'
|
||||
build_path: &systest_build_path './system/build/'
|
||||
options:
|
||||
- '-c'
|
||||
- '-Wall'
|
||||
@@ -21,11 +21,11 @@ compiler:
|
||||
- *systest_generated_path
|
||||
- *unit_tests_path
|
||||
- *systest_mocks_path
|
||||
- 'src/'
|
||||
- 'vendor/unity/src/'
|
||||
- 'vendor/c_exception/lib/'
|
||||
- 'test/system/test_compilation/'
|
||||
- 'test/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/c_exception/lib/'
|
||||
- './system/test_compilation/'
|
||||
- './'
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
@@ -1,10 +1,10 @@
|
||||
---
|
||||
compiler:
|
||||
path: gcc
|
||||
source_path: &systest_generated_path 'test/system/generated/'
|
||||
unit_tests_path: &unit_tests_path 'examples/test/'
|
||||
mocks_path: &systest_mocks_path 'test/system/generated/'
|
||||
build_path: &systest_build_path 'test/system/build/'
|
||||
source_path: &systest_generated_path './system/generated/'
|
||||
unit_tests_path: &unit_tests_path '../examples/test/'
|
||||
mocks_path: &systest_mocks_path './system/generated/'
|
||||
build_path: &systest_build_path './system/build/'
|
||||
options:
|
||||
- '-c'
|
||||
- '-m64'
|
||||
@@ -20,11 +20,11 @@ compiler:
|
||||
- *systest_generated_path
|
||||
- *unit_tests_path
|
||||
- *systest_mocks_path
|
||||
- 'src/'
|
||||
- 'vendor/unity/src/'
|
||||
- 'vendor/c_exception/lib/'
|
||||
- 'test/system/test_compilation/'
|
||||
- 'test/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/c_exception/lib/'
|
||||
- './system/test_compilation/'
|
||||
- './'
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
@@ -1,10 +1,10 @@
|
||||
---
|
||||
compiler:
|
||||
path: gcc
|
||||
source_path: &systest_generated_path 'test/system/generated/'
|
||||
unit_tests_path: &unit_tests_path 'examples/test/'
|
||||
mocks_path: &systest_mocks_path 'test/system/generated/'
|
||||
build_path: &systest_build_path 'test/system/build/'
|
||||
source_path: &systest_generated_path './system/generated/'
|
||||
unit_tests_path: &unit_tests_path '../examples/test/'
|
||||
mocks_path: &systest_mocks_path './system/generated/'
|
||||
build_path: &systest_build_path './system/build/'
|
||||
options:
|
||||
- '-c'
|
||||
- '-Wall'
|
||||
@@ -21,11 +21,11 @@ compiler:
|
||||
- *systest_generated_path
|
||||
- *unit_tests_path
|
||||
- *systest_mocks_path
|
||||
- 'src/'
|
||||
- 'vendor/unity/src/'
|
||||
- 'vendor/c_exception/lib/'
|
||||
- 'test/system/test_compilation/'
|
||||
- 'test/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/c_exception/lib/'
|
||||
- './system/test_compilation/'
|
||||
- './'
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
@@ -1,10 +1,10 @@
|
||||
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 4.0\'
|
||||
compiler:
|
||||
path: [*tools_root, 'arm\bin\iccarm.exe']
|
||||
source_path: &systest_generated_path 'test/system/generated/'
|
||||
unit_tests_path: &unit_tests_path 'examples/test/'
|
||||
mocks_path: &systest_mocks_path 'test/system/generated/'
|
||||
build_path: &systest_build_path 'test/system/build/'
|
||||
source_path: &systest_generated_path './system/generated/'
|
||||
unit_tests_path: &unit_tests_path '../examples/test/'
|
||||
mocks_path: &systest_mocks_path './system/generated/'
|
||||
build_path: &systest_build_path './system/build/'
|
||||
options:
|
||||
- --dlib_config
|
||||
- [*tools_root, 'arm\lib\dl4tptinl8n.h']
|
||||
@@ -38,11 +38,11 @@ compiler:
|
||||
- *systest_generated_path
|
||||
- *unit_tests_path
|
||||
- *systest_mocks_path
|
||||
- 'src/'
|
||||
- 'vendor/unity/src/'
|
||||
- 'vendor/c_exception/lib/'
|
||||
- 'test/system/test_compilation/'
|
||||
- 'test\'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/c_exception/lib/'
|
||||
- './system/test_compilation/'
|
||||
- './'
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
@@ -1,10 +1,10 @@
|
||||
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.3\'
|
||||
compiler:
|
||||
path: [*tools_root, 'arm\bin\iccarm.exe']
|
||||
source_path: &systest_generated_path 'test/system/generated/'
|
||||
unit_tests_path: &unit_tests_path 'examples/test/'
|
||||
mocks_path: &systest_mocks_path 'test/system/generated/'
|
||||
build_path: &systest_build_path 'test/system/build/'
|
||||
source_path: &systest_generated_path './system/generated/'
|
||||
unit_tests_path: &unit_tests_path '../examples/test/'
|
||||
mocks_path: &systest_mocks_path './system/generated/'
|
||||
build_path: &systest_build_path './system/build/'
|
||||
options:
|
||||
- --dlib_config
|
||||
- [*tools_root, 'arm\inc\DLib_Config_Normal.h']
|
||||
@@ -36,12 +36,12 @@ compiler:
|
||||
- *systest_generated_path
|
||||
- *unit_tests_path
|
||||
- *systest_mocks_path
|
||||
- 'src/'
|
||||
- 'vendor/unity/src/'
|
||||
- 'vendor/c_exception/lib/'
|
||||
- 'iar\iar_v5\incIAR\'
|
||||
- 'test\system\test_compilation\'
|
||||
- 'test\'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/c_exception/lib/'
|
||||
- './system/test_compilation/'
|
||||
- './'
|
||||
- '.\iar\iar_v5\incIAR\'
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
+4
-8
@@ -15,14 +15,10 @@ end
|
||||
|
||||
def create_stub(funcs)
|
||||
stub = Class.new
|
||||
#if (RUBY_VERSION.split('.')[0].to_i >= 2)
|
||||
# funcs.each_pair {|k,v| stub.define_singleton_method(k) {|*unused| return v } }
|
||||
#else
|
||||
blob = "class << stub\n"
|
||||
funcs.each_pair {|k,v| blob += "def #{k.to_s}(unused=nil)\n #{v.inspect}\nend\n" }
|
||||
blob += "end"
|
||||
eval blob
|
||||
#end
|
||||
blob = "class << stub\n"
|
||||
funcs.each_pair {|k,v| blob += "def #{k.to_s}(unused=nil)\n #{v.inspect}\nend\n" }
|
||||
blob += "end"
|
||||
eval blob
|
||||
stub
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_config'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_config'
|
||||
|
||||
|
||||
describe CMockConfig, "Verify CMockConfig Module" do
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_file_writer'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_file_writer'
|
||||
|
||||
describe CMockFileWriter, "Verify CMockFileWriter Module" do
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
$ThisIsOnlyATest = true
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator'
|
||||
|
||||
class MockedPluginHelper
|
||||
def initialize return_this
|
||||
@@ -465,8 +465,9 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
expected = [ "static int SupaFunction(uint32 sandwiches, const char* named)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n",
|
||||
" UNITY_SET_DETAIL(CMockString_SupaFunction);\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
|
||||
" cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
|
||||
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
|
||||
" uno",
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n",
|
||||
@@ -499,8 +500,9 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
expected = [ "int __stdcall SupaFunction(uint32 sandwiches, corn ...)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n",
|
||||
" UNITY_SET_DETAIL(CMockString_SupaFunction);\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
|
||||
" cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
|
||||
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
|
||||
" uno",
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_array'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_array'
|
||||
|
||||
describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
|
||||
before do
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_callback'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_callback'
|
||||
|
||||
describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Module" do
|
||||
|
||||
@@ -14,6 +14,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
|
||||
@config.expect :callback_include_count, true
|
||||
@config.expect :callback_after_arg_check, false
|
||||
@config.expect :plugins, [:ignore]
|
||||
|
||||
@cmock_generator_plugin_callback = CMockGeneratorPluginCallback.new(@config, @utils)
|
||||
end
|
||||
@@ -240,6 +241,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
|
||||
expected = ["void Lemon_StubWithCallback(CMOCK_Lemon_CALLBACK Callback)\n",
|
||||
"{\n",
|
||||
" Mock.Lemon_IgnoreBool = (int)0;\n",
|
||||
" Mock.Lemon_CallbackFunctionPointer = Callback;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_cexception'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_cexception'
|
||||
|
||||
describe CMockGeneratorPluginCexception, "Verify CMockGeneratorPluginCexception Module" do
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_expect'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect'
|
||||
|
||||
describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module Without Global Ordering" do
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_expect_any_args.rb'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect_any_args.rb'
|
||||
|
||||
describe CMockGeneratorPluginExpectAnyArgs, "Verify CMockGeneratorPluginExpectAnyArgs Module" do
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_expect'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect'
|
||||
|
||||
describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module with Global Ordering" do
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_ignore_arg'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_ignore_arg'
|
||||
|
||||
describe CMockGeneratorPluginIgnoreArg, "Verify CMockGeneratorPluginIgnoreArg Module" do
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_ignore'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_ignore'
|
||||
|
||||
describe CMockGeneratorPluginIgnore, "Verify CMockGeneratorPluginIgnore Module" do
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user