mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-13 05:39:58 +00:00
Merge pull request #294 from ThrowTheSwitch/style
Update Testing and Style to match our coding standard
This commit is contained in:
@@ -6,3 +6,4 @@ Gemfile.lock
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
*.swp
|
*.swp
|
||||||
examples/make_example/build
|
examples/make_example/build
|
||||||
|
examples/temp_sensor/build
|
||||||
|
|||||||
+16
-16
@@ -1,28 +1,28 @@
|
|||||||
language: ruby
|
sudo: required
|
||||||
|
language: ruby c
|
||||||
|
|
||||||
os:
|
matrix:
|
||||||
- linux
|
include:
|
||||||
|
#- os: osx
|
||||||
rvm:
|
# compiler: clang
|
||||||
- "2.3"
|
# osx_image: xcode7.3
|
||||||
- "2.4"
|
- os: linux
|
||||||
- "2.6"
|
dist: trusty
|
||||||
|
rvm: "2.4"
|
||||||
|
compiler: gcc
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
|
rvm: "2.7"
|
||||||
|
compiler: clang
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- sudo apt-get install --assume-yes --quiet gcc-multilib
|
- sudo apt-get install --assume-yes --quiet gcc-multilib
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
- gem install bundler
|
||||||
- bundle install
|
- bundle install
|
||||||
- gem install rspec
|
- gem install rspec
|
||||||
- gem install rubocop -v 0.57.2
|
- gem install rubocop -v 0.57.2
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- cd test && rake ci
|
- cd test && rake ci
|
||||||
- cd ..
|
|
||||||
- cd examples && cd make_example
|
|
||||||
- make clean
|
|
||||||
- make setup
|
|
||||||
- make test
|
|
||||||
- cd ..
|
|
||||||
- cd temp_sensor
|
|
||||||
- rake ci
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
source "http://rubygems.org/"
|
source "http://rubygems.org/"
|
||||||
|
|
||||||
gem "bundler", "~> 1.1.rc.7"
|
gem "bundler"
|
||||||
gem "rake", ">= 0.9.2.2"
|
gem "rake"
|
||||||
|
|
||||||
gem "minitest"
|
gem "minitest"
|
||||||
gem "require_all"
|
gem "require_all"
|
||||||
gem "constructor"
|
gem "constructor"
|
||||||
|
|||||||
@@ -2,13 +2,11 @@
|
|||||||
# CMock Project - Automatic Mock Generation for C
|
# CMock Project - Automatic Mock Generation for C
|
||||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
# Setup our load path:
|
# Setup our load path:
|
||||||
[
|
[
|
||||||
'lib',
|
'lib'
|
||||||
].each do |dir|
|
].each do |dir|
|
||||||
$LOAD_PATH.unshift( File.join( File.expand_path(File.dirname(__FILE__)) + '/../', dir) )
|
$:.unshift(File.join(__dir__ + '/../', dir))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,5 +12,5 @@
|
|||||||
'./vendor/unity/auto/',
|
'./vendor/unity/auto/',
|
||||||
'./test/system/'
|
'./test/system/'
|
||||||
].each do |dir|
|
].each do |dir|
|
||||||
$LOAD_PATH.unshift( File.join( File.expand_path(File.dirname(__FILE__) + "/../"), dir) )
|
$:.unshift(File.join(File.expand_path(File.dirname(__FILE__) + '/../'), dir))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
HERE = File.expand_path(File.dirname(__FILE__)) + '/'
|
HERE = __dir__ + '/'
|
||||||
|
|
||||||
require 'rake'
|
require 'rake'
|
||||||
require 'rake/clean'
|
require 'rake/clean'
|
||||||
@@ -7,36 +7,36 @@ require './rakefile_helper'
|
|||||||
|
|
||||||
include RakefileHelpers
|
include RakefileHelpers
|
||||||
|
|
||||||
REQUIRED_DIRS = [ './build', './build/mocks' ]
|
REQUIRED_DIRS = ['./build', './build/mocks'].freeze
|
||||||
REQUIRED_DIRS.each do |v|
|
REQUIRED_DIRS.each do |v|
|
||||||
directory v
|
directory v
|
||||||
end
|
end
|
||||||
|
|
||||||
# Load default configuration, for now
|
# Load default configuration, for now
|
||||||
DEFAULT_CONFIG_FILE = 'gcc.yml'
|
DEFAULT_CONFIG_FILE = 'gcc.yml'.freeze
|
||||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||||
|
|
||||||
task :unit do
|
task :unit do
|
||||||
run_tests(get_unit_test_files)
|
run_tests(unit_test_files)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Generate test summary"
|
desc 'Generate test summary'
|
||||||
task :summary do
|
task :summary do
|
||||||
report_summary
|
report_summary
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Build and test Unity"
|
desc 'Build and test Unity'
|
||||||
task :all => [:clean, :unit, :summary]
|
task :all => %i[clean unit summary]
|
||||||
task :default => REQUIRED_DIRS + [:clobber, :all]
|
task :default => REQUIRED_DIRS + %i[clobber all]
|
||||||
task :ci => [:default]
|
task :ci => [:default]
|
||||||
task :cruise => [:default]
|
task :cruise => [:default]
|
||||||
|
|
||||||
desc "Load configuration"
|
desc 'Load configuration'
|
||||||
task :config, :config_file do |t, args|
|
task :config, :config_file do |_t, args|
|
||||||
configure_toolchain(args[:config_file])
|
configure_toolchain(args[:config_file])
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Return error on Failures"
|
desc 'Return error on Failures'
|
||||||
task :strict do
|
task :strict do
|
||||||
$return_error_on_failures = true
|
$return_error_on_failures = true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ require '../../vendor/unity/auto/generate_test_runner'
|
|||||||
require '../../vendor/unity/auto/colour_reporter'
|
require '../../vendor/unity/auto/colour_reporter'
|
||||||
|
|
||||||
module RakefileHelpers
|
module RakefileHelpers
|
||||||
|
|
||||||
$return_error_on_failures = false
|
$return_error_on_failures = false
|
||||||
|
|
||||||
C_EXTENSION = '.c'
|
C_EXTENSION = '.c'.freeze
|
||||||
|
|
||||||
def load_configuration(config_file)
|
def load_configuration(config_file)
|
||||||
$cfg_file = config_file
|
$cfg_file = config_file
|
||||||
@@ -20,22 +19,22 @@ module RakefileHelpers
|
|||||||
CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil?
|
CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def configure_toolchain(config_file=DEFAULT_CONFIG_FILE)
|
def configure_toolchain(config_file = DEFAULT_CONFIG_FILE)
|
||||||
config_file += '.yml' unless config_file =~ /\.yml$/
|
config_file += '.yml' unless config_file =~ /\.yml$/
|
||||||
load_configuration(config_file)
|
load_configuration(config_file)
|
||||||
configure_clean
|
configure_clean
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_unit_test_files
|
def unit_test_files
|
||||||
path = $cfg['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION
|
path = $cfg['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION
|
||||||
path.gsub!(/\\/, '/')
|
path.tr!('\\', '/')
|
||||||
FileList.new(path)
|
FileList.new(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_local_include_dirs
|
def local_include_dirs
|
||||||
include_dirs = $cfg['compiler']['includes']['items'].dup
|
include_dirs = $cfg['compiler']['includes']['items'].dup
|
||||||
include_dirs.delete_if {|dir| dir.is_a?(Array)}
|
include_dirs.delete_if { |dir| dir.is_a?(Array) }
|
||||||
return include_dirs
|
include_dirs
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_headers(filename)
|
def extract_headers(filename)
|
||||||
@@ -43,133 +42,134 @@ module RakefileHelpers
|
|||||||
lines = File.readlines(filename)
|
lines = File.readlines(filename)
|
||||||
lines.each do |line|
|
lines.each do |line|
|
||||||
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
|
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
|
||||||
if not m.nil?
|
unless m.nil?
|
||||||
includes << m[1]
|
includes << m[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return includes
|
includes
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_source_file(header, paths)
|
def find_source_file(header, paths)
|
||||||
paths.each do |dir|
|
paths.each do |dir|
|
||||||
src_file = dir + header.ext(C_EXTENSION)
|
src_file = dir + header.ext(C_EXTENSION)
|
||||||
if (File.exists?(src_file))
|
if File.exist?(src_file)
|
||||||
return src_file
|
return src_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def tackit(strings)
|
def tackit(strings)
|
||||||
case(strings)
|
case strings
|
||||||
when Array
|
when Array
|
||||||
"\"#{strings.join}\""
|
"\"#{strings.join}\""
|
||||||
when /^-/
|
when /^-/
|
||||||
strings
|
strings
|
||||||
when /\s/
|
when /\s/
|
||||||
"\"#{strings}\""
|
"\"#{strings}\""
|
||||||
else
|
else
|
||||||
strings
|
strings
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def squash(prefix, items)
|
def squash(prefix, items)
|
||||||
result = ''
|
result = ''
|
||||||
items.each { |item| result += " #{prefix}#{tackit(item)}" }
|
items.each { |item| result += " #{prefix}#{tackit(item)}" }
|
||||||
return result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_compiler_fields
|
def build_compiler_fields
|
||||||
command = tackit($cfg['compiler']['path'])
|
command = tackit($cfg['compiler']['path'])
|
||||||
if $cfg['compiler']['defines']['items'].nil?
|
defines = if $cfg['compiler']['defines']['items'].nil?
|
||||||
defines = ''
|
''
|
||||||
else
|
else
|
||||||
defines = squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'])
|
squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'])
|
||||||
end
|
end
|
||||||
options = squash('', $cfg['compiler']['options'])
|
options = squash('', $cfg['compiler']['options'])
|
||||||
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
|
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
|
||||||
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
||||||
return {:command => command, :defines => defines, :options => options, :includes => includes}
|
{ :command => command, :defines => defines, :options => options, :includes => includes }
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile(file, defines=[])
|
def compile(file, _defines = [])
|
||||||
compiler = build_compiler_fields
|
compiler = build_compiler_fields
|
||||||
cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{file} " +
|
cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{file} " \
|
||||||
"#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}"
|
"#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}"
|
||||||
obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}"
|
obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}"
|
||||||
execute(cmd_str + obj_file)
|
execute(cmd_str + obj_file)
|
||||||
return obj_file
|
obj_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_linker_fields
|
def build_linker_fields
|
||||||
command = tackit($cfg['linker']['path'])
|
command = tackit($cfg['linker']['path'])
|
||||||
if $cfg['linker']['options'].nil?
|
options = if $cfg['linker']['options'].nil?
|
||||||
options = ''
|
''
|
||||||
else
|
else
|
||||||
options = squash('', $cfg['linker']['options'])
|
squash('', $cfg['linker']['options'])
|
||||||
end
|
end
|
||||||
if ($cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?)
|
includes = if $cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?
|
||||||
includes = ''
|
''
|
||||||
else
|
else
|
||||||
includes = squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
|
squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
|
||||||
end
|
end
|
||||||
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
||||||
return {:command => command, :options => options, :includes => includes}
|
{ :command => command, :options => options, :includes => includes }
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_it(exe_name, obj_list)
|
def link_it(exe_name, obj_list)
|
||||||
linker = build_linker_fields
|
linker = build_linker_fields
|
||||||
cmd_str = "#{linker[:command]}#{linker[:includes]} " +
|
cmd_str = "#{linker[:command]}#{linker[:includes]} " +
|
||||||
(obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).join +
|
(obj_list.map { |obj| "#{$cfg['linker']['object_files']['path']}#{obj} " }).join +
|
||||||
$cfg['linker']['bin_files']['prefix'] + ' ' +
|
$cfg['linker']['bin_files']['prefix'] + ' ' +
|
||||||
$cfg['linker']['bin_files']['destination'] +
|
$cfg['linker']['bin_files']['destination'] +
|
||||||
exe_name + $cfg['linker']['bin_files']['extension'] + " #{linker[:options]}"
|
exe_name + $cfg['linker']['bin_files']['extension'] + " #{linker[:options]}"
|
||||||
execute(cmd_str)
|
execute(cmd_str)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_simulator_fields
|
def build_simulator_fields
|
||||||
return nil if $cfg['simulator'].nil?
|
return nil if $cfg['simulator'].nil?
|
||||||
if $cfg['simulator']['path'].nil?
|
|
||||||
command = ''
|
command = if $cfg['simulator']['path'].nil?
|
||||||
else
|
''
|
||||||
command = (tackit($cfg['simulator']['path']) + ' ')
|
else
|
||||||
end
|
(tackit($cfg['simulator']['path']) + ' ')
|
||||||
if $cfg['simulator']['pre_support'].nil?
|
end
|
||||||
pre_support = ''
|
pre_support = if $cfg['simulator']['pre_support'].nil?
|
||||||
else
|
''
|
||||||
pre_support = squash('', $cfg['simulator']['pre_support'])
|
else
|
||||||
end
|
squash('', $cfg['simulator']['pre_support'])
|
||||||
if $cfg['simulator']['post_support'].nil?
|
end
|
||||||
post_support = ''
|
post_support = if $cfg['simulator']['post_support'].nil?
|
||||||
else
|
''
|
||||||
post_support = squash('', $cfg['simulator']['post_support'])
|
else
|
||||||
end
|
squash('', $cfg['simulator']['post_support'])
|
||||||
return {:command => command, :pre_support => pre_support, :post_support => post_support}
|
end
|
||||||
|
{ :command => command, :pre_support => pre_support, :post_support => post_support }
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute(command_string, verbose=true, ok_to_fail=false)
|
def execute(command_string, verbose = true, ok_to_fail = false)
|
||||||
report command_string
|
report command_string
|
||||||
output = `#{command_string}`.chomp
|
output = `#{command_string}`.chomp
|
||||||
report(output) if (verbose && !output.nil? && (output.length > 0))
|
report(output) if verbose && !output.nil? && !output.empty?
|
||||||
unless (!$?.nil? && $?.exitstatus.zero?) || ok_to_fail
|
unless (!$?.nil? && $?.exitstatus.zero?) || ok_to_fail
|
||||||
raise "Command failed. (Returned #{$?.exitstatus})"
|
raise "Command failed. (Returned #{$?.exitstatus})"
|
||||||
end
|
end
|
||||||
return output
|
|
||||||
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_summary
|
def report_summary
|
||||||
summary = UnityTestSummary.new
|
summary = UnityTestSummary.new
|
||||||
summary.root = HERE
|
summary.root = HERE
|
||||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||||
results_glob.gsub!(/\\/, '/')
|
results_glob.tr!('\\', '/')
|
||||||
results = Dir[results_glob]
|
results = Dir[results_glob]
|
||||||
summary.targets = results
|
summary.targets = results
|
||||||
report summary.run
|
report summary.run
|
||||||
raise "There were failures" if (summary.failures > 0) && $return_error_on_failures
|
raise 'There were failures' if (summary.failures > 0) && $return_error_on_failures
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_tests(test_files)
|
def run_tests(test_files)
|
||||||
|
|
||||||
report 'Running system tests...'
|
report 'Running system tests...'
|
||||||
|
|
||||||
# Tack on TEST define for compiling unit tests
|
# Tack on TEST define for compiling unit tests
|
||||||
@@ -178,30 +178,28 @@ module RakefileHelpers
|
|||||||
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
|
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
|
||||||
$cfg['compiler']['defines']['items'] << 'TEST'
|
$cfg['compiler']['defines']['items'] << 'TEST'
|
||||||
|
|
||||||
include_dirs = get_local_include_dirs
|
include_dirs = local_include_dirs
|
||||||
|
|
||||||
# Build and execute each unit test
|
# Build and execute each unit test
|
||||||
test_files.each do |test|
|
test_files.each do |test|
|
||||||
obj_list = []
|
obj_list = []
|
||||||
|
|
||||||
# Detect dependencies and build required required modules
|
# Detect dependencies and build required required modules
|
||||||
header_list = (extract_headers(test) + ['cmock.h'] + [ $cfg[:cmock][:unity_helper_path] ]).compact.uniq
|
header_list = (extract_headers(test) + ['cmock.h'] + [$cfg[:cmock][:unity_helper_path]]).compact.uniq
|
||||||
header_list.each do |header|
|
header_list.each do |header|
|
||||||
|
# create mocks if needed
|
||||||
|
next unless header =~ /Mock/
|
||||||
|
|
||||||
#create mocks if needed
|
require '../../lib/cmock.rb'
|
||||||
if (header =~ /Mock/)
|
@cmock ||= CMock.new($cfg_file)
|
||||||
require "../../lib/cmock.rb"
|
@cmock.setup_mocks([$cfg['compiler']['source_path'] + header.gsub('Mock', '')])
|
||||||
@cmock ||= CMock.new($cfg_file)
|
|
||||||
@cmock.setup_mocks([$cfg['compiler']['source_path']+header.gsub('Mock','')])
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#compile all mocks
|
# compile all mocks
|
||||||
header_list.each do |header|
|
header_list.each do |header|
|
||||||
#compile source file header if it exists
|
# compile source file header if it exists
|
||||||
src_file = find_source_file(header, include_dirs)
|
src_file = find_source_file(header, include_dirs)
|
||||||
if !src_file.nil?
|
unless src_file.nil?
|
||||||
obj_list << compile(src_file, test_defines)
|
obj_list << compile(src_file, test_defines)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -228,35 +226,34 @@ module RakefileHelpers
|
|||||||
# Execute unit test and generate results file
|
# Execute unit test and generate results file
|
||||||
simulator = build_simulator_fields
|
simulator = build_simulator_fields
|
||||||
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
|
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
|
||||||
if simulator.nil?
|
cmd_str = if simulator.nil?
|
||||||
cmd_str = executable
|
executable
|
||||||
else
|
else
|
||||||
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
|
"#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
|
||||||
end
|
end
|
||||||
output = execute(cmd_str, true, true)
|
output = execute(cmd_str, true, true)
|
||||||
test_results = $cfg['compiler']['build_path'] + test_base
|
test_results = $cfg['compiler']['build_path'] + test_base
|
||||||
if output.match(/OK$/m).nil?
|
test_results += if output.match(/OK$/m).nil?
|
||||||
test_results += '.testfail'
|
'.testfail'
|
||||||
else
|
else
|
||||||
test_results += '.testpass'
|
'.testpass'
|
||||||
end
|
end
|
||||||
File.open(test_results, 'w') { |f| f.print output }
|
File.open(test_results, 'w') { |f| f.print output }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_application(main)
|
def build_application(main)
|
||||||
|
report 'Building application...'
|
||||||
report "Building application..."
|
|
||||||
|
|
||||||
obj_list = []
|
obj_list = []
|
||||||
load_configuration($cfg_file)
|
load_configuration($cfg_file)
|
||||||
main_path = $cfg['compiler']['source_path'] + main + C_EXTENSION
|
main_path = $cfg['compiler']['source_path'] + main + C_EXTENSION
|
||||||
|
|
||||||
# Detect dependencies and build required required modules
|
# Detect dependencies and build required required modules
|
||||||
include_dirs = get_local_include_dirs
|
include_dirs = local_include_dirs
|
||||||
extract_headers(main_path).each do |header|
|
extract_headers(main_path).each do |header|
|
||||||
src_file = find_source_file(header, include_dirs)
|
src_file = find_source_file(header, include_dirs)
|
||||||
if !src_file.nil?
|
unless src_file.nil?
|
||||||
obj_list << compile(src_file)
|
obj_list << compile(src_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -268,5 +265,4 @@ module RakefileHelpers
|
|||||||
# Create the executable
|
# Create the executable
|
||||||
link_it(main_base, obj_list)
|
link_it(main_base, obj_list)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
+22
-23
@@ -4,22 +4,21 @@
|
|||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
[ "../config/production_environment",
|
['../config/production_environment',
|
||||||
"cmock_header_parser",
|
'cmock_header_parser',
|
||||||
"cmock_generator",
|
'cmock_generator',
|
||||||
"cmock_file_writer",
|
'cmock_file_writer',
|
||||||
"cmock_config",
|
'cmock_config',
|
||||||
"cmock_plugin_manager",
|
'cmock_plugin_manager',
|
||||||
"cmock_generator_utils",
|
'cmock_generator_utils',
|
||||||
"cmock_unityhelper_parser"].each {|req| require "#{File.expand_path(File.dirname(__FILE__))}/#{req}"}
|
'cmock_unityhelper_parser'].each { |req| require "#{__dir__}/#{req}" }
|
||||||
|
|
||||||
class CMock
|
class CMock
|
||||||
|
def initialize(options = nil)
|
||||||
def initialize(options=nil)
|
|
||||||
cm_config = CMockConfig.new(options)
|
cm_config = CMockConfig.new(options)
|
||||||
cm_unityhelper = CMockUnityHelperParser.new(cm_config)
|
cm_unityhelper = CMockUnityHelperParser.new(cm_config)
|
||||||
cm_writer = CMockFileWriter.new(cm_config)
|
cm_writer = CMockFileWriter.new(cm_config)
|
||||||
cm_gen_utils = CMockGeneratorUtils.new(cm_config, {:unity_helper => cm_unityhelper})
|
cm_gen_utils = CMockGeneratorUtils.new(cm_config, :unity_helper => cm_unityhelper)
|
||||||
cm_gen_plugins = CMockPluginManager.new(cm_config, cm_gen_utils)
|
cm_gen_plugins = CMockPluginManager.new(cm_config, cm_gen_utils)
|
||||||
@cm_parser = CMockHeaderParser.new(cm_config)
|
@cm_parser = CMockHeaderParser.new(cm_config)
|
||||||
@cm_generator = CMockGenerator.new(cm_config, cm_writer, cm_gen_utils, cm_gen_plugins)
|
@cm_generator = CMockGenerator.new(cm_config, cm_writer, cm_gen_utils, cm_gen_plugins)
|
||||||
@@ -55,11 +54,11 @@ class CMock
|
|||||||
end
|
end
|
||||||
|
|
||||||
def option_maker(options, key, val)
|
def option_maker(options, key, val)
|
||||||
options = options || {}
|
options ||= {}
|
||||||
options[key.to_sym] =
|
options[key.to_sym] =
|
||||||
if val.chr == ":"
|
if val.chr == ':'
|
||||||
val[1..-1].to_sym
|
val[1..-1].to_sym
|
||||||
elsif val.include? ";"
|
elsif val.include? ';'
|
||||||
val.split(';')
|
val.split(';')
|
||||||
elsif val == 'true'
|
elsif val == 'true'
|
||||||
true
|
true
|
||||||
@@ -73,12 +72,12 @@ def option_maker(options, key, val)
|
|||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
# Command Line Support ###############################
|
# Command Line Support ###############################
|
||||||
|
|
||||||
if ($0 == __FILE__)
|
if $0 == __FILE__
|
||||||
usage = "usage: ruby #{__FILE__} (-oOptionsFile) File(s)ToMock"
|
usage = "usage: ruby #{__FILE__} (-oOptionsFile) File(s)ToMock"
|
||||||
|
|
||||||
if (!ARGV[0])
|
unless ARGV[0]
|
||||||
puts usage
|
puts usage
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
@@ -86,18 +85,18 @@ if ($0 == __FILE__)
|
|||||||
options = {}
|
options = {}
|
||||||
filelist = []
|
filelist = []
|
||||||
ARGV.each do |arg|
|
ARGV.each do |arg|
|
||||||
if (arg =~ /^-o\"?([a-zA-Z0-9._\\\/:\s]+)\"?/)
|
if arg =~ /^-o\"?([a-zA-Z0-9._\\\/:\s]+)\"?/
|
||||||
options.merge! CMockConfig.load_config_file_from_yaml( arg.gsub(/^-o/,'') )
|
options.merge! CMockConfig.load_config_file_from_yaml(arg.gsub(/^-o/, ''))
|
||||||
elsif (arg == "--skeleton")
|
elsif arg == '--skeleton'
|
||||||
options[:skeleton] = true
|
options[:skeleton] = true
|
||||||
elsif (arg =~ /^--([a-zA-Z0-9._\\\/:\s]+)=\"?([a-zA-Z0-9._\-\\\/:\s\;]+)\"?/)
|
elsif arg =~ /^--([a-zA-Z0-9._\\\/:\s]+)=\"?([a-zA-Z0-9._\-\\\/:\s\;]+)\"?/
|
||||||
options = option_maker(options, $1, $2)
|
options = option_maker(options, Regexp.last_match(1), Regexp.last_match(2))
|
||||||
else
|
else
|
||||||
filelist << arg
|
filelist << arg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (options[:skeleton])
|
if options[:skeleton]
|
||||||
CMock.new(options).setup_skeletons(filelist)
|
CMock.new(options).setup_skeletons(filelist)
|
||||||
else
|
else
|
||||||
CMock.new(options).setup_mocks(filelist)
|
CMock.new(options).setup_mocks(filelist)
|
||||||
|
|||||||
+67
-68
@@ -5,73 +5,72 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockConfig
|
class CMockConfig
|
||||||
|
CMOCK_DEFAULT_OPTIONS =
|
||||||
|
{
|
||||||
|
:framework => :unity,
|
||||||
|
:mock_path => 'mocks',
|
||||||
|
:mock_prefix => 'Mock',
|
||||||
|
:mock_suffix => '',
|
||||||
|
:skeleton_path => '',
|
||||||
|
:weak => '',
|
||||||
|
:subdir => nil,
|
||||||
|
:plugins => [],
|
||||||
|
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
|
||||||
|
:attributes => %w[__ramfunc __irq __fiq register extern],
|
||||||
|
:c_calling_conventions => %w[__stdcall __cdecl __fastcall],
|
||||||
|
:enforce_strict_ordering => false,
|
||||||
|
:fail_on_unexpected_calls => true,
|
||||||
|
:unity_helper_path => false,
|
||||||
|
:treat_as => {},
|
||||||
|
:treat_as_array => {},
|
||||||
|
:treat_as_void => [],
|
||||||
|
:memcmp_if_unknown => true,
|
||||||
|
:when_no_prototypes => :warn, # the options being :ignore, :warn, or :error
|
||||||
|
:when_ptr => :compare_data, # the options being :compare_ptr, :compare_data, or :smart
|
||||||
|
:verbosity => 2, # the options being 0 errors only, 1 warnings and errors, 2 normal info, 3 verbose
|
||||||
|
:treat_externs => :exclude, # the options being :include or :exclude
|
||||||
|
:treat_inlines => :exclude, # the options being :include or :exclude
|
||||||
|
:callback_include_count => true,
|
||||||
|
:callback_after_arg_check => false,
|
||||||
|
:includes => nil,
|
||||||
|
:includes_h_pre_orig_header => nil,
|
||||||
|
:includes_h_post_orig_header => nil,
|
||||||
|
:includes_c_pre_header => nil,
|
||||||
|
:includes_c_post_header => nil,
|
||||||
|
:orig_header_include_fmt => '#include "%s"',
|
||||||
|
:array_size_type => [],
|
||||||
|
:array_size_name => 'size|len',
|
||||||
|
:skeleton => false,
|
||||||
|
|
||||||
CMockDefaultOptions =
|
# Format to look for inline functions.
|
||||||
{
|
# This is a combination of "static" and "inline" keywords ("static inline", "inline static", "inline", "static")
|
||||||
:framework => :unity,
|
# There are several possibilities:
|
||||||
:mock_path => 'mocks',
|
# - sometimes they appear together, sometimes individually,
|
||||||
:mock_prefix => 'Mock',
|
# - The keywords can appear before or after the return type (this is a compiler warning but people do weird stuff),
|
||||||
:mock_suffix => '',
|
# so we check for word boundaries when searching for them
|
||||||
:skeleton_path => '',
|
# - We first remove "static inline" combinations and boil down to single inline or static statements
|
||||||
:weak => '',
|
:inline_function_patterns => ['(static\s+inline|inline\s+static)\s*', '(\bstatic\b|\binline\b)\s*'] # Last part (\s*) is just to remove whitespaces (only to prettify the output)
|
||||||
:subdir => nil,
|
}.freeze
|
||||||
:plugins => [],
|
|
||||||
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
|
|
||||||
:attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'],
|
|
||||||
:c_calling_conventions => ['__stdcall', '__cdecl', '__fastcall'],
|
|
||||||
:enforce_strict_ordering => false,
|
|
||||||
:fail_on_unexpected_calls => true,
|
|
||||||
:unity_helper_path => false,
|
|
||||||
:treat_as => {},
|
|
||||||
:treat_as_array => {},
|
|
||||||
:treat_as_void => [],
|
|
||||||
:memcmp_if_unknown => true,
|
|
||||||
:when_no_prototypes => :warn, #the options being :ignore, :warn, or :error
|
|
||||||
:when_ptr => :compare_data, #the options being :compare_ptr, :compare_data, or :smart
|
|
||||||
:verbosity => 2, #the options being 0 errors only, 1 warnings and errors, 2 normal info, 3 verbose
|
|
||||||
:treat_externs => :exclude, #the options being :include or :exclude
|
|
||||||
:treat_inlines => :exclude, #the options being :include or :exclude
|
|
||||||
:callback_include_count => true,
|
|
||||||
:callback_after_arg_check => false,
|
|
||||||
:includes => nil,
|
|
||||||
:includes_h_pre_orig_header => nil,
|
|
||||||
:includes_h_post_orig_header => nil,
|
|
||||||
:includes_c_pre_header => nil,
|
|
||||||
:includes_c_post_header => nil,
|
|
||||||
:orig_header_include_fmt => "#include \"%s\"",
|
|
||||||
:array_size_type => [],
|
|
||||||
:array_size_name => 'size|len',
|
|
||||||
:skeleton => false,
|
|
||||||
|
|
||||||
# Format to look for inline functions.
|
def initialize(options = nil)
|
||||||
# This is a combination of "static" and "inline" keywords ("static inline", "inline static", "inline", "static")
|
case options
|
||||||
# There are several possibilities:
|
when NilClass then options = CMOCK_DEFAULT_OPTIONS.dup
|
||||||
# - sometimes they appear together, sometimes individually,
|
when String then options = CMOCK_DEFAULT_OPTIONS.dup.merge(load_config_file_from_yaml(options))
|
||||||
# - The keywords can appear before or after the return type (this is a compiler warning but people do weird stuff),
|
when Hash then options = CMOCK_DEFAULT_OPTIONS.dup.merge(options)
|
||||||
# so we check for word boundaries when searching for them
|
else raise 'If you specify arguments, it should be a filename or a hash of options'
|
||||||
# - We first remove "static inline" combinations and boil down to single inline or static statements
|
|
||||||
:inline_function_patterns => ['(static\s+inline|inline\s+static)\s*', '(\bstatic\b|\binline\b)\s*'], # Last part (\s*) is just to remove whitespaces (only to prettify the output)
|
|
||||||
}
|
|
||||||
|
|
||||||
def initialize(options=nil)
|
|
||||||
case(options)
|
|
||||||
when NilClass then options = CMockDefaultOptions.clone
|
|
||||||
when String then options = CMockDefaultOptions.clone.merge(load_config_file_from_yaml(options))
|
|
||||||
when Hash then options = CMockDefaultOptions.clone.merge(options)
|
|
||||||
else raise "If you specify arguments, it should be a filename or a hash of options"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#do some quick type verification
|
# do some quick type verification
|
||||||
[:plugins, :attributes, :treat_as_void].each do |opt|
|
%i[plugins attributes treat_as_void].each do |opt|
|
||||||
unless (options[opt].class == Array)
|
unless options[opt].class == Array
|
||||||
options[opt] = []
|
options[opt] = []
|
||||||
puts "WARNING: :#{opt.to_s} should be an array." unless (options[:verbosity] < 1)
|
puts "WARNING: :#{opt} should be an array." unless options[:verbosity] < 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
[:includes, :includes_h_pre_orig_header, :includes_h_post_orig_header, :includes_c_pre_header, :includes_c_post_header].each do |opt|
|
%i[includes includes_h_pre_orig_header includes_h_post_orig_header includes_c_pre_header includes_c_post_header].each do |opt|
|
||||||
unless (options[opt].nil? or (options[opt].class == Array))
|
unless options[opt].nil? || (options[opt].class == Array)
|
||||||
options[opt] = []
|
options[opt] = []
|
||||||
puts "WARNING: :#{opt.to_s} should be an array." unless (options[:verbosity] < 1)
|
puts "WARNING: :#{opt} should be an array." unless options[:verbosity] < 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
options[:unity_helper_path] ||= options[:unity_helper]
|
options[:unity_helper_path] ||= options[:unity_helper]
|
||||||
@@ -87,38 +86,38 @@ class CMockConfig
|
|||||||
end
|
end
|
||||||
|
|
||||||
options[:plugins].compact!
|
options[:plugins].compact!
|
||||||
options[:plugins].map! {|p| p.to_sym}
|
options[:plugins].map!(&:to_sym)
|
||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
treat_as_map = standard_treat_as_map()#.clone
|
treat_as_map = standard_treat_as_map # .clone
|
||||||
treat_as_map.merge!(@options[:treat_as])
|
treat_as_map.merge!(@options[:treat_as])
|
||||||
@options[:treat_as] = treat_as_map
|
@options[:treat_as] = treat_as_map
|
||||||
|
|
||||||
@options.each_key do |key|
|
@options.each_key do |key|
|
||||||
unless methods.include?(key)
|
unless methods.include?(key)
|
||||||
eval("def #{key.to_s}() return @options[:#{key.to_s}] end")
|
eval("def #{key}() return @options[:#{key}] end")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_config_file_from_yaml yaml_filename
|
def load_config_file_from_yaml(yaml_filename)
|
||||||
self.class.load_config_file_from_yaml yaml_filename
|
self.class.load_config_file_from_yaml yaml_filename
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load_config_file_from_yaml yaml_filename
|
def self.load_config_file_from_yaml(yaml_filename)
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
YAML.load_file(yaml_filename)[:cmock]
|
YAML.load_file(yaml_filename)[:cmock]
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_path(path)
|
def path(new_path)
|
||||||
@src_path = path
|
@src_path = new_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_unity_helper
|
def load_unity_helper
|
||||||
return nil unless (@options[:unity_helper_path])
|
return nil unless @options[:unity_helper_path]
|
||||||
|
|
||||||
return @options[:unity_helper_path].inject("") do |unity_helper, filename|
|
@options[:unity_helper_path].inject('') do |unity_helper, filename|
|
||||||
unity_helper + "\n" + File.new(filename).read
|
unity_helper + "\n" + File.new(filename).read
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockFileWriter
|
class CMockFileWriter
|
||||||
|
|
||||||
attr_reader :config
|
attr_reader :config
|
||||||
|
|
||||||
def initialize(config)
|
def initialize(config)
|
||||||
@@ -13,20 +12,16 @@ class CMockFileWriter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_subdir(subdir)
|
def create_subdir(subdir)
|
||||||
if !Dir.exists?("#{@config.mock_path}/")
|
require 'fileutils'
|
||||||
require 'fileutils'
|
FileUtils.mkdir_p "#{@config.mock_path}/" unless Dir.exist?("#{@config.mock_path}/")
|
||||||
FileUtils.mkdir_p "#{@config.mock_path}/"
|
FileUtils.mkdir_p "#{@config.mock_path}/#{subdir + '/' if subdir}" if subdir && !Dir.exist?("#{@config.mock_path}/#{subdir + '/' if subdir}")
|
||||||
end
|
|
||||||
if subdir && !Dir.exists?("#{@config.mock_path}/#{subdir+'/' if subdir}")
|
|
||||||
require 'fileutils'
|
|
||||||
FileUtils.mkdir_p "#{@config.mock_path}/#{subdir+'/' if subdir}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_file(filename, subdir)
|
def create_file(filename, subdir)
|
||||||
raise "Where's the block of data to create?" unless block_given?
|
raise "Where's the block of data to create?" unless block_given?
|
||||||
full_file_name_temp = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}.new"
|
|
||||||
full_file_name_done = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}"
|
full_file_name_temp = "#{@config.mock_path}/#{subdir + '/' if subdir}#{filename}.new"
|
||||||
|
full_file_name_done = "#{@config.mock_path}/#{subdir + '/' if subdir}#{filename}"
|
||||||
File.open(full_file_name_temp, 'w') do |file|
|
File.open(full_file_name_temp, 'w') do |file|
|
||||||
yield(file, filename)
|
yield(file, filename)
|
||||||
end
|
end
|
||||||
@@ -35,7 +30,8 @@ class CMockFileWriter
|
|||||||
|
|
||||||
def append_file(filename, subdir)
|
def append_file(filename, subdir)
|
||||||
raise "Where's the block of data to create?" unless block_given?
|
raise "Where's the block of data to create?" unless block_given?
|
||||||
full_file_name = "#{@config.skeleton_path}/#{subdir+'/' if subdir}#{filename}"
|
|
||||||
|
full_file_name = "#{@config.skeleton_path}/#{subdir + '/' if subdir}#{filename}"
|
||||||
File.open(full_file_name, 'a') do |file|
|
File.open(full_file_name, 'a') do |file|
|
||||||
yield(file, filename)
|
yield(file, filename)
|
||||||
end
|
end
|
||||||
@@ -45,7 +41,7 @@ class CMockFileWriter
|
|||||||
|
|
||||||
def update_file(dest, src)
|
def update_file(dest, src)
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
FileUtils.rm(dest) if (File.exist?(dest))
|
FileUtils.rm(dest) if File.exist?(dest)
|
||||||
FileUtils.cp(src, dest)
|
FileUtils.cp(src, dest)
|
||||||
FileUtils.rm(src)
|
FileUtils.rm(src)
|
||||||
end
|
end
|
||||||
|
|||||||
+53
-55
@@ -5,7 +5,6 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockGenerator
|
class CMockGenerator
|
||||||
|
|
||||||
attr_accessor :config, :file_writer, :module_name, :module_ext, :clean_mock_name, :mock_name, :utils, :plugins, :weak, :ordered
|
attr_accessor :config, :file_writer, :module_name, :module_ext, :clean_mock_name, :mock_name, :utils, :plugins, :weak, :ordered
|
||||||
|
|
||||||
def initialize(config, file_writer, utils, plugins)
|
def initialize(config, file_writer, utils, plugins)
|
||||||
@@ -16,34 +15,33 @@ class CMockGenerator
|
|||||||
@prefix = @config.mock_prefix
|
@prefix = @config.mock_prefix
|
||||||
@suffix = @config.mock_suffix
|
@suffix = @config.mock_suffix
|
||||||
@weak = @config.weak
|
@weak = @config.weak
|
||||||
@include_inline = @config.treat_inlines
|
@include_inline = @config.treat_inlines
|
||||||
@ordered = @config.enforce_strict_ordering
|
@ordered = @config.enforce_strict_ordering
|
||||||
@framework = @config.framework.to_s
|
@framework = @config.framework.to_s
|
||||||
@fail_on_unexpected_calls = @config.fail_on_unexpected_calls
|
@fail_on_unexpected_calls = @config.fail_on_unexpected_calls
|
||||||
|
|
||||||
@subdir = @config.subdir
|
@subdir = @config.subdir
|
||||||
|
|
||||||
@includes_h_pre_orig_header = (@config.includes || @config.includes_h_pre_orig_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
|
@includes_h_pre_orig_header = (@config.includes || @config.includes_h_pre_orig_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }
|
||||||
@includes_h_post_orig_header = (@config.includes_h_post_orig_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
|
@includes_h_post_orig_header = (@config.includes_h_post_orig_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }
|
||||||
@includes_c_pre_header = (@config.includes_c_pre_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
|
@includes_c_pre_header = (@config.includes_c_pre_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }
|
||||||
@includes_c_post_header = (@config.includes_c_post_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
|
@includes_c_post_header = (@config.includes_c_post_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }
|
||||||
|
|
||||||
here = File.dirname __FILE__
|
here = File.dirname __FILE__
|
||||||
unity_path_in_ceedling = "#{here}/../../unity" # path to Unity from within Ceedling
|
unity_path_in_ceedling = "#{here}/../../unity" # path to Unity from within Ceedling
|
||||||
unity_path_in_cmock = "#{here}/../vendor/unity" # path to Unity from within CMock
|
unity_path_in_cmock = "#{here}/../vendor/unity" # path to Unity from within CMock
|
||||||
# path to Unity as specified by env var
|
# path to Unity as specified by env var
|
||||||
unity_path_in_env = ENV.has_key?("UNITY_DIR") ? File.expand_path(ENV.fetch("UNITY_DIR")) : nil
|
unity_path_in_env = ENV.key?('UNITY_DIR') ? File.expand_path(ENV.fetch('UNITY_DIR')) : nil
|
||||||
|
|
||||||
if unity_path_in_env and File.exist? unity_path_in_env
|
if unity_path_in_env && File.exist?(unity_path_in_env)
|
||||||
require "#{unity_path_in_env}/auto/type_sanitizer"
|
require "#{unity_path_in_env}/auto/type_sanitizer"
|
||||||
elsif File.exist? unity_path_in_ceedling
|
elsif File.exist? unity_path_in_ceedling
|
||||||
require "#{unity_path_in_ceedling}/auto/type_sanitizer"
|
require "#{unity_path_in_ceedling}/auto/type_sanitizer"
|
||||||
elsif File.exist? unity_path_in_cmock
|
elsif File.exist? unity_path_in_cmock
|
||||||
require "#{unity_path_in_cmock}/auto/type_sanitizer"
|
require "#{unity_path_in_cmock}/auto/type_sanitizer"
|
||||||
else
|
else
|
||||||
raise "Failed to find an instance of Unity to pull in type_sanitizer module!"
|
raise 'Failed to find an instance of Unity to pull in type_sanitizer module!'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_mock(module_name, parsed_stuff, module_ext = nil)
|
def create_mock(module_name, parsed_stuff, module_ext = nil)
|
||||||
@@ -51,7 +49,7 @@ class CMockGenerator
|
|||||||
@module_ext = module_ext || '.h'
|
@module_ext = module_ext || '.h'
|
||||||
@mock_name = @prefix + @module_name + @suffix
|
@mock_name = @prefix + @module_name + @suffix
|
||||||
@clean_mock_name = TypeSanitizer.sanitize_c_identifier(@mock_name)
|
@clean_mock_name = TypeSanitizer.sanitize_c_identifier(@mock_name)
|
||||||
create_mock_subdir()
|
create_mock_subdir
|
||||||
create_mock_header_file(parsed_stuff)
|
create_mock_header_file(parsed_stuff)
|
||||||
create_mock_source_file(parsed_stuff)
|
create_mock_source_file(parsed_stuff)
|
||||||
end
|
end
|
||||||
@@ -63,13 +61,13 @@ class CMockGenerator
|
|||||||
|
|
||||||
private if $ThisIsOnlyATest.nil? ##############################
|
private if $ThisIsOnlyATest.nil? ##############################
|
||||||
|
|
||||||
def create_mock_subdir()
|
def create_mock_subdir
|
||||||
@file_writer.create_subdir(@subdir)
|
@file_writer.create_subdir(@subdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_mock_header_file(parsed_stuff)
|
def create_mock_header_file(parsed_stuff)
|
||||||
if @include_inline == :include
|
if @include_inline == :include
|
||||||
@file_writer.create_file(@module_name + (@module_ext || '.h'), @subdir) do |file, filename|
|
@file_writer.create_file(@module_name + (@module_ext || '.h'), @subdir) do |file, _filename|
|
||||||
file << parsed_stuff[:normalized_source]
|
file << parsed_stuff[:normalized_source]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -86,7 +84,7 @@ class CMockGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_mock_source_file(parsed_stuff)
|
def create_mock_source_file(parsed_stuff)
|
||||||
@file_writer.create_file(@mock_name + ".c", @subdir) do |file, filename|
|
@file_writer.create_file(@mock_name + '.c', @subdir) do |file, filename|
|
||||||
create_source_header_section(file, filename, parsed_stuff[:functions])
|
create_source_header_section(file, filename, parsed_stuff[:functions])
|
||||||
create_instance_structure(file, parsed_stuff[:functions])
|
create_instance_structure(file, parsed_stuff[:functions])
|
||||||
create_extern_declarations(file)
|
create_extern_declarations(file)
|
||||||
@@ -101,9 +99,9 @@ class CMockGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_skeleton_source_file(parsed_stuff)
|
def create_skeleton_source_file(parsed_stuff)
|
||||||
filename = "#{@config.mock_path}/#{@subdir+'/' if @subdir}#{module_name}.c"
|
filename = "#{@config.mock_path}/#{@subdir + '/' if @subdir}#{module_name}.c"
|
||||||
existing = File.exists?(filename) ? File.read(filename) : ""
|
existing = File.exist?(filename) ? File.read(filename) : ''
|
||||||
@file_writer.append_file(@module_name + ".c", @subdir) do |file, fullname|
|
@file_writer.append_file(@module_name + '.c', @subdir) do |file, fullname|
|
||||||
create_source_header_section(file, fullname, []) if existing.empty?
|
create_source_header_section(file, fullname, []) if existing.empty?
|
||||||
parsed_stuff[:functions].each do |function|
|
parsed_stuff[:functions].each do |function|
|
||||||
create_function_skeleton(file, function, existing)
|
create_function_skeleton(file, function, existing)
|
||||||
@@ -111,18 +109,18 @@ class CMockGenerator
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_mock_header_header(file, filename)
|
def create_mock_header_header(file, _filename)
|
||||||
define_name = @clean_mock_name.upcase
|
define_name = @clean_mock_name.upcase
|
||||||
orig_filename = (@subdir ? @subdir + "/" : "") + @module_name + (@module_ext || '.h')
|
orig_filename = (@subdir ? @subdir + '/' : '') + @module_name + (@module_ext || '.h')
|
||||||
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
|
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
|
||||||
file << "#ifndef _#{define_name}_H\n"
|
file << "#ifndef _#{define_name}_H\n"
|
||||||
file << "#define _#{define_name}_H\n\n"
|
file << "#define _#{define_name}_H\n\n"
|
||||||
file << "#include \"#{@framework}.h\"\n"
|
file << "#include \"#{@framework}.h\"\n"
|
||||||
@includes_h_pre_orig_header.each {|inc| file << "#include #{inc}\n"}
|
@includes_h_pre_orig_header.each { |inc| file << "#include #{inc}\n" }
|
||||||
file << @config.orig_header_include_fmt.gsub(/%s/, "#{orig_filename}") + "\n"
|
file << @config.orig_header_include_fmt.gsub(/%s/, orig_filename.to_s) + "\n"
|
||||||
@includes_h_post_orig_header.each {|inc| file << "#include #{inc}\n"}
|
@includes_h_post_orig_header.each { |inc| file << "#include #{inc}\n" }
|
||||||
plugin_includes = @plugins.run(:include_files)
|
plugin_includes = @plugins.run(:include_files)
|
||||||
file << plugin_includes if (!plugin_includes.empty?)
|
file << plugin_includes unless plugin_includes.empty?
|
||||||
file << "\n"
|
file << "\n"
|
||||||
file << "/* Ignore the following warnings, since we are copying code */\n"
|
file << "/* Ignore the following warnings, since we are copying code */\n"
|
||||||
file << "#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n"
|
file << "#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n"
|
||||||
@@ -140,7 +138,7 @@ class CMockGenerator
|
|||||||
|
|
||||||
def create_typedefs(file, typedefs)
|
def create_typedefs(file, typedefs)
|
||||||
file << "\n"
|
file << "\n"
|
||||||
typedefs.each {|typedef| file << "#{typedef}\n" }
|
typedefs.each { |typedef| file << "#{typedef}\n" }
|
||||||
file << "\n\n"
|
file << "\n\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -162,20 +160,20 @@ class CMockGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_source_header_section(file, filename, functions)
|
def create_source_header_section(file, filename, functions)
|
||||||
header_file = (@subdir ? @subdir + '/' : '') + filename.gsub(".c",(@module_ext || '.h'))
|
header_file = (@subdir ? @subdir + '/' : '') + filename.gsub('.c', (@module_ext || '.h'))
|
||||||
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" unless functions.empty?
|
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" unless functions.empty?
|
||||||
file << "#include <string.h>\n"
|
file << "#include <string.h>\n"
|
||||||
file << "#include <stdlib.h>\n"
|
file << "#include <stdlib.h>\n"
|
||||||
file << "#include <setjmp.h>\n"
|
file << "#include <setjmp.h>\n"
|
||||||
file << "#include \"cmock.h\"\n"
|
file << "#include \"cmock.h\"\n"
|
||||||
@includes_c_pre_header.each {|inc| file << "#include #{inc}\n"}
|
@includes_c_pre_header.each { |inc| file << "#include #{inc}\n" }
|
||||||
file << "#include \"#{header_file}\"\n"
|
file << "#include \"#{header_file}\"\n"
|
||||||
@includes_c_post_header.each {|inc| file << "#include #{inc}\n"}
|
@includes_c_post_header.each { |inc| file << "#include #{inc}\n" }
|
||||||
file << "\n"
|
file << "\n"
|
||||||
strs = []
|
strs = []
|
||||||
functions.each do |func|
|
functions.each do |func|
|
||||||
strs << func[:name]
|
strs << func[:name]
|
||||||
func[:args].each {|arg| strs << arg[:name] }
|
func[:args].each { |arg| strs << arg[:name] }
|
||||||
end
|
end
|
||||||
strs.uniq.sort.each do |str|
|
strs.uniq.sort.each do |str|
|
||||||
file << "static const char* CMockString_#{str} = \"#{str}\";\n"
|
file << "static const char* CMockString_#{str} = \"#{str}\";\n"
|
||||||
@@ -191,7 +189,7 @@ class CMockGenerator
|
|||||||
file << "\n} CMOCK_#{function[:name]}_CALL_INSTANCE;\n\n"
|
file << "\n} CMOCK_#{function[:name]}_CALL_INSTANCE;\n\n"
|
||||||
end
|
end
|
||||||
file << "static struct #{@clean_mock_name}Instance\n{\n"
|
file << "static struct #{@clean_mock_name}Instance\n{\n"
|
||||||
if (functions.size == 0)
|
if functions.empty?
|
||||||
file << " unsigned char placeHolder;\n"
|
file << " unsigned char placeHolder;\n"
|
||||||
end
|
end
|
||||||
functions.each do |function|
|
functions.each do |function|
|
||||||
@@ -203,7 +201,7 @@ class CMockGenerator
|
|||||||
|
|
||||||
def create_extern_declarations(file)
|
def create_extern_declarations(file)
|
||||||
file << "extern jmp_buf AbortFrame;\n"
|
file << "extern jmp_buf AbortFrame;\n"
|
||||||
if (@ordered)
|
if @ordered
|
||||||
file << "extern int GlobalExpectCount;\n"
|
file << "extern int GlobalExpectCount;\n"
|
||||||
file << "extern int GlobalVerifyOrder;\n"
|
file << "extern int GlobalVerifyOrder;\n"
|
||||||
end
|
end
|
||||||
@@ -234,13 +232,13 @@ class CMockGenerator
|
|||||||
file << "void #{@clean_mock_name}_Destroy(void)\n{\n"
|
file << "void #{@clean_mock_name}_Destroy(void)\n{\n"
|
||||||
file << " CMock_Guts_MemFreeAll();\n"
|
file << " CMock_Guts_MemFreeAll();\n"
|
||||||
file << " memset(&Mock, 0, sizeof(Mock));\n"
|
file << " memset(&Mock, 0, sizeof(Mock));\n"
|
||||||
file << functions.collect {|function| @plugins.run(:mock_destroy, function)}.join
|
file << functions.collect { |function| @plugins.run(:mock_destroy, function) }.join
|
||||||
|
|
||||||
unless (@fail_on_unexpected_calls)
|
unless @fail_on_unexpected_calls
|
||||||
file << functions.collect {|function| @plugins.run(:mock_ignore, function)}.join
|
file << functions.collect { |function| @plugins.run(:mock_ignore, function) }.join
|
||||||
end
|
end
|
||||||
|
|
||||||
if (@ordered)
|
if @ordered
|
||||||
file << " GlobalExpectCount = 0;\n"
|
file << " GlobalExpectCount = 0;\n"
|
||||||
file << " GlobalVerifyOrder = 0;\n"
|
file << " GlobalVerifyOrder = 0;\n"
|
||||||
end
|
end
|
||||||
@@ -253,15 +251,15 @@ class CMockGenerator
|
|||||||
(function[:return][:type]) +
|
(function[:return][:type]) +
|
||||||
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
|
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
|
||||||
args_string = function[:args_string]
|
args_string = function[:args_string]
|
||||||
args_string += (", " + function[:var_arg]) unless (function[:var_arg].nil?)
|
args_string += (', ' + function[:var_arg]) unless function[:var_arg].nil?
|
||||||
|
|
||||||
# Create mock function
|
# Create mock function
|
||||||
if (not @weak.empty?)
|
unless @weak.empty?
|
||||||
file << "#if defined (__IAR_SYSTEMS_ICC__)\n"
|
file << "#if defined (__IAR_SYSTEMS_ICC__)\n"
|
||||||
file << "#pragma weak #{function[:name]}\n"
|
file << "#pragma weak #{function[:name]}\n"
|
||||||
file << "#else\n"
|
file << "#else\n"
|
||||||
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string}) #{weak};\n"
|
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string}) #{weak};\n"
|
||||||
file << "#endif\n\n"
|
file << "#endif\n\n"
|
||||||
end
|
end
|
||||||
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
|
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
|
||||||
file << "{\n"
|
file << "{\n"
|
||||||
@@ -273,7 +271,7 @@ class CMockGenerator
|
|||||||
file << @plugins.run(:mock_implementation_precheck, function)
|
file << @plugins.run(:mock_implementation_precheck, function)
|
||||||
file << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n"
|
file << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n"
|
||||||
file << " cmock_line = cmock_call_instance->LineNumber;\n"
|
file << " cmock_line = cmock_call_instance->LineNumber;\n"
|
||||||
if (@ordered)
|
if @ordered
|
||||||
file << " if (cmock_call_instance->CallOrder > ++GlobalVerifyOrder)\n"
|
file << " if (cmock_call_instance->CallOrder > ++GlobalVerifyOrder)\n"
|
||||||
file << " UNITY_TEST_FAIL(cmock_line, CMockStringCalledEarly);\n"
|
file << " UNITY_TEST_FAIL(cmock_line, CMockStringCalledEarly);\n"
|
||||||
file << " if (cmock_call_instance->CallOrder < GlobalVerifyOrder)\n"
|
file << " if (cmock_call_instance->CallOrder < GlobalVerifyOrder)\n"
|
||||||
@@ -281,7 +279,7 @@ class CMockGenerator
|
|||||||
end
|
end
|
||||||
file << @plugins.run(:mock_implementation, function)
|
file << @plugins.run(:mock_implementation, function)
|
||||||
file << " UNITY_CLR_DETAILS();\n"
|
file << " UNITY_CLR_DETAILS();\n"
|
||||||
file << " return cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?])
|
file << " return cmock_call_instance->ReturnVal;\n" unless function[:return][:void?]
|
||||||
file << "}\n\n"
|
file << "}\n\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -296,17 +294,17 @@ class CMockGenerator
|
|||||||
(function[:return][:type]) +
|
(function[:return][:type]) +
|
||||||
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
|
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
|
||||||
args_string = function[:args_string]
|
args_string = function[:args_string]
|
||||||
args_string += (", " + function[:var_arg]) unless (function[:var_arg].nil?)
|
args_string += (', ' + function[:var_arg]) unless function[:var_arg].nil?
|
||||||
|
|
||||||
decl = "#{function_mod_and_rettype} #{function[:name]}(#{args_string})"
|
decl = "#{function_mod_and_rettype} #{function[:name]}(#{args_string})"
|
||||||
|
|
||||||
unless (existing.include?(decl))
|
return if existing.include?(decl)
|
||||||
file << "#{decl}\n"
|
|
||||||
file << "{\n"
|
file << "#{decl}\n"
|
||||||
file << " //TODO: Implement Me!\n"
|
file << "{\n"
|
||||||
function[:args].each {|arg| file << " (void)#{arg[:name]};\n"}
|
file << " //TODO: Implement Me!\n"
|
||||||
file << " return (#{(function[:return][:type])})0;\n" unless (function[:return][:void?])
|
function[:args].each { |arg| file << " (void)#{arg[:name]};\n" }
|
||||||
file << "}\n\n"
|
file << " return (#{(function[:return][:type])})0;\n" unless function[:return][:void?]
|
||||||
end
|
file << "}\n\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockGeneratorPluginArray
|
class CMockGeneratorPluginArray
|
||||||
|
|
||||||
attr_reader :priority
|
attr_reader :priority
|
||||||
attr_accessor :config, :utils, :unity_helper, :ordered
|
attr_accessor :config, :utils, :unity_helper, :ordered
|
||||||
def initialize(config, utils)
|
def initialize(config, utils)
|
||||||
@@ -18,46 +17,47 @@ class CMockGeneratorPluginArray
|
|||||||
end
|
end
|
||||||
|
|
||||||
def instance_typedefs(function)
|
def instance_typedefs(function)
|
||||||
function[:args].inject("") do |all, arg|
|
function[:args].inject('') do |all, arg|
|
||||||
(arg[:ptr?]) ? all + " int Expected_#{arg[:name]}_Depth;\n" : all
|
arg[:ptr?] ? all + " int Expected_#{arg[:name]}_Depth;\n" : all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_function_declarations(function)
|
def mock_function_declarations(function)
|
||||||
return nil unless function[:contains_ptr?]
|
return nil unless function[:contains_ptr?]
|
||||||
args_call = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : "#{m[:name]}"}.join(', ')
|
|
||||||
|
args_call = function[:args].map { |m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : (m[:name]).to_s }.join(', ')
|
||||||
args_string = function[:args].map do |m|
|
args_string = function[:args].map do |m|
|
||||||
type = @utils.arg_type_with_const(m)
|
type = @utils.arg_type_with_const(m)
|
||||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||||
end.join(', ')
|
end.join(', ')
|
||||||
if (function[:return][:void?])
|
if function[:return][:void?]
|
||||||
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" +
|
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" \
|
||||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n"
|
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n"
|
||||||
else
|
else
|
||||||
return "#define #{function[:name]}_ExpectWithArrayAndReturn(#{args_call}, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, #{args_call}, cmock_retval)\n" +
|
return "#define #{function[:name]}_ExpectWithArrayAndReturn(#{args_call}, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, #{args_call}, cmock_retval)\n" \
|
||||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]});\n"
|
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]});\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_interfaces(function)
|
def mock_interfaces(function)
|
||||||
return nil unless function[:contains_ptr?]
|
return nil unless function[:contains_ptr?]
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
func_name = function[:name]
|
func_name = function[:name]
|
||||||
args_string = function[:args].map do |m|
|
args_string = function[:args].map do |m|
|
||||||
type = @utils.arg_type_with_const(m)
|
type = @utils.arg_type_with_const(m)
|
||||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||||
end.join(', ')
|
end.join(', ')
|
||||||
call_string = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name]}.join(', ')
|
call_string = function[:args].map { |m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name] }.join(', ')
|
||||||
if (function[:return][:void?])
|
lines << if function[:return][:void?]
|
||||||
lines << "void #{func_name}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string})\n"
|
"void #{func_name}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string})\n"
|
||||||
else
|
else
|
||||||
lines << "void #{func_name}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]})\n"
|
"void #{func_name}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]})\n"
|
||||||
end
|
end
|
||||||
lines << "{\n"
|
lines << "{\n"
|
||||||
lines << @utils.code_add_base_expectation(func_name)
|
lines << @utils.code_add_base_expectation(func_name)
|
||||||
lines << " CMockExpectParameters_#{func_name}(cmock_call_instance, #{call_string});\n"
|
lines << " CMockExpectParameters_#{func_name}(cmock_call_instance, #{call_string});\n"
|
||||||
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n" unless (function[:return][:void?])
|
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n" unless function[:return][:void?]
|
||||||
lines << "}\n\n"
|
lines << "}\n\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockGeneratorPluginCallback
|
class CMockGeneratorPluginCallback
|
||||||
|
|
||||||
attr_accessor :include_count
|
attr_accessor :include_count
|
||||||
attr_reader :priority
|
attr_reader :priority
|
||||||
attr_reader :config, :utils
|
attr_reader :config, :utils
|
||||||
@@ -30,7 +29,7 @@ class CMockGeneratorPluginCallback
|
|||||||
return_type = function[:return][:type]
|
return_type = function[:return][:type]
|
||||||
action = @config.callback_after_arg_check ? 'AddCallback' : 'Stub'
|
action = @config.callback_after_arg_check ? 'AddCallback' : 'Stub'
|
||||||
style = (@include_count ? 1 : 0) | (function[:args].empty? ? 0 : 2)
|
style = (@include_count ? 1 : 0) | (function[:args].empty? ? 0 : 2)
|
||||||
styles = [ "void", "int cmock_num_calls", function[:args_string], "#{function[:args_string]}, int cmock_num_calls" ]
|
styles = ['void', 'int cmock_num_calls', function[:args_string], "#{function[:args_string]}, int cmock_num_calls"]
|
||||||
"typedef #{return_type} (* CMOCK_#{func_name}_CALLBACK)(#{styles[style]});\n" \
|
"typedef #{return_type} (* CMOCK_#{func_name}_CALLBACK)(#{styles[style]});\n" \
|
||||||
"void #{func_name}_AddCallback(CMOCK_#{func_name}_CALLBACK Callback);\n" \
|
"void #{func_name}_AddCallback(CMOCK_#{func_name}_CALLBACK Callback);\n" \
|
||||||
"void #{func_name}_Stub(CMOCK_#{func_name}_CALLBACK Callback);\n" \
|
"void #{func_name}_Stub(CMOCK_#{func_name}_CALLBACK Callback);\n" \
|
||||||
@@ -69,7 +68,7 @@ class CMockGeneratorPluginCallback
|
|||||||
def mock_interfaces(function)
|
def mock_interfaces(function)
|
||||||
func_name = function[:name]
|
func_name = function[:name]
|
||||||
has_ignore = @config.plugins.include? :ignore
|
has_ignore = @config.plugins.include? :ignore
|
||||||
lines = ""
|
lines = ''
|
||||||
lines << "void #{func_name}_AddCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n"
|
lines << "void #{func_name}_AddCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n"
|
||||||
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if has_ignore
|
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if has_ignore
|
||||||
lines << " Mock.#{func_name}_CallbackBool = (int)1;\n"
|
lines << " Mock.#{func_name}_CallbackBool = (int)1;\n"
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockGeneratorPluginCexception
|
class CMockGeneratorPluginCexception
|
||||||
|
|
||||||
attr_reader :priority
|
attr_reader :priority
|
||||||
attr_reader :config, :utils
|
attr_reader :config, :utils
|
||||||
|
|
||||||
@@ -16,36 +15,35 @@ class CMockGeneratorPluginCexception
|
|||||||
end
|
end
|
||||||
|
|
||||||
def include_files
|
def include_files
|
||||||
return "#include \"CException.h\"\n"
|
"#include \"CException.h\"\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def instance_typedefs(function)
|
def instance_typedefs(_function)
|
||||||
" CEXCEPTION_T ExceptionToThrow;\n"
|
" CEXCEPTION_T ExceptionToThrow;\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_function_declarations(function)
|
def mock_function_declarations(function)
|
||||||
if (function[:args_string] == "void")
|
if function[:args_string] == 'void'
|
||||||
return "#define #{function[:name]}_ExpectAndThrow(cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n" +
|
"#define #{function[:name]}_ExpectAndThrow(cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n" \
|
||||||
"void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw);\n"
|
"void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw);\n"
|
||||||
else
|
else
|
||||||
return "#define #{function[:name]}_ExpectAndThrow(#{function[:args_call]}, cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, #{function[:args_call]}, cmock_to_throw)\n" +
|
"#define #{function[:name]}_ExpectAndThrow(#{function[:args_call]}, cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, #{function[:args_call]}, cmock_to_throw)\n" \
|
||||||
"void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, CEXCEPTION_T cmock_to_throw);\n"
|
"void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, CEXCEPTION_T cmock_to_throw);\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_implementation(function)
|
def mock_implementation(_function)
|
||||||
" if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n {\n" +
|
" if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n {\n" \
|
||||||
" UNITY_CLR_DETAILS();\n" +
|
" UNITY_CLR_DETAILS();\n" \
|
||||||
" Throw(cmock_call_instance->ExceptionToThrow);\n }\n"
|
" Throw(cmock_call_instance->ExceptionToThrow);\n }\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_interfaces(function)
|
def mock_interfaces(function)
|
||||||
arg_insert = (function[:args_string] == "void") ? "" : "#{function[:args_string]}, "
|
arg_insert = function[:args_string] == 'void' ? '' : "#{function[:args_string]}, "
|
||||||
[ "void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{arg_insert}CEXCEPTION_T cmock_to_throw)\n{\n",
|
["void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{arg_insert}CEXCEPTION_T cmock_to_throw)\n{\n",
|
||||||
@utils.code_add_base_expectation(function[:name]),
|
@utils.code_add_base_expectation(function[:name]),
|
||||||
@utils.code_call_argument_loader(function),
|
@utils.code_call_argument_loader(function),
|
||||||
" cmock_call_instance->ExceptionToThrow = cmock_to_throw;\n",
|
" cmock_call_instance->ExceptionToThrow = cmock_to_throw;\n",
|
||||||
"}\n\n" ].join
|
"}\n\n"].join
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockGeneratorPluginExpect
|
class CMockGeneratorPluginExpect
|
||||||
|
|
||||||
attr_reader :priority
|
attr_reader :priority
|
||||||
attr_accessor :config, :utils, :unity_helper, :ordered
|
attr_accessor :config, :utils, :unity_helper, :ordered
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ class CMockGeneratorPluginExpect
|
|||||||
@unity_helper = @utils.helpers[:unity_helper]
|
@unity_helper = @utils.helpers[:unity_helper]
|
||||||
@priority = 5
|
@priority = 5
|
||||||
|
|
||||||
if (@config.plugins.include? :expect_any_args)
|
if @config.plugins.include? :expect_any_args
|
||||||
alias :mock_implementation :mock_implementation_might_check_args
|
alias :mock_implementation :mock_implementation_might_check_args
|
||||||
else
|
else
|
||||||
alias :mock_implementation :mock_implementation_always_check_args
|
alias :mock_implementation :mock_implementation_always_check_args
|
||||||
@@ -25,9 +24,9 @@ class CMockGeneratorPluginExpect
|
|||||||
end
|
end
|
||||||
|
|
||||||
def instance_typedefs(function)
|
def instance_typedefs(function)
|
||||||
lines = ""
|
lines = ''
|
||||||
lines << " #{function[:return][:type]} ReturnVal;\n" unless (function[:return][:void?])
|
lines << " #{function[:return][:type]} ReturnVal;\n" unless function[:return][:void?]
|
||||||
lines << " int CallOrder;\n" if (@ordered)
|
lines << " int CallOrder;\n" if @ordered
|
||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
lines << " #{arg[:type]} Expected_#{arg[:name]};\n"
|
lines << " #{arg[:type]} Expected_#{arg[:name]};\n"
|
||||||
end
|
end
|
||||||
@@ -35,27 +34,25 @@ class CMockGeneratorPluginExpect
|
|||||||
end
|
end
|
||||||
|
|
||||||
def mock_function_declarations(function)
|
def mock_function_declarations(function)
|
||||||
if (function[:args].empty?)
|
if function[:args].empty?
|
||||||
if (function[:return][:void?])
|
if function[:return][:void?]
|
||||||
return "#define #{function[:name]}_Expect() #{function[:name]}_CMockExpect(__LINE__)\n" +
|
"#define #{function[:name]}_Expect() #{function[:name]}_CMockExpect(__LINE__)\n" \
|
||||||
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
|
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
|
||||||
else
|
else
|
||||||
return "#define #{function[:name]}_ExpectAndReturn(cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
|
"#define #{function[:name]}_ExpectAndReturn(cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, cmock_retval)\n" \
|
||||||
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||||
end
|
end
|
||||||
|
elsif function[:return][:void?]
|
||||||
|
"#define #{function[:name]}_Expect(#{function[:args_call]}) #{function[:name]}_CMockExpect(__LINE__, #{function[:args_call]})\n" \
|
||||||
|
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]});\n"
|
||||||
else
|
else
|
||||||
if (function[:return][:void?])
|
"#define #{function[:name]}_ExpectAndReturn(#{function[:args_call]}, cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, #{function[:args_call]}, cmock_retval)\n" \
|
||||||
return "#define #{function[:name]}_Expect(#{function[:args_call]}) #{function[:name]}_CMockExpect(__LINE__, #{function[:args_call]})\n" +
|
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]});\n"
|
||||||
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]});\n"
|
|
||||||
else
|
|
||||||
return "#define #{function[:name]}_ExpectAndReturn(#{function[:args_call]}, cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, #{function[:args_call]}, cmock_retval)\n" +
|
|
||||||
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]});\n"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_implementation_always_check_args(function)
|
def mock_implementation_always_check_args(function)
|
||||||
lines = ""
|
lines = ''
|
||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
lines << @utils.code_verify_an_arg_expectation(function, arg)
|
lines << @utils.code_verify_an_arg_expectation(function, arg)
|
||||||
end
|
end
|
||||||
@@ -63,7 +60,8 @@ class CMockGeneratorPluginExpect
|
|||||||
end
|
end
|
||||||
|
|
||||||
def mock_implementation_might_check_args(function)
|
def mock_implementation_might_check_args(function)
|
||||||
return "" if (function[:args].empty?)
|
return '' if function[:args].empty?
|
||||||
|
|
||||||
lines = " if (!cmock_call_instance->ExpectAnyArgsBool)\n {\n"
|
lines = " if (!cmock_call_instance->ExpectAnyArgsBool)\n {\n"
|
||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
lines << @utils.code_verify_an_arg_expectation(function, arg)
|
lines << @utils.code_verify_an_arg_expectation(function, arg)
|
||||||
@@ -73,24 +71,22 @@ class CMockGeneratorPluginExpect
|
|||||||
end
|
end
|
||||||
|
|
||||||
def mock_interfaces(function)
|
def mock_interfaces(function)
|
||||||
lines = ""
|
lines = ''
|
||||||
func_name = function[:name]
|
func_name = function[:name]
|
||||||
if (function[:return][:void?])
|
lines << if function[:return][:void?]
|
||||||
if (function[:args_string] == "void")
|
if function[:args_string] == 'void'
|
||||||
lines << "void #{func_name}_CMockExpect(UNITY_LINE_TYPE cmock_line)\n{\n"
|
"void #{func_name}_CMockExpect(UNITY_LINE_TYPE cmock_line)\n{\n"
|
||||||
else
|
else
|
||||||
lines << "void #{func_name}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]})\n{\n"
|
"void #{func_name}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]})\n{\n"
|
||||||
end
|
end
|
||||||
else
|
elsif function[:args_string] == 'void'
|
||||||
if (function[:args_string] == "void")
|
"void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||||
lines << "void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
else
|
||||||
else
|
"void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]})\n{\n"
|
||||||
lines << "void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]})\n{\n"
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
lines << @utils.code_add_base_expectation(func_name)
|
lines << @utils.code_add_base_expectation(func_name)
|
||||||
lines << @utils.code_call_argument_loader(function)
|
lines << @utils.code_call_argument_loader(function)
|
||||||
lines << @utils.code_assign_argument_quickly("cmock_call_instance->ReturnVal", function[:return]) unless (function[:return][:void?])
|
lines << @utils.code_assign_argument_quickly('cmock_call_instance->ReturnVal', function[:return]) unless function[:return][:void?]
|
||||||
lines << "}\n\n"
|
lines << "}\n\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockGeneratorPluginExpectAnyArgs
|
class CMockGeneratorPluginExpectAnyArgs
|
||||||
|
|
||||||
attr_reader :priority
|
attr_reader :priority
|
||||||
attr_reader :config, :utils
|
attr_reader :config, :utils
|
||||||
|
|
||||||
@@ -15,39 +14,37 @@ class CMockGeneratorPluginExpectAnyArgs
|
|||||||
@priority = 3
|
@priority = 3
|
||||||
end
|
end
|
||||||
|
|
||||||
def instance_typedefs(function)
|
def instance_typedefs(_function)
|
||||||
" int ExpectAnyArgsBool;\n"
|
" int ExpectAnyArgsBool;\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_function_declarations(function)
|
def mock_function_declarations(function)
|
||||||
unless (function[:args].empty?)
|
if function[:args].empty?
|
||||||
if (function[:return][:void?])
|
''
|
||||||
return "#define #{function[:name]}_ExpectAnyArgs() #{function[:name]}_CMockExpectAnyArgs(__LINE__)\n" +
|
elsif function[:return][:void?]
|
||||||
"void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
|
"#define #{function[:name]}_ExpectAnyArgs() #{function[:name]}_CMockExpectAnyArgs(__LINE__)\n" \
|
||||||
else
|
"void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
|
||||||
return "#define #{function[:name]}_ExpectAnyArgsAndReturn(cmock_retval) #{function[:name]}_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n" +
|
|
||||||
"void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
""
|
"#define #{function[:name]}_ExpectAnyArgsAndReturn(cmock_retval) #{function[:name]}_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n" \
|
||||||
|
"void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_interfaces(function)
|
def mock_interfaces(function)
|
||||||
lines = ""
|
lines = ''
|
||||||
unless (function[:args].empty?)
|
unless function[:args].empty?
|
||||||
if (function[:return][:void?])
|
lines << if function[:return][:void?]
|
||||||
lines << "void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n{\n"
|
"void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n{\n"
|
||||||
else
|
else
|
||||||
lines << "void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
"void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||||
end
|
end
|
||||||
lines << @utils.code_add_base_expectation(function[:name], true)
|
lines << @utils.code_add_base_expectation(function[:name], true)
|
||||||
unless (function[:return][:void?])
|
unless function[:return][:void?]
|
||||||
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n"
|
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n"
|
||||||
end
|
end
|
||||||
lines << " cmock_call_instance->ExpectAnyArgsBool = (int)1;\n"
|
lines << " cmock_call_instance->ExpectAnyArgsBool = (int)1;\n"
|
||||||
lines << "}\n\n"
|
lines << "}\n\n"
|
||||||
end
|
end
|
||||||
return lines
|
lines
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockGeneratorPluginIgnore
|
class CMockGeneratorPluginIgnore
|
||||||
|
|
||||||
attr_reader :priority
|
attr_reader :priority
|
||||||
attr_reader :config, :utils
|
attr_reader :config, :utils
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ class CMockGeneratorPluginIgnore
|
|||||||
end
|
end
|
||||||
|
|
||||||
def instance_structure(function)
|
def instance_structure(function)
|
||||||
if (function[:return][:void?])
|
if function[:return][:void?]
|
||||||
" int #{function[:name]}_IgnoreBool;\n"
|
" int #{function[:name]}_IgnoreBool;\n"
|
||||||
else
|
else
|
||||||
" int #{function[:name]}_IgnoreBool;\n #{function[:return][:type]} #{function[:name]}_FinalReturn;\n"
|
" int #{function[:name]}_IgnoreBool;\n #{function[:return][:type]} #{function[:name]}_FinalReturn;\n"
|
||||||
@@ -24,11 +23,11 @@ class CMockGeneratorPluginIgnore
|
|||||||
end
|
end
|
||||||
|
|
||||||
def mock_function_declarations(function)
|
def mock_function_declarations(function)
|
||||||
if (function[:return][:void?])
|
if function[:return][:void?]
|
||||||
return "#define #{function[:name]}_Ignore() #{function[:name]}_CMockIgnore()\n" +
|
"#define #{function[:name]}_Ignore() #{function[:name]}_CMockIgnore()\n" \
|
||||||
"void #{function[:name]}_CMockIgnore(void);\n"
|
"void #{function[:name]}_CMockIgnore(void);\n"
|
||||||
else
|
else
|
||||||
return "#define #{function[:name]}_IgnoreAndReturn(cmock_retval) #{function[:name]}_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n" +
|
"#define #{function[:name]}_IgnoreAndReturn(cmock_retval) #{function[:name]}_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n" \
|
||||||
"void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
"void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -36,28 +35,28 @@ class CMockGeneratorPluginIgnore
|
|||||||
def mock_implementation_precheck(function)
|
def mock_implementation_precheck(function)
|
||||||
lines = " if (Mock.#{function[:name]}_IgnoreBool)\n {\n"
|
lines = " if (Mock.#{function[:name]}_IgnoreBool)\n {\n"
|
||||||
lines << " UNITY_CLR_DETAILS();\n"
|
lines << " UNITY_CLR_DETAILS();\n"
|
||||||
if (function[:return][:void?])
|
if function[:return][:void?]
|
||||||
lines << " return;\n }\n"
|
lines << " return;\n }\n"
|
||||||
else
|
else
|
||||||
retval = function[:return].merge( { :name => "cmock_call_instance->ReturnVal"} )
|
retval = function[:return].merge(:name => 'cmock_call_instance->ReturnVal')
|
||||||
lines << " if (cmock_call_instance == NULL)\n return Mock.#{function[:name]}_FinalReturn;\n"
|
lines << " if (cmock_call_instance == NULL)\n return Mock.#{function[:name]}_FinalReturn;\n"
|
||||||
lines << " " + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless (retval[:void?])
|
lines << ' ' + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless retval[:void?]
|
||||||
lines << " return cmock_call_instance->ReturnVal;\n }\n"
|
lines << " return cmock_call_instance->ReturnVal;\n }\n"
|
||||||
end
|
end
|
||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_interfaces(function)
|
def mock_interfaces(function)
|
||||||
lines = ""
|
lines = ''
|
||||||
if (function[:return][:void?])
|
lines << if function[:return][:void?]
|
||||||
lines << "void #{function[:name]}_CMockIgnore(void)\n{\n"
|
"void #{function[:name]}_CMockIgnore(void)\n{\n"
|
||||||
else
|
else
|
||||||
lines << "void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
"void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||||
end
|
end
|
||||||
if (!function[:return][:void?])
|
unless function[:return][:void?]
|
||||||
lines << @utils.code_add_base_expectation(function[:name], false)
|
lines << @utils.code_add_base_expectation(function[:name], false)
|
||||||
end
|
end
|
||||||
unless (function[:return][:void?])
|
unless function[:return][:void?]
|
||||||
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n"
|
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n"
|
||||||
end
|
end
|
||||||
lines << " Mock.#{function[:name]}_IgnoreBool = (int)1;\n"
|
lines << " Mock.#{function[:name]}_IgnoreBool = (int)1;\n"
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ class CMockGeneratorPluginIgnoreArg
|
|||||||
attr_reader :priority
|
attr_reader :priority
|
||||||
attr_accessor :utils
|
attr_accessor :utils
|
||||||
|
|
||||||
def initialize(config, utils)
|
def initialize(_config, utils)
|
||||||
@utils = utils
|
@utils = utils
|
||||||
@priority = 10
|
@priority = 10
|
||||||
end
|
end
|
||||||
|
|
||||||
def instance_typedefs(function)
|
def instance_typedefs(function)
|
||||||
lines = ""
|
lines = ''
|
||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
lines << " int IgnoreArg_#{arg[:name]};\n"
|
lines << " int IgnoreArg_#{arg[:name]};\n"
|
||||||
end
|
end
|
||||||
@@ -16,7 +16,7 @@ class CMockGeneratorPluginIgnoreArg
|
|||||||
end
|
end
|
||||||
|
|
||||||
def mock_function_declarations(function)
|
def mock_function_declarations(function)
|
||||||
lines = ""
|
lines = ''
|
||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
lines << "#define #{function[:name]}_IgnoreArg_#{arg[:name]}()"
|
lines << "#define #{function[:name]}_IgnoreArg_#{arg[:name]}()"
|
||||||
lines << " #{function[:name]}_CMockIgnoreArg_#{arg[:name]}(__LINE__)\n"
|
lines << " #{function[:name]}_CMockIgnoreArg_#{arg[:name]}(__LINE__)\n"
|
||||||
@@ -31,8 +31,8 @@ class CMockGeneratorPluginIgnoreArg
|
|||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
lines << "void #{func_name}_CMockIgnoreArg_#{arg[:name]}(UNITY_LINE_TYPE cmock_line)\n"
|
lines << "void #{func_name}_CMockIgnoreArg_#{arg[:name]}(UNITY_LINE_TYPE cmock_line)\n"
|
||||||
lines << "{\n"
|
lines << "{\n"
|
||||||
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " +
|
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " \
|
||||||
"(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n"
|
"(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n"
|
||||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n"
|
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n"
|
||||||
lines << " cmock_call_instance->IgnoreArg_#{arg[:name]} = 1;\n"
|
lines << " cmock_call_instance->IgnoreArg_#{arg[:name]} = 1;\n"
|
||||||
lines << "}\n\n"
|
lines << "}\n\n"
|
||||||
|
|||||||
@@ -2,41 +2,41 @@ class CMockGeneratorPluginReturnThruPtr
|
|||||||
attr_reader :priority
|
attr_reader :priority
|
||||||
attr_accessor :utils
|
attr_accessor :utils
|
||||||
|
|
||||||
def initialize(config, utils)
|
def initialize(_config, utils)
|
||||||
@utils = utils
|
@utils = utils
|
||||||
@priority = 9
|
@priority = 9
|
||||||
end
|
end
|
||||||
|
|
||||||
def instance_typedefs(function)
|
def instance_typedefs(function)
|
||||||
lines = ""
|
lines = ''
|
||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
if (@utils.ptr_or_str?(arg[:type]) and not arg[:const?])
|
next unless @utils.ptr_or_str?(arg[:type]) && !(arg[:const?])
|
||||||
lines << " int ReturnThruPtr_#{arg[:name]}_Used;\n"
|
|
||||||
lines << " #{arg[:type]} ReturnThruPtr_#{arg[:name]}_Val;\n"
|
lines << " int ReturnThruPtr_#{arg[:name]}_Used;\n"
|
||||||
lines << " int ReturnThruPtr_#{arg[:name]}_Size;\n"
|
lines << " #{arg[:type]} ReturnThruPtr_#{arg[:name]}_Val;\n"
|
||||||
end
|
lines << " int ReturnThruPtr_#{arg[:name]}_Size;\n"
|
||||||
end
|
end
|
||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_function_declarations(function)
|
def mock_function_declarations(function)
|
||||||
lines = ""
|
lines = ''
|
||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
if (@utils.ptr_or_str?(arg[:type]) and not arg[:const?])
|
next unless @utils.ptr_or_str?(arg[:type]) && !(arg[:const?])
|
||||||
lines << "#define #{function[:name]}_ReturnThruPtr_#{arg[:name]}(#{arg[:name]})"
|
|
||||||
# If the pointer type actually contains an asterisk, we can do sizeof the type (super safe), otherwise
|
lines << "#define #{function[:name]}_ReturnThruPtr_#{arg[:name]}(#{arg[:name]})"
|
||||||
# we need to do a sizeof the dereferenced pointer (which could be a problem if give the wrong size
|
# If the pointer type actually contains an asterisk, we can do sizeof the type (super safe), otherwise
|
||||||
if (arg[:type][-1] == '*')
|
# we need to do a sizeof the dereferenced pointer (which could be a problem if give the wrong size
|
||||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(#{arg[:type][0..-2]}))\n"
|
lines << if arg[:type][-1] == '*'
|
||||||
else
|
" #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(#{arg[:type][0..-2]}))\n"
|
||||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(*#{arg[:name]}))\n"
|
else
|
||||||
end
|
" #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(*#{arg[:name]}))\n"
|
||||||
lines << "#define #{function[:name]}_ReturnArrayThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_len)"
|
end
|
||||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, (int)(cmock_len * (int)sizeof(*#{arg[:name]})))\n"
|
lines << "#define #{function[:name]}_ReturnArrayThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_len)"
|
||||||
lines << "#define #{function[:name]}_ReturnMemThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_size)"
|
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, (int)(cmock_len * (int)sizeof(*#{arg[:name]})))\n"
|
||||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, cmock_size)\n"
|
lines << "#define #{function[:name]}_ReturnMemThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_size)"
|
||||||
lines << "void #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(UNITY_LINE_TYPE cmock_line, #{arg[:type]} #{arg[:name]}, int cmock_size);\n"
|
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, cmock_size)\n"
|
||||||
end
|
lines << "void #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(UNITY_LINE_TYPE cmock_line, #{arg[:type]} #{arg[:name]}, int cmock_size);\n"
|
||||||
end
|
end
|
||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
@@ -46,17 +46,17 @@ class CMockGeneratorPluginReturnThruPtr
|
|||||||
func_name = function[:name]
|
func_name = function[:name]
|
||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
arg_name = arg[:name]
|
arg_name = arg[:name]
|
||||||
if (@utils.ptr_or_str?(arg[:type]) and not arg[:const?])
|
next unless @utils.ptr_or_str?(arg[:type]) && !(arg[:const?])
|
||||||
lines << "void #{func_name}_CMockReturnMemThruPtr_#{arg_name}(UNITY_LINE_TYPE cmock_line, #{arg[:type]} #{arg_name}, int cmock_size)\n"
|
|
||||||
lines << "{\n"
|
lines << "void #{func_name}_CMockReturnMemThruPtr_#{arg_name}(UNITY_LINE_TYPE cmock_line, #{arg[:type]} #{arg_name}, int cmock_size)\n"
|
||||||
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " +
|
lines << "{\n"
|
||||||
"(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n"
|
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " \
|
||||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringPtrPreExp);\n"
|
"(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n"
|
||||||
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Used = 1;\n"
|
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringPtrPreExp);\n"
|
||||||
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Val = #{arg_name};\n"
|
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Used = 1;\n"
|
||||||
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size = cmock_size;\n"
|
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Val = #{arg_name};\n"
|
||||||
lines << "}\n\n"
|
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size = cmock_size;\n"
|
||||||
end
|
lines << "}\n\n"
|
||||||
end
|
end
|
||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
@@ -65,14 +65,14 @@ class CMockGeneratorPluginReturnThruPtr
|
|||||||
lines = []
|
lines = []
|
||||||
function[:args].each do |arg|
|
function[:args].each do |arg|
|
||||||
arg_name = arg[:name]
|
arg_name = arg[:name]
|
||||||
if (@utils.ptr_or_str?(arg[:type]) and not arg[:const?])
|
next unless @utils.ptr_or_str?(arg[:type]) && !(arg[:const?])
|
||||||
lines << " if (cmock_call_instance->ReturnThruPtr_#{arg_name}_Used)\n"
|
|
||||||
lines << " {\n"
|
lines << " if (cmock_call_instance->ReturnThruPtr_#{arg_name}_Used)\n"
|
||||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(#{arg_name}, cmock_line, CMockStringPtrIsNULL);\n"
|
lines << " {\n"
|
||||||
lines << " memcpy((void*)#{arg_name}, (void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n"
|
lines << " UNITY_TEST_ASSERT_NOT_NULL(#{arg_name}, cmock_line, CMockStringPtrIsNULL);\n"
|
||||||
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size);\n"
|
lines << " memcpy((void*)#{arg_name}, (void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n"
|
||||||
lines << " }\n"
|
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size);\n"
|
||||||
end
|
lines << " }\n"
|
||||||
end
|
end
|
||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
|
|||||||
+119
-121
@@ -5,10 +5,9 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockGeneratorUtils
|
class CMockGeneratorUtils
|
||||||
|
|
||||||
attr_accessor :config, :helpers, :ordered, :ptr_handling, :arrays, :cexception
|
attr_accessor :config, :helpers, :ordered, :ptr_handling, :arrays, :cexception
|
||||||
|
|
||||||
def initialize(config, helpers={})
|
def initialize(config, helpers = {})
|
||||||
@config = config
|
@config = config
|
||||||
@ptr_handling = @config.when_ptr
|
@ptr_handling = @config.when_ptr
|
||||||
@ordered = @config.enforce_strict_ordering
|
@ordered = @config.enforce_strict_ordering
|
||||||
@@ -16,9 +15,9 @@ class CMockGeneratorUtils
|
|||||||
@cexception = @config.plugins.include? :cexception
|
@cexception = @config.plugins.include? :cexception
|
||||||
@expect_any = @config.plugins.include? :expect_any_args
|
@expect_any = @config.plugins.include? :expect_any_args
|
||||||
@return_thru_ptr = @config.plugins.include? :return_thru_ptr
|
@return_thru_ptr = @config.plugins.include? :return_thru_ptr
|
||||||
@ignore_arg = @config.plugins.include? :ignore_arg
|
@ignore_arg = @config.plugins.include? :ignore_arg
|
||||||
@ignore = @config.plugins.include? :ignore
|
@ignore = @config.plugins.include? :ignore
|
||||||
@treat_as = @config.treat_as
|
@treat_as = @config.treat_as
|
||||||
@helpers = helpers
|
@helpers = helpers
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -36,78 +35,78 @@ class CMockGeneratorUtils
|
|||||||
end
|
end
|
||||||
|
|
||||||
def code_verify_an_arg_expectation(function, arg)
|
def code_verify_an_arg_expectation(function, arg)
|
||||||
if (@arrays)
|
if @arrays
|
||||||
case(@ptr_handling)
|
case @ptr_handling
|
||||||
when :smart then code_verify_an_arg_expectation_with_smart_arrays(function, arg)
|
when :smart then code_verify_an_arg_expectation_with_smart_arrays(function, arg)
|
||||||
when :compare_data then code_verify_an_arg_expectation_with_normal_arrays(function, arg)
|
when :compare_data then code_verify_an_arg_expectation_with_normal_arrays(function, arg)
|
||||||
when :compare_ptr then raise "ERROR: the array plugin doesn't enjoy working with :compare_ptr only. Disable one option."
|
when :compare_ptr then raise "ERROR: the array plugin doesn't enjoy working with :compare_ptr only. Disable one option."
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
code_verify_an_arg_expectation_with_no_arrays(function, arg)
|
code_verify_an_arg_expectation_with_no_arrays(function, arg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def code_add_base_expectation(func_name, global_ordering_supported=true)
|
def code_add_base_expectation(func_name, global_ordering_supported = true)
|
||||||
lines = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_#{func_name}_CALL_INSTANCE));\n"
|
lines = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_#{func_name}_CALL_INSTANCE));\n"
|
||||||
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n"
|
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n"
|
||||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n"
|
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n"
|
||||||
lines << " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n"
|
lines << " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n"
|
||||||
lines << " Mock.#{func_name}_CallInstance = CMock_Guts_MemChain(Mock.#{func_name}_CallInstance, cmock_guts_index);\n"
|
lines << " Mock.#{func_name}_CallInstance = CMock_Guts_MemChain(Mock.#{func_name}_CallInstance, cmock_guts_index);\n"
|
||||||
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if (@ignore)
|
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if @ignore
|
||||||
lines << " cmock_call_instance->LineNumber = cmock_line;\n"
|
lines << " cmock_call_instance->LineNumber = cmock_line;\n"
|
||||||
lines << " cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" if (@ordered and global_ordering_supported)
|
lines << " cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" if @ordered && global_ordering_supported
|
||||||
lines << " cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n" if (@cexception)
|
lines << " cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n" if @cexception
|
||||||
lines << " cmock_call_instance->ExpectAnyArgsBool = (int)0;\n" if (@expect_any)
|
lines << " cmock_call_instance->ExpectAnyArgsBool = (int)0;\n" if @expect_any
|
||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
|
|
||||||
def code_add_an_arg_expectation(arg, depth=1)
|
def code_add_an_arg_expectation(arg, depth = 1)
|
||||||
lines = code_assign_argument_quickly("cmock_call_instance->Expected_#{arg[:name]}", arg)
|
lines = code_assign_argument_quickly("cmock_call_instance->Expected_#{arg[:name]}", arg)
|
||||||
lines << " cmock_call_instance->Expected_#{arg[:name]}_Depth = #{arg[:name]}_Depth;\n" if (@arrays and (depth.class == String))
|
lines << " cmock_call_instance->Expected_#{arg[:name]}_Depth = #{arg[:name]}_Depth;\n" if @arrays && (depth.class == String)
|
||||||
lines << " cmock_call_instance->IgnoreArg_#{arg[:name]} = 0;\n" if (@ignore_arg)
|
lines << " cmock_call_instance->IgnoreArg_#{arg[:name]} = 0;\n" if @ignore_arg
|
||||||
lines << " cmock_call_instance->ReturnThruPtr_#{arg[:name]}_Used = 0;\n" if (@return_thru_ptr and ptr_or_str?(arg[:type]) and not arg[:const?])
|
lines << " cmock_call_instance->ReturnThruPtr_#{arg[:name]}_Used = 0;\n" if @return_thru_ptr && ptr_or_str?(arg[:type]) && !(arg[:const?])
|
||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
|
|
||||||
def code_assign_argument_quickly(dest, arg)
|
def code_assign_argument_quickly(dest, arg)
|
||||||
if (arg[:ptr?] or @treat_as.include?(arg[:type]))
|
if arg[:ptr?] || @treat_as.include?(arg[:type])
|
||||||
" #{dest} = #{arg[:name]};\n"
|
" #{dest} = #{arg[:name]};\n"
|
||||||
else
|
else
|
||||||
assert_expr = "sizeof(#{arg[:name]}) == sizeof(#{arg[:type]}) ? 1 : -1"
|
assert_expr = "sizeof(#{arg[:name]}) == sizeof(#{arg[:type]}) ? 1 : -1"
|
||||||
comment = "/* add #{arg[:type]} to :treat_as_array if this causes an error */"
|
comment = "/* add #{arg[:type]} to :treat_as_array if this causes an error */"
|
||||||
" memcpy((void*)(&#{dest}), (void*)(&#{arg[:name]}),\n" +
|
" memcpy((void*)(&#{dest}), (void*)(&#{arg[:name]}),\n" \
|
||||||
" sizeof(#{arg[:type]}[#{assert_expr}])); #{comment}\n"
|
" sizeof(#{arg[:type]}[#{assert_expr}])); #{comment}\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def code_add_argument_loader(function)
|
def code_add_argument_loader(function)
|
||||||
if (function[:args_string] != "void")
|
if function[:args_string] != 'void'
|
||||||
if (@arrays)
|
if @arrays
|
||||||
args_string = function[:args].map do |m|
|
args_string = function[:args].map do |m|
|
||||||
type = arg_type_with_const(m)
|
type = arg_type_with_const(m)
|
||||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||||
end.join(', ')
|
end.join(', ')
|
||||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string});\n" +
|
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string});\n" \
|
||||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string})\n{\n" +
|
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string})\n{\n" +
|
||||||
function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg, (arg[:ptr?] ? "#{arg[:name]}_Depth" : 1) ) } +
|
function[:args].inject('') { |all, arg| all + code_add_an_arg_expectation(arg, (arg[:ptr?] ? "#{arg[:name]}_Depth" : 1)) } +
|
||||||
"}\n\n"
|
"}\n\n"
|
||||||
else
|
else
|
||||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]});\n" +
|
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]});\n" \
|
||||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]})\n{\n" +
|
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]})\n{\n" +
|
||||||
function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg) } +
|
function[:args].inject('') { |all, arg| all + code_add_an_arg_expectation(arg) } +
|
||||||
"}\n\n"
|
"}\n\n"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
""
|
''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def code_call_argument_loader(function)
|
def code_call_argument_loader(function)
|
||||||
if (function[:args_string] != "void")
|
if function[:args_string] != 'void'
|
||||||
args = function[:args].map do |m|
|
args = function[:args].map do |m|
|
||||||
if (@arrays and m[:ptr?] and not m[:array_data?])
|
if @arrays && m[:ptr?] && !(m[:array_data?])
|
||||||
"#{m[:name]}, 1"
|
"#{m[:name]}, 1"
|
||||||
elsif (@arrays and m[:array_size?])
|
elsif @arrays && m[:array_size?]
|
||||||
"#{m[:name]}, #{m[:name]}"
|
"#{m[:name]}, #{m[:name]}"
|
||||||
else
|
else
|
||||||
m[:name]
|
m[:name]
|
||||||
@@ -115,60 +114,60 @@ class CMockGeneratorUtils
|
|||||||
end
|
end
|
||||||
" CMockExpectParameters_#{function[:name]}(cmock_call_instance, #{args.join(', ')});\n"
|
" CMockExpectParameters_#{function[:name]}(cmock_call_instance, #{args.join(', ')});\n"
|
||||||
else
|
else
|
||||||
""
|
''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ptr_or_str?(arg_type)
|
def ptr_or_str?(arg_type)
|
||||||
return (arg_type.include? '*' or
|
(arg_type.include?('*') ||
|
||||||
@treat_as.fetch(arg_type, "").include? '*')
|
@treat_as.fetch(arg_type, '').include?('*'))
|
||||||
end
|
end
|
||||||
|
|
||||||
#private ######################
|
# private ######################
|
||||||
|
|
||||||
def lookup_expect_type(function, arg)
|
def lookup_expect_type(_function, arg)
|
||||||
c_type = arg[:type]
|
c_type = arg[:type]
|
||||||
arg_name = arg[:name]
|
arg_name = arg[:name]
|
||||||
expected = "cmock_call_instance->Expected_#{arg_name}"
|
expected = "cmock_call_instance->Expected_#{arg_name}"
|
||||||
ignore = "cmock_call_instance->IgnoreArg_#{arg_name}"
|
ignore = "cmock_call_instance->IgnoreArg_#{arg_name}"
|
||||||
unity_func = if ((arg[:ptr?]) and ((c_type =~ /\*\*/) or (@ptr_handling == :compare_ptr)))
|
unity_func = if (arg[:ptr?]) && ((c_type =~ /\*\*/) || (@ptr_handling == :compare_ptr))
|
||||||
['UNITY_TEST_ASSERT_EQUAL_PTR', '']
|
['UNITY_TEST_ASSERT_EQUAL_PTR', '']
|
||||||
else
|
else
|
||||||
(@helpers.nil? or @helpers[:unity_helper].nil?) ? ["UNITY_TEST_ASSERT_EQUAL",''] : @helpers[:unity_helper].get_helper(c_type)
|
@helpers.nil? || @helpers[:unity_helper].nil? ? ['UNITY_TEST_ASSERT_EQUAL', ''] : @helpers[:unity_helper].get_helper(c_type)
|
||||||
end
|
end
|
||||||
return c_type, arg_name, expected, ignore, unity_func[0], unity_func[1]
|
[c_type, arg_name, expected, ignore, unity_func[0], unity_func[1]]
|
||||||
end
|
end
|
||||||
|
|
||||||
def code_verify_an_arg_expectation_with_no_arrays(function, arg)
|
def code_verify_an_arg_expectation_with_no_arrays(function, arg)
|
||||||
c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg)
|
c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg)
|
||||||
lines = ""
|
lines = ''
|
||||||
lines << " if (!#{ignore})\n" if @ignore_arg
|
lines << " if (!#{ignore})\n" if @ignore_arg
|
||||||
lines << " {\n"
|
lines << " {\n"
|
||||||
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
||||||
case(unity_func)
|
case unity_func
|
||||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
when 'UNITY_TEST_ASSERT_EQUAL_MEMORY'
|
||||||
c_type_local = c_type.gsub(/\*$/,'')
|
c_type_local = c_type.gsub(/\*$/, '')
|
||||||
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n"
|
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n"
|
||||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
|
when 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY'
|
||||||
if (pre == '&')
|
if pre == '&'
|
||||||
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, CMockStringMismatch);\n"
|
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), cmock_line, CMockStringMismatch);\n"
|
||||||
else
|
|
||||||
lines << " if (#{pre}#{expected} == NULL)\n"
|
|
||||||
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
|
||||||
lines << " else\n"
|
|
||||||
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, CMockStringMismatch); }\n"
|
|
||||||
end
|
|
||||||
when /_ARRAY/
|
|
||||||
if (pre == '&')
|
|
||||||
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, CMockStringMismatch);\n"
|
|
||||||
else
|
|
||||||
lines << " if (#{pre}#{expected} == NULL)\n"
|
|
||||||
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
|
||||||
lines << " else\n"
|
|
||||||
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, CMockStringMismatch); }\n"
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
|
lines << " if (#{pre}#{expected} == NULL)\n"
|
||||||
|
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
||||||
|
lines << " else\n"
|
||||||
|
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), cmock_line, CMockStringMismatch); }\n"
|
||||||
|
end
|
||||||
|
when /_ARRAY/
|
||||||
|
if pre == '&'
|
||||||
|
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, CMockStringMismatch);\n"
|
||||||
|
else
|
||||||
|
lines << " if (#{pre}#{expected} == NULL)\n"
|
||||||
|
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
||||||
|
lines << " else\n"
|
||||||
|
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, CMockStringMismatch); }\n"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
|
||||||
end
|
end
|
||||||
lines << " }\n"
|
lines << " }\n"
|
||||||
lines
|
lines
|
||||||
@@ -176,35 +175,35 @@ class CMockGeneratorUtils
|
|||||||
|
|
||||||
def code_verify_an_arg_expectation_with_normal_arrays(function, arg)
|
def code_verify_an_arg_expectation_with_normal_arrays(function, arg)
|
||||||
c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg)
|
c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg)
|
||||||
depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
|
depth_name = arg[:ptr?] ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
|
||||||
lines = ""
|
lines = ''
|
||||||
lines << " if (!#{ignore})\n" if @ignore_arg
|
lines << " if (!#{ignore})\n" if @ignore_arg
|
||||||
lines << " {\n"
|
lines << " {\n"
|
||||||
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
||||||
case(unity_func)
|
case unity_func
|
||||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
when 'UNITY_TEST_ASSERT_EQUAL_MEMORY'
|
||||||
c_type_local = c_type.gsub(/\*$/,'')
|
c_type_local = c_type.gsub(/\*$/, '')
|
||||||
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n"
|
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n"
|
||||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
|
when 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY'
|
||||||
if (pre == '&')
|
if pre == '&'
|
||||||
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, CMockStringMismatch);\n"
|
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), cmock_line, CMockStringMismatch);\n"
|
||||||
else
|
|
||||||
lines << " if (#{pre}#{expected} == NULL)\n"
|
|
||||||
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
|
||||||
lines << " else\n"
|
|
||||||
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
|
|
||||||
end
|
|
||||||
when /_ARRAY/
|
|
||||||
if (pre == '&')
|
|
||||||
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch);\n"
|
|
||||||
else
|
|
||||||
lines << " if (#{pre}#{expected} == NULL)\n"
|
|
||||||
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
|
||||||
lines << " else\n"
|
|
||||||
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch); }\n"
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
|
lines << " if (#{pre}#{expected} == NULL)\n"
|
||||||
|
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
||||||
|
lines << " else\n"
|
||||||
|
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
|
||||||
|
end
|
||||||
|
when /_ARRAY/
|
||||||
|
if pre == '&'
|
||||||
|
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch);\n"
|
||||||
|
else
|
||||||
|
lines << " if (#{pre}#{expected} == NULL)\n"
|
||||||
|
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
||||||
|
lines << " else\n"
|
||||||
|
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch); }\n"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
|
||||||
end
|
end
|
||||||
lines << " }\n"
|
lines << " }\n"
|
||||||
lines
|
lines
|
||||||
@@ -212,40 +211,39 @@ class CMockGeneratorUtils
|
|||||||
|
|
||||||
def code_verify_an_arg_expectation_with_smart_arrays(function, arg)
|
def code_verify_an_arg_expectation_with_smart_arrays(function, arg)
|
||||||
c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg)
|
c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg)
|
||||||
depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
|
depth_name = arg[:ptr?] ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
|
||||||
lines = ""
|
lines = ''
|
||||||
lines << " if (!#{ignore})\n" if @ignore_arg
|
lines << " if (!#{ignore})\n" if @ignore_arg
|
||||||
lines << " {\n"
|
lines << " {\n"
|
||||||
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
||||||
case(unity_func)
|
case unity_func
|
||||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
when 'UNITY_TEST_ASSERT_EQUAL_MEMORY'
|
||||||
c_type_local = c_type.gsub(/\*$/,'')
|
c_type_local = c_type.gsub(/\*$/, '')
|
||||||
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n"
|
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n"
|
||||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
|
when 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY'
|
||||||
if (pre == '&')
|
if pre == '&'
|
||||||
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, CMockStringMismatch);\n"
|
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), #{depth_name}, cmock_line, CMockStringMismatch);\n"
|
||||||
else
|
|
||||||
lines << " if (#{pre}#{expected} == NULL)\n"
|
|
||||||
lines << " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
|
||||||
lines << ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : "")
|
|
||||||
lines << " else\n"
|
|
||||||
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
|
|
||||||
end
|
|
||||||
when /_ARRAY/
|
|
||||||
if (pre == '&')
|
|
||||||
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch);\n"
|
|
||||||
else
|
|
||||||
lines << " if (#{pre}#{expected} == NULL)\n"
|
|
||||||
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
|
||||||
lines << ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : "")
|
|
||||||
lines << " else\n"
|
|
||||||
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch); }\n"
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
|
lines << " if (#{pre}#{expected} == NULL)\n"
|
||||||
|
lines << " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
||||||
|
lines << (depth_name != 1 ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : '')
|
||||||
|
lines << " else\n"
|
||||||
|
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
|
||||||
|
end
|
||||||
|
when /_ARRAY/
|
||||||
|
if pre == '&'
|
||||||
|
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch);\n"
|
||||||
|
else
|
||||||
|
lines << " if (#{pre}#{expected} == NULL)\n"
|
||||||
|
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
|
||||||
|
lines << (depth_name != 1 ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : '')
|
||||||
|
lines << " else\n"
|
||||||
|
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch); }\n"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
|
||||||
end
|
end
|
||||||
lines << " }\n"
|
lines << " }\n"
|
||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
+136
-140
@@ -5,7 +5,6 @@
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockHeaderParser
|
class CMockHeaderParser
|
||||||
|
|
||||||
attr_accessor :funcs, :c_attr_noconst, :c_attributes, :treat_as_void, :treat_externs, :treat_inlines, :inline_function_patterns
|
attr_accessor :funcs, :c_attr_noconst, :c_attributes, :treat_as_void, :treat_externs, :treat_inlines, :inline_function_patterns
|
||||||
|
|
||||||
def initialize(cfg)
|
def initialize(cfg)
|
||||||
@@ -18,35 +17,35 @@ class CMockHeaderParser
|
|||||||
@treat_as_void = (['void'] + cfg.treat_as_void).uniq
|
@treat_as_void = (['void'] + cfg.treat_as_void).uniq
|
||||||
@function_declaration_parse_base_match = '([\w\s\*\(\),\[\]]+??)\(([\w\s\*\(\),\.\[\]+\-\/]*)\)'
|
@function_declaration_parse_base_match = '([\w\s\*\(\),\[\]]+??)\(([\w\s\*\(\),\.\[\]+\-\/]*)\)'
|
||||||
@declaration_parse_matcher = /#{@function_declaration_parse_base_match}$/m
|
@declaration_parse_matcher = /#{@function_declaration_parse_base_match}$/m
|
||||||
@standards = (['int','short','char','long','unsigned','signed'] + cfg.treat_as.keys).uniq
|
@standards = (%w[int short char long unsigned signed] + cfg.treat_as.keys).uniq
|
||||||
@array_size_name = cfg.array_size_name
|
@array_size_name = cfg.array_size_name
|
||||||
@array_size_type = (['int', 'size_t'] + cfg.array_size_type).uniq
|
@array_size_type = (%w[int size_t] + cfg.array_size_type).uniq
|
||||||
@when_no_prototypes = cfg.when_no_prototypes
|
@when_no_prototypes = cfg.when_no_prototypes
|
||||||
@local_as_void = @treat_as_void
|
@local_as_void = @treat_as_void
|
||||||
@verbosity = cfg.verbosity
|
@verbosity = cfg.verbosity
|
||||||
@treat_externs = cfg.treat_externs
|
@treat_externs = cfg.treat_externs
|
||||||
@treat_inlines = cfg.treat_inlines
|
@treat_inlines = cfg.treat_inlines
|
||||||
@inline_function_patterns = cfg.inline_function_patterns
|
@inline_function_patterns = cfg.inline_function_patterns
|
||||||
@c_strippables += ['extern'] if (@treat_externs == :include) #we'll need to remove the attribute if we're allowing externs
|
@c_strippables += ['extern'] if @treat_externs == :include # we'll need to remove the attribute if we're allowing externs
|
||||||
@c_strippables += ['inline'] if (@treat_inlines == :include) #we'll need to remove the attribute if we're allowing inlines
|
@c_strippables += ['inline'] if @treat_inlines == :include # we'll need to remove the attribute if we're allowing inlines
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(name, source)
|
def parse(name, source)
|
||||||
@module_name = name.gsub(/\W/,'')
|
@module_name = name.gsub(/\W/, '')
|
||||||
@typedefs = []
|
@typedefs = []
|
||||||
@funcs = []
|
@funcs = []
|
||||||
@normalized_source = nil
|
@normalized_source = nil
|
||||||
function_names = []
|
function_names = []
|
||||||
|
|
||||||
parse_functions( import_source(source) ).map do |decl|
|
parse_functions(import_source(source)).map do |decl|
|
||||||
func = parse_declaration(decl)
|
func = parse_declaration(decl)
|
||||||
unless (function_names.include? func[:name])
|
unless function_names.include? func[:name]
|
||||||
@funcs << func
|
@funcs << func
|
||||||
function_names << func[:name]
|
function_names << func[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@normalized_source = if (@treat_inlines == :include)
|
@normalized_source = if @treat_inlines == :include
|
||||||
transform_inline_functions(source)
|
transform_inline_functions(source)
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
@@ -55,24 +54,23 @@ class CMockHeaderParser
|
|||||||
{ :includes => nil,
|
{ :includes => nil,
|
||||||
:functions => @funcs,
|
:functions => @funcs,
|
||||||
:typedefs => @typedefs,
|
:typedefs => @typedefs,
|
||||||
:normalized_source => @normalized_source
|
:normalized_source => @normalized_source }
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private if $ThisIsOnlyATest.nil? ################
|
private if $ThisIsOnlyATest.nil? ################
|
||||||
|
|
||||||
def remove_nested_pairs_of_braces(source)
|
def remove_nested_pairs_of_braces(source)
|
||||||
# remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection)
|
# remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection)
|
||||||
if (RUBY_VERSION.split('.')[0].to_i > 1)
|
if RUBY_VERSION.split('.')[0].to_i > 1
|
||||||
#we assign a string first because (no joke) if Ruby 1.9.3 sees this line as a regex, it will crash.
|
# we assign a string first because (no joke) if Ruby 1.9.3 sees this line as a regex, it will crash.
|
||||||
r = "\\{([^\\{\\}]*|\\g<0>)*\\}"
|
r = '\\{([^\\{\\}]*|\\g<0>)*\\}'
|
||||||
source.gsub!(/#{r}/m, '{ }')
|
source.gsub!(/#{r}/m, '{ }')
|
||||||
else
|
else
|
||||||
while source.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
|
while source.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return source
|
source
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the number of pairs of braces/square brackets in the function provided by the user
|
# Return the number of pairs of braces/square brackets in the function provided by the user
|
||||||
@@ -83,22 +81,22 @@ class CMockHeaderParser
|
|||||||
total_pairs = 0
|
total_pairs = 0
|
||||||
|
|
||||||
source.each_char do |c|
|
source.each_char do |c|
|
||||||
if ("{" == c)
|
if c == '{'
|
||||||
curr_level += 1
|
curr_level += 1
|
||||||
total_pairs +=1
|
total_pairs += 1
|
||||||
is_function_start_found = true
|
is_function_start_found = true
|
||||||
elsif ("}" == c)
|
elsif c == '}'
|
||||||
curr_level -=1
|
curr_level -= 1
|
||||||
end
|
end
|
||||||
|
|
||||||
break if is_function_start_found && curr_level == 0 # We reached the end of the inline function body
|
break if is_function_start_found && curr_level == 0 # We reached the end of the inline function body
|
||||||
end
|
end
|
||||||
|
|
||||||
if 0 != curr_level
|
if curr_level != 0
|
||||||
total_pairs = 0 # Something is fishy about this source, not enough closing braces?
|
total_pairs = 0 # Something is fishy about this source, not enough closing braces?
|
||||||
end
|
end
|
||||||
|
|
||||||
return total_pairs
|
total_pairs
|
||||||
end
|
end
|
||||||
|
|
||||||
# Transform inline functions to regular functions in the source by the user
|
# Transform inline functions to regular functions in the source by the user
|
||||||
@@ -117,7 +115,7 @@ class CMockHeaderParser
|
|||||||
end
|
end
|
||||||
|
|
||||||
# let's clean up the encoding in case they've done anything weird with the characters we might find
|
# 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)
|
source = source.force_encoding('ISO-8859-1').encode('utf-8', :replace => nil)
|
||||||
|
|
||||||
# smush multiline macros into single line (checking for continuation character at end of line '\')
|
# smush multiline macros into single line (checking for continuation character at end of line '\')
|
||||||
# If the user uses a macro to declare an inline function,
|
# If the user uses a macro to declare an inline function,
|
||||||
@@ -141,15 +139,15 @@ class CMockHeaderParser
|
|||||||
loop do
|
loop do
|
||||||
inline_function_match = source.match(/#{format}/) # Search for inline function declaration
|
inline_function_match = source.match(/#{format}/) # Search for inline function declaration
|
||||||
|
|
||||||
break if nil == inline_function_match # No inline functions so nothing to do
|
break if inline_function_match.nil? # No inline functions so nothing to do
|
||||||
|
|
||||||
# 1. Determine if we are dealing with a user defined macro to declare inline functions
|
# 1. Determine if we are dealing with a user defined macro to declare inline functions
|
||||||
# If the end of the pre-match string is a macro-declaration-like string,
|
# If the end of the pre-match string is a macro-declaration-like string,
|
||||||
# we are dealing with a user defined macro to declare inline functions
|
# we are dealing with a user defined macro to declare inline functions
|
||||||
if /(#define\s*)\z/ === inline_function_match.pre_match
|
if /(#define\s*)\z/ =~ inline_function_match.pre_match
|
||||||
# Remove the macro from the source
|
# Remove the macro from the source
|
||||||
stripped_pre_match = inline_function_match.pre_match.sub(/(#define\s*)\z/,'')
|
stripped_pre_match = inline_function_match.pre_match.sub(/(#define\s*)\z/, '')
|
||||||
stripped_post_match = inline_function_match.post_match.sub(/\A(.*[\n]?)/,'')
|
stripped_post_match = inline_function_match.post_match.sub(/\A(.*[\n]?)/, '')
|
||||||
source = stripped_pre_match + stripped_post_match
|
source = stripped_pre_match + stripped_post_match
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
@@ -157,7 +155,7 @@ class CMockHeaderParser
|
|||||||
# 2. Determine if we are dealing with an inline function declaration iso function definition
|
# 2. Determine if we are dealing with an inline function declaration iso function definition
|
||||||
# If the start of the post-match string is a function-declaration-like string (something ending with semicolon after the function arguments),
|
# If the start of the post-match string is a function-declaration-like string (something ending with semicolon after the function arguments),
|
||||||
# we are dealing with a inline function declaration
|
# we are dealing with a inline function declaration
|
||||||
if /\A#{@function_declaration_parse_base_match}\s*;/m === inline_function_match.post_match
|
if /\A#{@function_declaration_parse_base_match}\s*;/m =~ inline_function_match.post_match
|
||||||
# Only remove the inline part from the function declaration, leaving the function declaration won't do any harm
|
# Only remove the inline part from the function declaration, leaving the function declaration won't do any harm
|
||||||
source = inline_function_match.pre_match + inline_function_match.post_match
|
source = inline_function_match.pre_match + inline_function_match.post_match
|
||||||
next
|
next
|
||||||
@@ -167,25 +165,24 @@ class CMockHeaderParser
|
|||||||
# Remove the function body to transform it into a 'normal' function.
|
# Remove the function body to transform it into a 'normal' function.
|
||||||
total_pairs_to_remove = count_number_of_pairs_of_braces_in_function(inline_function_match.post_match)
|
total_pairs_to_remove = count_number_of_pairs_of_braces_in_function(inline_function_match.post_match)
|
||||||
|
|
||||||
break if 0 == total_pairs_to_remove # Bad source?
|
break if total_pairs_to_remove == 0 # Bad source?
|
||||||
|
|
||||||
inline_function_stripped = inline_function_match.post_match
|
inline_function_stripped = inline_function_match.post_match
|
||||||
|
|
||||||
total_pairs_to_remove.times do
|
total_pairs_to_remove.times do
|
||||||
inline_function_stripped.sub!(/\s*#{square_bracket_pair_regex_format}/, ";") # Remove inline implementation (+ some whitespace because it's prettier)
|
inline_function_stripped.sub!(/\s*#{square_bracket_pair_regex_format}/, ';') # Remove inline implementation (+ some whitespace because it's prettier)
|
||||||
end
|
end
|
||||||
|
|
||||||
source = inline_function_match.pre_match + inline_function_stripped # Make new source with the inline function removed and move on to the next
|
source = inline_function_match.pre_match + inline_function_stripped # Make new source with the inline function removed and move on to the next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return source
|
source
|
||||||
end
|
end
|
||||||
|
|
||||||
def import_source(source)
|
def import_source(source)
|
||||||
|
|
||||||
# let's clean up the encoding in case they've done anything weird with the characters we might find
|
# 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)
|
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
|
# 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
|
# 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
|
||||||
@@ -197,16 +194,16 @@ class CMockHeaderParser
|
|||||||
|
|
||||||
# If user wants to mock inline functions,
|
# If user wants to mock inline functions,
|
||||||
# remove the (user specific) inline keywords before removing anything else to avoid missing an inline function
|
# remove the (user specific) inline keywords before removing anything else to avoid missing an inline function
|
||||||
if (@treat_inlines == :include)
|
if @treat_inlines == :include
|
||||||
@inline_function_patterns.each { |user_format_string|
|
@inline_function_patterns.each do |user_format_string|
|
||||||
source.gsub!(/#{user_format_string}/, '') # remove user defined inline function patterns
|
source.gsub!(/#{user_format_string}/, '') # remove user defined inline function patterns
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# smush multiline macros into single line (checking for continuation character at end of line '\')
|
# smush multiline macros into single line (checking for continuation character at end of line '\')
|
||||||
source.gsub!(/\s*\\\s*/m, ' ')
|
source.gsub!(/\s*\\\s*/m, ' ')
|
||||||
|
|
||||||
#remove comments (block and line, in three steps to ensure correct precedence)
|
# remove comments (block and line, in three steps to ensure correct precedence)
|
||||||
source.gsub!(/(?<!\*)\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks
|
source.gsub!(/(?<!\*)\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks
|
||||||
source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
|
source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
|
||||||
source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
|
source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
|
||||||
@@ -229,65 +226,64 @@ class CMockHeaderParser
|
|||||||
source.gsub!(/\s*=\s*['"a-zA-Z0-9_\.]+\s*/, '') # remove default value statements from argument lists
|
source.gsub!(/\s*=\s*['"a-zA-Z0-9_\.]+\s*/, '') # remove default value statements from argument lists
|
||||||
source.gsub!(/^(?:[\w\s]*\W)?typedef\W[^;]*/m, '') # remove typedef statements
|
source.gsub!(/^(?:[\w\s]*\W)?typedef\W[^;]*/m, '') # remove typedef statements
|
||||||
source.gsub!(/\)(\w)/, ') \1') # add space between parenthese and alphanumeric
|
source.gsub!(/\)(\w)/, ') \1') # add space between parenthese and alphanumeric
|
||||||
source.gsub!(/(^|\W+)(?:#{@c_strippables.join('|')})(?=$|\W+)/,'\1') unless @c_strippables.empty? # remove known attributes slated to be stripped
|
source.gsub!(/(^|\W+)(?:#{@c_strippables.join('|')})(?=$|\W+)/, '\1') unless @c_strippables.empty? # remove known attributes slated to be stripped
|
||||||
|
|
||||||
#scan standalone function pointers and remove them, because they can just be ignored
|
# scan standalone function pointers and remove them, because they can just be ignored
|
||||||
source.gsub!(/\w+\s*\(\s*\*\s*\w+\s*\)\s*\([^)]*\)\s*;/,';')
|
source.gsub!(/\w+\s*\(\s*\*\s*\w+\s*\)\s*\([^)]*\)\s*;/, ';')
|
||||||
|
|
||||||
#scan for functions which return function pointers, because they are a pain
|
# scan for functions which return function pointers, because they are a pain
|
||||||
source.gsub!(/([\w\s\*]+)\(*\(\s*\*([\w\s\*]+)\s*\(([\w\s\*,]*)\)\)\s*\(([\w\s\*,]*)\)\)*/) do |m|
|
source.gsub!(/([\w\s\*]+)\(*\(\s*\*([\w\s\*]+)\s*\(([\w\s\*,]*)\)\)\s*\(([\w\s\*,]*)\)\)*/) do |_m|
|
||||||
functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}"
|
functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}"
|
||||||
@typedefs << "typedef #{$1.strip}(*#{functype})(#{$4});"
|
@typedefs << "typedef #{Regexp.last_match(1).strip}(*#{functype})(#{Regexp.last_match(4)});"
|
||||||
"#{functype} #{$2.strip}(#{$3});"
|
"#{functype} #{Regexp.last_match(2).strip}(#{Regexp.last_match(3)});"
|
||||||
end
|
end
|
||||||
|
|
||||||
source = remove_nested_pairs_of_braces(source)
|
source = remove_nested_pairs_of_braces(source)
|
||||||
|
|
||||||
if (@treat_inlines == :include)
|
if @treat_inlines == :include
|
||||||
# Functions having "{ }" at this point are/were inline functions,
|
# Functions having "{ }" at this point are/were inline functions,
|
||||||
# User wants them in so 'disguise' them as normal functions with the ";"
|
# User wants them in so 'disguise' them as normal functions with the ";"
|
||||||
source.gsub!("{ }", ";")
|
source.gsub!('{ }', ';')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# remove function definitions by stripping off the arguments right now
|
# remove function definitions by stripping off the arguments right now
|
||||||
source.gsub!(/\([^\)]*\)\s*\{[^\}]*\}/m, ";")
|
source.gsub!(/\([^\)]*\)\s*\{[^\}]*\}/m, ';')
|
||||||
|
|
||||||
#drop extra white space to make the rest go faster
|
# drop extra white space to make the rest go faster
|
||||||
source.gsub!(/^\s+/, '') # remove extra white space from beginning of line
|
source.gsub!(/^\s+/, '') # remove extra white space from beginning of line
|
||||||
source.gsub!(/\s+$/, '') # remove extra white space from end of line
|
source.gsub!(/\s+$/, '') # remove extra white space from end of line
|
||||||
source.gsub!(/\s*\(\s*/, '(') # remove extra white space from before left parens
|
source.gsub!(/\s*\(\s*/, '(') # remove extra white space from before left parens
|
||||||
source.gsub!(/\s*\)\s*/, ')') # remove extra white space from before right parens
|
source.gsub!(/\s*\)\s*/, ')') # remove extra white space from before right parens
|
||||||
source.gsub!(/\s+/, ' ') # remove remaining extra white space
|
source.gsub!(/\s+/, ' ') # remove remaining extra white space
|
||||||
|
|
||||||
#split lines on semicolons and remove things that are obviously not what we are looking for
|
# split lines on semicolons and remove things that are obviously not what we are looking for
|
||||||
src_lines = source.split(/\s*;\s*/).uniq
|
src_lines = source.split(/\s*;\s*/).uniq
|
||||||
src_lines.delete_if {|line| line.strip.length == 0} # remove blank lines
|
src_lines.delete_if { |line| line.strip.empty? } # remove blank lines
|
||||||
src_lines.delete_if {|line| !(line =~ /[\w\s\*]+\(+\s*\*[\*\s]*[\w\s]+(?:\[[\w\s]*\]\s*)+\)+\s*\((?:[\w\s\*]*,?)*\s*\)/).nil?} #remove function pointer arrays
|
src_lines.delete_if { |line| !(line =~ /[\w\s\*]+\(+\s*\*[\*\s]*[\w\s]+(?:\[[\w\s]*\]\s*)+\)+\s*\((?:[\w\s\*]*,?)*\s*\)/).nil? } # remove function pointer arrays
|
||||||
|
|
||||||
unless (@treat_externs == :include)
|
unless @treat_externs == :include
|
||||||
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:extern)\s+/).nil?} # remove extern functions
|
src_lines.delete_if { |line| !(line =~ /(?:^|\s+)(?:extern)\s+/).nil? } # remove extern functions
|
||||||
end
|
end
|
||||||
|
|
||||||
unless (@treat_inlines == :include)
|
unless @treat_inlines == :include
|
||||||
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:inline)\s+/).nil?} # remove inline functions
|
src_lines.delete_if { |line| !(line =~ /(?:^|\s+)(?:inline)\s+/).nil? } # remove inline functions
|
||||||
end
|
end
|
||||||
|
|
||||||
src_lines.delete_if {|line| line.empty? } #drop empty lines
|
src_lines.delete_if(&:empty?) # drop empty lines
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_functions(source)
|
def parse_functions(source)
|
||||||
funcs = []
|
funcs = []
|
||||||
source.each {|line| funcs << line.strip.gsub(/\s+/, ' ') if (line =~ @declaration_parse_matcher)}
|
source.each { |line| funcs << line.strip.gsub(/\s+/, ' ') if line =~ @declaration_parse_matcher }
|
||||||
if funcs.empty?
|
if funcs.empty?
|
||||||
case @when_no_prototypes
|
case @when_no_prototypes
|
||||||
when :error
|
when :error
|
||||||
raise "ERROR: No function prototypes found!"
|
raise 'ERROR: No function prototypes found!'
|
||||||
when :warn
|
when :warn
|
||||||
puts "WARNING: No function prototypes found!" unless (@verbosity < 1)
|
puts 'WARNING: No function prototypes found!' unless @verbosity < 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return funcs
|
funcs
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_type_and_name(arg)
|
def parse_type_and_name(arg)
|
||||||
@@ -295,8 +291,8 @@ class CMockHeaderParser
|
|||||||
# to remove 'const' only when it applies to the pointer itself, not when it
|
# to remove 'const' only when it applies to the pointer itself, not when it
|
||||||
# applies to the type pointed to. For non-pointer types, remove any
|
# applies to the type pointed to. For non-pointer types, remove any
|
||||||
# occurrence of 'const'.
|
# occurrence of 'const'.
|
||||||
arg.gsub!(/(\w)\*/,'\1 *') # pull asterisks away from preceding word
|
arg.gsub!(/(\w)\*/, '\1 *') # pull asterisks away from preceding word
|
||||||
arg.gsub!(/\*(\w)/,'* \1') # pull asterisks away from following word
|
arg.gsub!(/\*(\w)/, '* \1') # pull asterisks away from following word
|
||||||
arg_array = arg.split
|
arg_array = arg.split
|
||||||
arg_info = divine_ptr_and_const(arg)
|
arg_info = divine_ptr_and_const(arg)
|
||||||
arg_info[:name] = arg_array[-1]
|
arg_info[:name] = arg_array[-1]
|
||||||
@@ -321,15 +317,15 @@ class CMockHeaderParser
|
|||||||
end
|
end
|
||||||
|
|
||||||
arg_info[:modifier] = attr_array.join(' ')
|
arg_info[:modifier] = attr_array.join(' ')
|
||||||
arg_info[:type] = type_array.join(' ').gsub(/\s+\*/,'*') # remove space before asterisks
|
arg_info[:type] = type_array.join(' ').gsub(/\s+\*/, '*') # remove space before asterisks
|
||||||
return arg_info
|
arg_info
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_args(arg_list)
|
def parse_args(arg_list)
|
||||||
args = []
|
args = []
|
||||||
arg_list.split(',').each do |arg|
|
arg_list.split(',').each do |arg|
|
||||||
arg.strip!
|
arg.strip!
|
||||||
return args if (arg =~ /^\s*((\.\.\.)|(void))\s*$/) # we're done if we reach void by itself or ...
|
return args if arg =~ /^\s*((\.\.\.)|(void))\s*$/ # we're done if we reach void by itself or ...
|
||||||
|
|
||||||
arg_info = parse_type_and_name(arg)
|
arg_info = parse_type_and_name(arg)
|
||||||
arg_info.delete(:modifier) # don't care about this
|
arg_info.delete(:modifier) # don't care about this
|
||||||
@@ -337,7 +333,7 @@ class CMockHeaderParser
|
|||||||
|
|
||||||
# in C, array arguments implicitly degrade to pointers
|
# in C, array arguments implicitly degrade to pointers
|
||||||
# make the translation explicit here to simplify later logic
|
# make the translation explicit here to simplify later logic
|
||||||
if @treat_as_array[arg_info[:type]] and not arg_info[:ptr?] then
|
if @treat_as_array[arg_info[:type]] && !(arg_info[:ptr?])
|
||||||
arg_info[:type] = "#{@treat_as_array[arg_info[:type]]}*"
|
arg_info[:type] = "#{@treat_as_array[arg_info[:type]]}*"
|
||||||
arg_info[:type] = "const #{arg_info[:type]}" if arg_info[:const?]
|
arg_info[:type] = "const #{arg_info[:type]}" if arg_info[:const?]
|
||||||
arg_info[:ptr?] = true
|
arg_info[:ptr?] = true
|
||||||
@@ -347,31 +343,35 @@ class CMockHeaderParser
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Try to find array pair in parameters following this pattern : <type> * <name>, <@array_size_type> <@array_size_name>
|
# Try to find array pair in parameters following this pattern : <type> * <name>, <@array_size_type> <@array_size_name>
|
||||||
args.each_with_index {|val, index|
|
args.each_with_index do |val, index|
|
||||||
next_index = index + 1
|
next_index = index + 1
|
||||||
if (args.length > next_index)
|
next unless args.length > next_index
|
||||||
if (val[:ptr?] == true and args[next_index][:name].match(@array_size_name) and @array_size_type.include?(args[next_index][:type]))
|
|
||||||
val[:array_data?] = true
|
|
||||||
args[next_index][:array_size?] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
return args
|
if (val[:ptr?] == true) && args[next_index][:name].match(@array_size_name) && @array_size_type.include?(args[next_index][:type])
|
||||||
|
val[:array_data?] = true
|
||||||
|
args[next_index][:array_size?] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
args
|
||||||
end
|
end
|
||||||
|
|
||||||
def divine_ptr(arg)
|
def divine_ptr(arg)
|
||||||
return false unless arg.include? '*'
|
return false unless arg.include? '*'
|
||||||
# treat "const char *" and similar as a string, not a pointer
|
# treat "const char *" and similar as a string, not a pointer
|
||||||
return false if /(^|\s)(const\s+)?char(\s+const)?\s*\*(?!.*\*)/ =~ arg
|
return false if /(^|\s)(const\s+)?char(\s+const)?\s*\*(?!.*\*)/ =~ arg
|
||||||
return true
|
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def divine_const(arg)
|
def divine_const(arg)
|
||||||
# a non-pointer arg containing "const" is a constant
|
# a non-pointer arg containing "const" is a constant
|
||||||
# an arg containing "const" before the last * is a pointer to a constant
|
# an arg containing "const" before the last * is a pointer to a constant
|
||||||
return ( arg.include?('*') ? (/(^|\s|\*)const(\s(\w|\s)*)?\*(?!.*\*)/ =~ arg)
|
if arg.include?('*') ? (/(^|\s|\*)const(\s(\w|\s)*)?\*(?!.*\*)/ =~ arg) : (/(^|\s)const(\s|$)/ =~ arg)
|
||||||
: (/(^|\s)const(\s|$)/ =~ arg) ) ? true : false
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def divine_ptr_and_const(arg)
|
def divine_ptr_and_const(arg)
|
||||||
@@ -381,14 +381,14 @@ class CMockHeaderParser
|
|||||||
divination[:const?] = divine_const(arg)
|
divination[:const?] = divine_const(arg)
|
||||||
|
|
||||||
# an arg containing "const" after the last * is a constant pointer
|
# an arg containing "const" after the last * is a constant pointer
|
||||||
divination[:const_ptr?] = (/\*(?!.*\*)\s*const(\s|$)/ =~ arg) ? true : false
|
divination[:const_ptr?] = /\*(?!.*\*)\s*const(\s|$)/ =~ arg ? true : false
|
||||||
|
|
||||||
return divination
|
divination
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_args(arg_list)
|
def clean_args(arg_list)
|
||||||
if ((@local_as_void.include?(arg_list.strip)) or (arg_list.empty?))
|
if @local_as_void.include?(arg_list.strip) || arg_list.empty?
|
||||||
return 'void'
|
'void'
|
||||||
else
|
else
|
||||||
c = 0
|
c = 0
|
||||||
# magically turn brackets into asterisks, also match for parentheses that come from macros
|
# magically turn brackets into asterisks, also match for parentheses that come from macros
|
||||||
@@ -399,48 +399,46 @@ class CMockHeaderParser
|
|||||||
arg_list.gsub!(/\*(\w)/, '* \1')
|
arg_list.gsub!(/\*(\w)/, '* \1')
|
||||||
|
|
||||||
# scan argument list for function pointers and replace them with custom types
|
# 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|
|
arg_list.gsub!(/([\w\s\*]+)\(+\s*\*[\*\s]*([\w\s]*)\s*\)+\s*\(((?:[\w\s\*]*,?)*)\s*\)*/) do |_m|
|
||||||
|
|
||||||
functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}"
|
functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}"
|
||||||
funcret = $1.strip
|
funcret = Regexp.last_match(1).strip
|
||||||
funcname = $2.strip
|
funcname = Regexp.last_match(2).strip
|
||||||
funcargs = $3.strip
|
funcargs = Regexp.last_match(3).strip
|
||||||
funconst = ''
|
funconst = ''
|
||||||
if (funcname.include? 'const')
|
if funcname.include? 'const'
|
||||||
funcname.gsub!('const','').strip!
|
funcname.gsub!('const', '').strip!
|
||||||
funconst = 'const '
|
funconst = 'const '
|
||||||
end
|
end
|
||||||
@typedefs << "typedef #{funcret}(*#{functype})(#{funcargs});"
|
@typedefs << "typedef #{funcret}(*#{functype})(#{funcargs});"
|
||||||
funcname = "cmock_arg#{c+=1}" if (funcname.empty?)
|
funcname = "cmock_arg#{c += 1}" if funcname.empty?
|
||||||
"#{functype} #{funconst}#{funcname}"
|
"#{functype} #{funconst}#{funcname}"
|
||||||
end
|
end
|
||||||
|
|
||||||
#scan argument list for function pointers with shorthand notation and replace them with custom types
|
# scan argument list for function pointers with shorthand notation and replace them with custom types
|
||||||
arg_list.gsub!(/([\w\s\*]+)+\s+(\w+)\s*\(((?:[\w\s\*]*,?)*)\s*\)*/) do |m|
|
arg_list.gsub!(/([\w\s\*]+)+\s+(\w+)\s*\(((?:[\w\s\*]*,?)*)\s*\)*/) do |_m|
|
||||||
|
|
||||||
functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}"
|
functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}"
|
||||||
funcret = $1.strip
|
funcret = Regexp.last_match(1).strip
|
||||||
funcname = $2.strip
|
funcname = Regexp.last_match(2).strip
|
||||||
funcargs = $3.strip
|
funcargs = Regexp.last_match(3).strip
|
||||||
funconst = ''
|
funconst = ''
|
||||||
if (funcname.include? 'const')
|
if funcname.include? 'const'
|
||||||
funcname.gsub!('const','').strip!
|
funcname.gsub!('const', '').strip!
|
||||||
funconst = 'const '
|
funconst = 'const '
|
||||||
end
|
end
|
||||||
@typedefs << "typedef #{funcret}(*#{functype})(#{funcargs});"
|
@typedefs << "typedef #{funcret}(*#{functype})(#{funcargs});"
|
||||||
funcname = "cmock_arg#{c+=1}" if (funcname.empty?)
|
funcname = "cmock_arg#{c += 1}" if funcname.empty?
|
||||||
"#{functype} #{funconst}#{funcname}"
|
"#{functype} #{funconst}#{funcname}"
|
||||||
end
|
end
|
||||||
|
|
||||||
#automatically name unnamed arguments (those that only had a type)
|
# automatically name unnamed arguments (those that only had a type)
|
||||||
arg_list.split(/\s*,\s*/).map { |arg|
|
arg_list.split(/\s*,\s*/).map do |arg|
|
||||||
parts = (arg.split - ['struct', 'union', 'enum', 'const', 'const*'])
|
parts = (arg.split - ['struct', 'union', 'enum', 'const', 'const*'])
|
||||||
if ((parts.size < 2) or (parts[-1][-1].chr == '*') or (@standards.include?(parts[-1])))
|
if (parts.size < 2) || (parts[-1][-1].chr == '*') || @standards.include?(parts[-1])
|
||||||
"#{arg} cmock_arg#{c+=1}"
|
"#{arg} cmock_arg#{c += 1}"
|
||||||
else
|
else
|
||||||
arg
|
arg
|
||||||
end
|
end
|
||||||
}.join(', ')
|
end.join(', ')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -450,10 +448,10 @@ class CMockHeaderParser
|
|||||||
regex_match = @declaration_parse_matcher.match(declaration)
|
regex_match = @declaration_parse_matcher.match(declaration)
|
||||||
raise "Failed parsing function declaration: '#{declaration}'" if regex_match.nil?
|
raise "Failed parsing function declaration: '#{declaration}'" if regex_match.nil?
|
||||||
|
|
||||||
#grab argument list
|
# grab argument list
|
||||||
args = regex_match[2].strip
|
args = regex_match[2].strip
|
||||||
|
|
||||||
#process function attributes, return type, and name
|
# process function attributes, return type, and name
|
||||||
parsed = parse_type_and_name(regex_match[1])
|
parsed = parse_type_and_name(regex_match[1])
|
||||||
|
|
||||||
decl[:name] = parsed[:name]
|
decl[:name] = parsed[:name]
|
||||||
@@ -463,66 +461,64 @@ class CMockHeaderParser
|
|||||||
end
|
end
|
||||||
|
|
||||||
rettype = parsed[:type]
|
rettype = parsed[:type]
|
||||||
rettype = 'void' if (@local_as_void.include?(rettype.strip))
|
rettype = 'void' if @local_as_void.include?(rettype.strip)
|
||||||
decl[:return] = { :type => rettype,
|
decl[:return] = { :type => rettype,
|
||||||
:name => 'cmock_to_return',
|
:name => 'cmock_to_return',
|
||||||
:str => "#{rettype} cmock_to_return",
|
:str => "#{rettype} cmock_to_return",
|
||||||
:void? => (rettype == 'void'),
|
:void? => (rettype == 'void'),
|
||||||
:ptr? => parsed[:ptr?],
|
:ptr? => parsed[:ptr?] || false,
|
||||||
:const? => parsed[:const?],
|
:const? => parsed[:const?] || false,
|
||||||
:const_ptr? => parsed[:const_ptr?]
|
:const_ptr? => parsed[:const_ptr?] || false }
|
||||||
}
|
|
||||||
|
|
||||||
#remove default argument statements from mock definitions
|
# remove default argument statements from mock definitions
|
||||||
args.gsub!(/=\s*[a-zA-Z0-9_\.]+\s*/, ' ')
|
args.gsub!(/=\s*[a-zA-Z0-9_\.]+\s*/, ' ')
|
||||||
|
|
||||||
#check for var args
|
# check for var args
|
||||||
if (args =~ /\.\.\./)
|
if args =~ /\.\.\./
|
||||||
decl[:var_arg] = args.match( /[\w\s]*\.\.\./ ).to_s.strip
|
decl[:var_arg] = args.match(/[\w\s]*\.\.\./).to_s.strip
|
||||||
if (args =~ /\,[\w\s]*\.\.\./)
|
args = if args =~ /\,[\w\s]*\.\.\./
|
||||||
args = args.gsub!(/\,[\w\s]*\.\.\./,'')
|
args.gsub!(/\,[\w\s]*\.\.\./, '')
|
||||||
else
|
else
|
||||||
args = 'void'
|
'void'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
decl[:var_arg] = nil
|
decl[:var_arg] = nil
|
||||||
end
|
end
|
||||||
args = clean_args(args)
|
args = clean_args(args)
|
||||||
decl[:args_string] = args
|
decl[:args_string] = args
|
||||||
decl[:args] = parse_args(args)
|
decl[:args] = parse_args(args)
|
||||||
decl[:args_call] = decl[:args].map{|a| a[:name]}.join(', ')
|
decl[:args_call] = decl[:args].map { |a| a[:name] }.join(', ')
|
||||||
decl[:contains_ptr?] = decl[:args].inject(false) {|ptr, arg| arg[:ptr?] ? true : ptr }
|
decl[:contains_ptr?] = decl[:args].inject(false) { |ptr, arg| arg[:ptr?] ? true : ptr }
|
||||||
|
|
||||||
if (decl[:return][:type].nil? or decl[:name].nil? or decl[:args].nil? or
|
if decl[:return][:type].nil? || decl[:name].nil? || decl[:args].nil? ||
|
||||||
decl[:return][:type].empty? or decl[:name].empty?)
|
decl[:return][:type].empty? || decl[:name].empty?
|
||||||
raise "Failed Parsing Declaration Prototype!\n" +
|
raise "Failed Parsing Declaration Prototype!\n" \
|
||||||
" declaration: '#{declaration}'\n" +
|
" declaration: '#{declaration}'\n" \
|
||||||
" modifier: '#{decl[:modifier]}'\n" +
|
" modifier: '#{decl[:modifier]}'\n" \
|
||||||
" return: #{prototype_inspect_hash(decl[:return])}\n" +
|
" return: #{prototype_inspect_hash(decl[:return])}\n" \
|
||||||
" function: '#{decl[:name]}'\n" +
|
" function: '#{decl[:name]}'\n" \
|
||||||
" args: #{prototype_inspect_array_of_hashes(decl[:args])}\n"
|
" args: #{prototype_inspect_array_of_hashes(decl[:args])}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
return decl
|
decl
|
||||||
end
|
end
|
||||||
|
|
||||||
def prototype_inspect_hash(hash)
|
def prototype_inspect_hash(hash)
|
||||||
pairs = []
|
pairs = []
|
||||||
hash.each_pair { |name, value| pairs << ":#{name} => #{"'" if (value.class == String)}#{value}#{"'" if (value.class == String)}" }
|
hash.each_pair { |name, value| pairs << ":#{name} => #{"'" if value.class == String}#{value}#{"'" if value.class == String}" }
|
||||||
return "{#{pairs.join(', ')}}"
|
"{#{pairs.join(', ')}}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def prototype_inspect_array_of_hashes(array)
|
def prototype_inspect_array_of_hashes(array)
|
||||||
hashes = []
|
hashes = []
|
||||||
array.each { |hash| hashes << prototype_inspect_hash(hash) }
|
array.each { |hash| hashes << prototype_inspect_hash(hash) }
|
||||||
case (array.size)
|
case array.size
|
||||||
when 0
|
when 0
|
||||||
return "[]"
|
return '[]'
|
||||||
when 1
|
when 1
|
||||||
return "[#{hashes[0]}]"
|
return "[#{hashes[0]}]"
|
||||||
else
|
else
|
||||||
return "[\n #{hashes.join("\n ")}\n ]\n"
|
return "[\n #{hashes.join("\n ")}\n ]\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
+20
-25
@@ -4,10 +4,7 @@
|
|||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
require 'thread'
|
|
||||||
|
|
||||||
class CMockPluginManager
|
class CMockPluginManager
|
||||||
|
|
||||||
attr_accessor :plugins
|
attr_accessor :plugins
|
||||||
|
|
||||||
def initialize(config, utils)
|
def initialize(config, utils)
|
||||||
@@ -15,41 +12,39 @@ class CMockPluginManager
|
|||||||
plugins_to_load = [:expect, config.plugins].flatten.uniq.compact
|
plugins_to_load = [:expect, config.plugins].flatten.uniq.compact
|
||||||
plugins_to_load.each do |plugin|
|
plugins_to_load.each do |plugin|
|
||||||
plugin_name = plugin.to_s
|
plugin_name = plugin.to_s
|
||||||
object_name = "CMockGeneratorPlugin" + camelize(plugin_name)
|
object_name = 'CMockGeneratorPlugin' + camelize(plugin_name)
|
||||||
self.class.plugin_require_mutex.synchronize { load_plugin(plugin_name, object_name, config, utils) }
|
self.class.mutex.synchronize { load_plugin(plugin_name, object_name, config, utils) }
|
||||||
end
|
end
|
||||||
@plugins.sort! {|a,b| a.priority <=> b.priority }
|
@plugins.sort! { |a, b| a.priority <=> b.priority }
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(method, args=nil)
|
def run(method, args = nil)
|
||||||
if args.nil?
|
if args.nil?
|
||||||
return @plugins.collect{ |plugin| plugin.send(method) if plugin.respond_to?(method) }.flatten.join
|
@plugins.collect { |plugin| plugin.send(method) if plugin.respond_to?(method) }.flatten.join
|
||||||
else
|
else
|
||||||
return @plugins.collect{ |plugin| plugin.send(method, args) if plugin.respond_to?(method) }.flatten.join
|
@plugins.collect { |plugin| plugin.send(method, args) if plugin.respond_to?(method) }.flatten.join
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def camelize(lower_case_and_underscored_word)
|
def camelize(lower_case_and_underscored_word)
|
||||||
lower_case_and_underscored_word.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
lower_case_and_underscored_word.gsub(/\/(.?)/) { '::' + Regexp.last_match(1).upcase }.gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def self.mutex
|
||||||
|
|
||||||
def self.plugin_require_mutex
|
|
||||||
@mutex ||= Mutex.new
|
@mutex ||= Mutex.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def load_plugin(plugin_name, object_name, config, utils)
|
def load_plugin(plugin_name, object_name, config, utils)
|
||||||
begin
|
unless Object.const_defined? object_name
|
||||||
unless (Object.const_defined? object_name)
|
file_name = "#{__dir__}/cmock_generator_plugin_#{plugin_name.downcase}.rb"
|
||||||
file_name = "#{File.expand_path(File.dirname(__FILE__))}/cmock_generator_plugin_#{plugin_name.downcase}.rb"
|
require file_name
|
||||||
require file_name
|
|
||||||
end
|
|
||||||
class_name = Object.const_get(object_name)
|
|
||||||
@plugins << class_name.new(config, utils)
|
|
||||||
rescue
|
|
||||||
file_name = "#{File.expand_path(File.dirname(__FILE__))}/cmock_generator_plugin_#{plugin_name.downcase}.rb"
|
|
||||||
raise "ERROR: CMock unable to load plugin '#{plugin_name}' '#{object_name}' #{file_name}"
|
|
||||||
end
|
end
|
||||||
|
class_name = Object.const_get(object_name)
|
||||||
|
@plugins << class_name.new(config, utils)
|
||||||
|
rescue StandardError
|
||||||
|
file_name = "#{__dir__}/cmock_generator_plugin_#{plugin_name.downcase}.rb"
|
||||||
|
raise "ERROR: CMock unable to load plugin '#{plugin_name}' '#{object_name}' #{file_name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,74 +2,76 @@
|
|||||||
# CMock Project - Automatic Mock Generation for C
|
# CMock Project - Automatic Mock Generation for C
|
||||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
class CMockUnityHelperParser
|
class CMockUnityHelperParser
|
||||||
|
|
||||||
attr_accessor :c_types
|
attr_accessor :c_types
|
||||||
|
|
||||||
def initialize(config)
|
def initialize(config)
|
||||||
@config = config
|
@config = config
|
||||||
@fallback = @config.plugins.include?(:array) ? 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY' : 'UNITY_TEST_ASSERT_EQUAL_MEMORY'
|
@fallback = @config.plugins.include?(:array) ? 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY' : 'UNITY_TEST_ASSERT_EQUAL_MEMORY'
|
||||||
@c_types = map_C_types.merge(import_source)
|
@c_types = map_c_types.merge(import_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_helper(ctype)
|
def get_helper(ctype)
|
||||||
lookup = ctype.gsub(/(?:^|(\S?)(\s*)|(\W))const(?:$|(\s*)(\S)|(\W))/,'\1\3\5\6').strip.gsub(/\s+/,'_')
|
lookup = ctype.gsub(/(?:^|(\S?)(\s*)|(\W))const(?:$|(\s*)(\S)|(\W))/, '\1\3\5\6').strip.gsub(/\s+/, '_')
|
||||||
return [@c_types[lookup], ''] if (@c_types[lookup])
|
return [@c_types[lookup], ''] if @c_types[lookup]
|
||||||
if (lookup =~ /\*$/)
|
|
||||||
lookup = lookup.gsub(/\*$/,'')
|
if lookup =~ /\*$/
|
||||||
return [@c_types[lookup], '*'] if (@c_types[lookup])
|
lookup = lookup.gsub(/\*$/, '')
|
||||||
|
return [@c_types[lookup], '*'] if @c_types[lookup]
|
||||||
else
|
else
|
||||||
lookup = lookup + '*'
|
lookup += '*'
|
||||||
return [@c_types[lookup], '&'] if (@c_types[lookup])
|
return [@c_types[lookup], '&'] if @c_types[lookup]
|
||||||
end
|
end
|
||||||
return ['UNITY_TEST_ASSERT_EQUAL_PTR', ''] if (ctype =~ /cmock_\w+_ptr\d+/)
|
return ['UNITY_TEST_ASSERT_EQUAL_PTR', ''] if ctype =~ /cmock_\w+_ptr\d+/
|
||||||
raise("Don't know how to test #{ctype} and memory tests are disabled!") unless @config.memcmp_if_unknown
|
raise("Don't know how to test #{ctype} and memory tests are disabled!") unless @config.memcmp_if_unknown
|
||||||
return (lookup =~ /\*$/) ? [@fallback, '&'] : [@fallback, '']
|
|
||||||
|
lookup =~ /\*$/ ? [@fallback, '&'] : [@fallback, '']
|
||||||
end
|
end
|
||||||
|
|
||||||
private ###########################
|
private ###########################
|
||||||
|
|
||||||
def map_C_types
|
def map_c_types
|
||||||
c_types = {}
|
c_types = {}
|
||||||
@config.treat_as.each_pair do |ctype, expecttype|
|
@config.treat_as.each_pair do |ctype, expecttype|
|
||||||
c_type = ctype.gsub(/\s+/,'_')
|
c_type = ctype.gsub(/\s+/, '_')
|
||||||
if (expecttype =~ /\*/)
|
if expecttype =~ /\*/
|
||||||
c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype.gsub(/\*/,'')}_ARRAY"
|
c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype.delete('*')}_ARRAY"
|
||||||
else
|
else
|
||||||
c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}"
|
c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}"
|
||||||
c_types[c_type+'*'] ||= "UNITY_TEST_ASSERT_EQUAL_#{expecttype}_ARRAY"
|
c_types[c_type + '*'] ||= "UNITY_TEST_ASSERT_EQUAL_#{expecttype}_ARRAY"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
c_types
|
c_types
|
||||||
end
|
end
|
||||||
|
|
||||||
def import_source
|
def import_source
|
||||||
source = @config.load_unity_helper
|
source = @config.load_unity_helper
|
||||||
return {} if source.nil?
|
return {} if source.nil?
|
||||||
|
|
||||||
c_types = {}
|
c_types = {}
|
||||||
source = source.gsub(/\/\/.*$/, '') #remove line comments
|
source = source.gsub(/\/\/.*$/, '') # remove line comments
|
||||||
source = source.gsub(/\/\*.*?\*\//m, '') #remove block comments
|
source = source.gsub(/\/\*.*?\*\//m, '') # remove block comments
|
||||||
|
|
||||||
#scan for comparison helpers
|
# scan for comparison helpers
|
||||||
match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+))\s*\(' + Array.new(4,'\s*\w+\s*').join(',') + '\)')
|
match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+))\s*\(' + Array.new(4, '\s*\w+\s*').join(',') + '\)')
|
||||||
pairs = source.scan(match_regex).flatten.compact
|
pairs = source.scan(match_regex).flatten.compact
|
||||||
(pairs.size/2).times do |i|
|
(pairs.size / 2).times do |i|
|
||||||
expect = pairs[i*2]
|
expect = pairs[i * 2]
|
||||||
ctype = pairs[(i*2)+1]
|
ctype = pairs[(i * 2) + 1]
|
||||||
c_types[ctype] = expect unless expect.include?("_ARRAY")
|
c_types[ctype] = expect unless expect.include?('_ARRAY')
|
||||||
end
|
end
|
||||||
|
|
||||||
#scan for array variants of those helpers
|
# scan for array variants of those helpers
|
||||||
match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+_ARRAY))\s*\(' + Array.new(5,'\s*\w+\s*').join(',') + '\)')
|
match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+_ARRAY))\s*\(' + Array.new(5, '\s*\w+\s*').join(',') + '\)')
|
||||||
pairs = source.scan(match_regex).flatten.compact
|
pairs = source.scan(match_regex).flatten.compact
|
||||||
(pairs.size/2).times do |i|
|
(pairs.size / 2).times do |i|
|
||||||
expect = pairs[i*2]
|
expect = pairs[i * 2]
|
||||||
ctype = pairs[(i*2)+1]
|
ctype = pairs[(i * 2) + 1]
|
||||||
c_types[ctype.gsub('_ARRAY','*')] = expect
|
c_types[ctype.gsub('_ARRAY', '*')] = expect
|
||||||
end
|
end
|
||||||
|
|
||||||
c_types
|
c_types
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+49
-48
@@ -28,33 +28,32 @@ end
|
|||||||
|
|
||||||
all_headers_to_mock = []
|
all_headers_to_mock = []
|
||||||
|
|
||||||
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT")
|
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].casecmp('--SILENT') == 0)
|
||||||
|
|
||||||
File.open(TEST_MAKEFILE, "w") do |mkfile|
|
|
||||||
|
|
||||||
|
File.open(TEST_MAKEFILE, 'w') do |mkfile|
|
||||||
# Define make variables
|
# Define make variables
|
||||||
mkfile.puts "CC ?= gcc"
|
mkfile.puts 'CC ?= gcc'
|
||||||
mkfile.puts "BUILD_DIR = #{BUILD_DIR}"
|
mkfile.puts "BUILD_DIR = #{BUILD_DIR}"
|
||||||
mkfile.puts "SRC_DIR = #{SRC_DIR}"
|
mkfile.puts "SRC_DIR = #{SRC_DIR}"
|
||||||
mkfile.puts "TEST_DIR = #{TEST_DIR}"
|
mkfile.puts "TEST_DIR = #{TEST_DIR}"
|
||||||
mkfile.puts "TEST_CFLAGS ?= -DTEST"
|
mkfile.puts 'TEST_CFLAGS ?= -DTEST'
|
||||||
mkfile.puts "CMOCK_DIR ?= #{CMOCK_DIR}"
|
mkfile.puts "CMOCK_DIR ?= #{CMOCK_DIR}"
|
||||||
mkfile.puts "UNITY_DIR ?= #{UNITY_DIR}"
|
mkfile.puts "UNITY_DIR ?= #{UNITY_DIR}"
|
||||||
mkfile.puts "TEST_BUILD_DIR ?= ${BUILD_DIR}/test"
|
mkfile.puts 'TEST_BUILD_DIR ?= ${BUILD_DIR}/test'
|
||||||
mkfile.puts "TEST_MAKEFILE = ${TEST_BUILD_DIR}/MakefileTestSupport"
|
mkfile.puts 'TEST_MAKEFILE = ${TEST_BUILD_DIR}/MakefileTestSupport'
|
||||||
mkfile.puts "OBJ ?= ${BUILD_DIR}/obj"
|
mkfile.puts 'OBJ ?= ${BUILD_DIR}/obj'
|
||||||
mkfile.puts "OBJ_DIR = ${OBJ}"
|
mkfile.puts 'OBJ_DIR = ${OBJ}'
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
# Build Unity
|
# Build Unity
|
||||||
mkfile.puts "#{UNITY_OBJ}: #{UNITY_SRC}/unity.c"
|
mkfile.puts "#{UNITY_OBJ}: #{UNITY_SRC}/unity.c"
|
||||||
mkfile.puts "\t${CC} -o $@ -c $< -I #{UNITY_SRC}"
|
mkfile.puts "\t${CC} -o $@ -c $< -I #{UNITY_SRC}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
# Build CMock
|
# Build CMock
|
||||||
mkfile.puts "#{CMOCK_OBJ}: #{CMOCK_SRC}/cmock.c"
|
mkfile.puts "#{CMOCK_OBJ}: #{CMOCK_SRC}/cmock.c"
|
||||||
mkfile.puts "\t${CC} -o $@ -c $< -I #{UNITY_SRC} -I #{CMOCK_SRC}"
|
mkfile.puts "\t${CC} -o $@ -c $< -I #{UNITY_SRC} -I #{CMOCK_SRC}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
test_sources = Dir["#{TEST_DIR}/**/test_*.c"]
|
test_sources = Dir["#{TEST_DIR}/**/test_*.c"]
|
||||||
test_targets = []
|
test_targets = []
|
||||||
@@ -69,7 +68,8 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
|||||||
if MOCK_SUFFIX.empty?
|
if MOCK_SUFFIX.empty?
|
||||||
return filename.start_with? MOCK_PREFIX
|
return filename.start_with? MOCK_PREFIX
|
||||||
end
|
end
|
||||||
return (filename.start_with? MOCK_PREFIX or filename.end_with? MOCK_SUFFIX)
|
|
||||||
|
(filename.start_with?(MOCK_PREFIX) || filename.end_with?(MOCK_SUFFIX))
|
||||||
end
|
end
|
||||||
|
|
||||||
all_headers = all_headers.reject { |f| reject_mock_files(f) }
|
all_headers = all_headers.reject { |f| reject_mock_files(f) }
|
||||||
@@ -93,56 +93,58 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
|||||||
# Build main project modules, with TEST defined
|
# Build main project modules, with TEST defined
|
||||||
module_src = File.join(SRC_DIR, "#{src_module_name}.c")
|
module_src = File.join(SRC_DIR, "#{src_module_name}.c")
|
||||||
module_obj = File.join(OBJ_DIR, "#{src_module_name}.o")
|
module_obj = File.join(OBJ_DIR, "#{src_module_name}.o")
|
||||||
if not makefile_targets.include? module_obj
|
unless makefile_targets.include? module_obj
|
||||||
makefile_targets.push(module_obj)
|
makefile_targets.push(module_obj)
|
||||||
mkfile.puts "#{module_obj}: #{module_src}"
|
mkfile.puts "#{module_obj}: #{module_src}"
|
||||||
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I ${SRC_DIR} ${INCLUDE_PATH}"
|
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I ${SRC_DIR} ${INCLUDE_PATH}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
end
|
end
|
||||||
|
|
||||||
# process link-only files
|
# process link-only files
|
||||||
linkonly = cfg[:includes][:linkonly]
|
linkonly = cfg[:includes][:linkonly]
|
||||||
linkonly_objs = []
|
linkonly_objs = []
|
||||||
linkonly.each do |linkonlyfile|
|
linkonly.each do |linkonlyfile|
|
||||||
linkonlybase = File.basename(linkonlyfile,".*")
|
linkonlybase = File.basename(linkonlyfile, '.*')
|
||||||
linkonlymodule_src = File.join(SRC_DIR, "#{linkonlyfile}")
|
linkonlymodule_src = File.join(SRC_DIR, linkonlyfile.to_s)
|
||||||
linkonlymodule_obj = File.join(OBJ_DIR, "#{linkonlybase}.o")
|
linkonlymodule_obj = File.join(OBJ_DIR, "#{linkonlybase}.o")
|
||||||
linkonly_objs.push(linkonlymodule_obj)
|
linkonly_objs.push(linkonlymodule_obj)
|
||||||
#only create the target if we didn't already
|
# only create the target if we didn't already
|
||||||
if not makefile_targets.include? linkonlymodule_obj
|
next if makefile_targets.include? linkonlymodule_obj
|
||||||
makefile_targets.push(linkonlymodule_obj)
|
|
||||||
mkfile.puts "#{linkonlymodule_obj}: #{linkonlymodule_src}"
|
makefile_targets.push(linkonlymodule_obj)
|
||||||
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I ${SRC_DIR} ${INCLUDE_PATH}"
|
mkfile.puts "#{linkonlymodule_obj}: #{linkonlymodule_src}"
|
||||||
mkfile.puts ""
|
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I ${SRC_DIR} ${INCLUDE_PATH}"
|
||||||
end
|
mkfile.puts ''
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create runners
|
# Create runners
|
||||||
mkfile.puts "#{runner_source}: #{test}"
|
mkfile.puts "#{runner_source}: #{test}"
|
||||||
mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/create_runner.rb #{test} #{runner_source}"
|
mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/create_runner.rb #{test} #{runner_source}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
# Build runner
|
# Build runner
|
||||||
mkfile.puts "#{runner_obj}: #{runner_source}"
|
mkfile.puts "#{runner_obj}: #{runner_source}"
|
||||||
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{SRC_DIR} -I #{MOCKS_DIR} -I #{UNITY_SRC} -I #{CMOCK_SRC} ${INCLUDE_PATH}"
|
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{SRC_DIR} -I #{MOCKS_DIR} -I #{UNITY_SRC} -I #{CMOCK_SRC} ${INCLUDE_PATH}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
# Collect mocks to generate
|
# Collect mocks to generate
|
||||||
system_mocks = cfg[:includes][:system].select{|name| name =~ MOCK_MATCHER}
|
system_mocks = cfg[:includes][:system].select { |name| name =~ MOCK_MATCHER }
|
||||||
raise "Mocking of system headers is not yet supported!" if !system_mocks.empty?
|
raise 'Mocking of system headers is not yet supported!' unless system_mocks.empty?
|
||||||
local_mocks = cfg[:includes][:local].select{|name| name =~ MOCK_MATCHER}
|
|
||||||
|
|
||||||
module_names_to_mock = local_mocks.map{|name| "#{name.sub(/#{MOCK_PREFIX}/,'')}"}
|
local_mocks = cfg[:includes][:local].select { |name| name =~ MOCK_MATCHER }
|
||||||
|
|
||||||
|
module_names_to_mock = local_mocks.map { |name| name.sub(/#{MOCK_PREFIX}/, '').to_s }
|
||||||
headers_to_mock = []
|
headers_to_mock = []
|
||||||
module_names_to_mock.each do |name|
|
module_names_to_mock.each do |name|
|
||||||
header_to_mock = nil
|
header_to_mock = nil
|
||||||
all_headers.each do |header|
|
all_headers.each do |header|
|
||||||
if (header =~ /[\/\\]?#{name}$/)
|
if header =~ /[\/\\]?#{name}$/
|
||||||
header_to_mock = header
|
header_to_mock = header
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
raise "Module header '#{name}' not found to mock!" unless header_to_mock
|
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
|
end
|
||||||
|
|
||||||
@@ -156,18 +158,18 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
|||||||
# Build test suite
|
# Build test suite
|
||||||
mkfile.puts "#{test_obj}: #{test} #{module_obj} #{mock_objs.join(' ')}"
|
mkfile.puts "#{test_obj}: #{test} #{module_obj} #{mock_objs.join(' ')}"
|
||||||
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{SRC_DIR} -I #{UNITY_SRC} -I #{CMOCK_SRC} -I #{MOCKS_DIR} ${INCLUDE_PATH}"
|
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{SRC_DIR} -I #{UNITY_SRC} -I #{CMOCK_SRC} -I #{MOCKS_DIR} ${INCLUDE_PATH}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
# Build test suite executable
|
# Build test suite executable
|
||||||
test_objs = "#{test_obj} #{runner_obj} #{module_obj} #{mock_objs.join(' ')} #{linkonly_objs.join(' ')} #{UNITY_OBJ} #{CMOCK_OBJ}"
|
test_objs = "#{test_obj} #{runner_obj} #{module_obj} #{mock_objs.join(' ')} #{linkonly_objs.join(' ')} #{UNITY_OBJ} #{CMOCK_OBJ}"
|
||||||
mkfile.puts "#{test_bin}: #{test_objs}"
|
mkfile.puts "#{test_bin}: #{test_objs}"
|
||||||
mkfile.puts "\t${CC} -o $@ ${LDFLAGS} #{test_objs}"
|
mkfile.puts "\t${CC} -o $@ ${LDFLAGS} #{test_objs}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
# Run test suite and generate report
|
# Run test suite and generate report
|
||||||
mkfile.puts "#{test_results}: #{test_bin}"
|
mkfile.puts "#{test_results}: #{test_bin}"
|
||||||
mkfile.puts "\t-#{test_bin} > #{test_results} 2>&1"
|
mkfile.puts "\t-#{test_bin} > #{test_results} 2>&1"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
test_targets << test_bin
|
test_targets << test_bin
|
||||||
end
|
end
|
||||||
@@ -181,22 +183,21 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
|||||||
|
|
||||||
mkfile.puts "#{mock_src}: #{hdr}"
|
mkfile.puts "#{mock_src}: #{hdr}"
|
||||||
mkfile.puts "\t@CMOCK_DIR=${CMOCK_DIR} ruby ${CMOCK_DIR}/scripts/create_mock.rb #{hdr}"
|
mkfile.puts "\t@CMOCK_DIR=${CMOCK_DIR} ruby ${CMOCK_DIR}/scripts/create_mock.rb #{hdr}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
mkfile.puts "#{mock_obj}: #{mock_src} #{mock_header}"
|
mkfile.puts "#{mock_obj}: #{mock_src} #{mock_header}"
|
||||||
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{MOCKS_DIR} -I #{SRC_DIR} -I #{UNITY_SRC} -I #{CMOCK_SRC} ${INCLUDE_PATH}"
|
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{MOCKS_DIR} -I #{SRC_DIR} -I #{UNITY_SRC} -I #{CMOCK_SRC} ${INCLUDE_PATH}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create test summary task
|
# Create test summary task
|
||||||
mkfile.puts "test_summary:"
|
mkfile.puts 'test_summary:'
|
||||||
mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/test_summary.rb #{suppress_error ? '--silent' : ''}"
|
mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/test_summary.rb #{suppress_error ? '--silent' : ''}"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
mkfile.puts ".PHONY: test_summary"
|
mkfile.puts '.PHONY: test_summary'
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
# Create target to run all tests
|
# Create target to run all tests
|
||||||
mkfile.puts "test: #{test_targets.map{|t| t + '.testresult'}.join(' ')} test_summary"
|
mkfile.puts "test: #{test_targets.map { |t| t + '.testresult' }.join(' ')} test_summary"
|
||||||
mkfile.puts ""
|
mkfile.puts ''
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
require "#{ENV['CMOCK_DIR']}/lib/cmock"
|
require "#{ENV['CMOCK_DIR']}/lib/cmock"
|
||||||
|
|
||||||
raise "Header file to mock must be specified!" unless ARGV.length >= 1
|
raise 'Header file to mock must be specified!' unless ARGV.length >= 1
|
||||||
|
|
||||||
mock_out = ENV.fetch('MOCK_OUT', './build/test/mocks')
|
mock_out = ENV.fetch('MOCK_OUT', './build/test/mocks')
|
||||||
mock_prefix = ENV.fetch('MOCK_PREFIX', 'mock_')
|
mock_prefix = ENV.fetch('MOCK_PREFIX', 'mock_')
|
||||||
cmock = CMock.new({:plugins => [:ignore, :return_thru_ptr], :mock_prefix => mock_prefix, :mock_path => mock_out})
|
cmock = CMock.new(:plugins => %i[ignore return_thru_ptr], :mock_prefix => mock_prefix, :mock_path => mock_out)
|
||||||
cmock.setup_mocks(ARGV[0])
|
cmock.setup_mocks(ARGV[0])
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
if ($0 == __FILE__)
|
if $0 == __FILE__
|
||||||
|
|
||||||
#make sure there is at least one parameter left (the input file)
|
# make sure there is at least one parameter left (the input file)
|
||||||
if ARGV.length < 2
|
if ARGV.length < 2
|
||||||
puts ["\nusage: ruby #{__FILE__} input_test_file (output)",
|
puts ["\nusage: ruby #{__FILE__} input_test_file (output)",
|
||||||
"",
|
'',
|
||||||
" input_test_file - this is the C file you want to create a runner for",
|
' input_test_file - this is the C file you want to create a runner for',
|
||||||
" output - this is the name of the runner file to generate",
|
' output - this is the name of the runner file to generate',
|
||||||
" defaults to (input_test_file)_Runner",
|
' defaults to (input_test_file)_Runner'].join("\n")
|
||||||
].join("\n")
|
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -15,6 +14,5 @@ if ($0 == __FILE__)
|
|||||||
|
|
||||||
test = ARGV[0]
|
test = ARGV[0]
|
||||||
runner = ARGV[1]
|
runner = ARGV[1]
|
||||||
generator = UnityTestRunnerGenerator.new.run(test, runner)
|
UnityTestRunnerGenerator.new.run(test, runner)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].casecmp('--SILENT') == 0)
|
||||||
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT")
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require "#{ENV['UNITY_DIR']}/auto/unity_test_summary.rb"
|
require "#{ENV['UNITY_DIR']}/auto/unity_test_summary.rb"
|
||||||
|
|||||||
+40
-2
@@ -32,7 +32,7 @@ configure_clean
|
|||||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||||
|
|
||||||
task :default => [:test]
|
task :default => [:test]
|
||||||
task :ci => [:no_color, :default]
|
task :ci => [:no_color, :default, 'test:examples', 'style:check']
|
||||||
task :cruise => :ci
|
task :cruise => :ci
|
||||||
|
|
||||||
desc "Load configuration"
|
desc "Load configuration"
|
||||||
@@ -43,7 +43,7 @@ task :config, :config_file do |t, args|
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Still support testing everything with just 'test' but switch default to ceedling-like test:all
|
# Still support testing everything with just 'test' but switch default to ceedling-like test:all
|
||||||
task :test => [:clobber, :prep_system_tests, 'test:units', 'test:c', 'test:system']
|
task :test => ['test:all']
|
||||||
|
|
||||||
namespace :test do
|
namespace :test do
|
||||||
desc "Run all unit, c, and system tests"
|
desc "Run all unit, c, and system tests"
|
||||||
@@ -89,6 +89,11 @@ namespace :test do
|
|||||||
run_system_test_compilations(compile_tests_to_run)
|
run_system_test_compilations(compile_tests_to_run)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Test cmock examples"
|
||||||
|
task :examples => [:prep_system_tests] do
|
||||||
|
run_examples()
|
||||||
|
end
|
||||||
|
|
||||||
#individual system tests
|
#individual system tests
|
||||||
FileList['system/test_interactions/*.yml'].each do |test|
|
FileList['system/test_interactions/*.yml'].each do |test|
|
||||||
basename = File.basename(test,'.*')
|
basename = File.basename(test,'.*')
|
||||||
@@ -107,3 +112,36 @@ end
|
|||||||
task :no_color do
|
task :no_color do
|
||||||
$colour_output = false
|
$colour_output = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
################### CODING STYLE VALIDATION
|
||||||
|
namespace :style do
|
||||||
|
desc "Check style"
|
||||||
|
task :check do
|
||||||
|
report "\nVERIFYING RUBY STYLE"
|
||||||
|
report execute("rubocop ../lib ../examples ../config ../scripts --config ../vendor/unity/test/.rubocop.yml", true)
|
||||||
|
report "Styling Ruby:PASS"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Fix Style of all C Code"
|
||||||
|
task :c do
|
||||||
|
run_astyle("../src/*.* ../extras/fixture/src/*.*")
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Attempt to Autocorrect style"
|
||||||
|
task :auto => ['style:clean'] do
|
||||||
|
report execute("rubocop ../lib ../examples ../config ../scripts --auto-correct --config ../vendor/unity/test/.rubocop.yml", true)
|
||||||
|
report "Autocorrected What We Could."
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Update style todo list"
|
||||||
|
task :todo => ['style:clean'] do
|
||||||
|
report execute("rubocop ../lib ../examples ../config ../scripts --auto-gen-config --config ../vendor/unity/test/.rubocop.yml", true)
|
||||||
|
report "Updated Style TODO List."
|
||||||
|
end
|
||||||
|
|
||||||
|
task :clean do
|
||||||
|
File.delete(".rubocop_todo.yml") if File.exists?(".rubocop_todo.yml")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task :style => ['style:check']
|
||||||
@@ -161,6 +161,18 @@ module RakefileHelpers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run_astyle(style_what)
|
||||||
|
report "Styling C Code..."
|
||||||
|
command = "AStyle " \
|
||||||
|
"--style=allman --indent=spaces=4 --indent-switches --indent-preproc-define --indent-preproc-block " \
|
||||||
|
"--pad-oper --pad-comma --unpad-paren --pad-header " \
|
||||||
|
"--align-pointer=type --align-reference=name " \
|
||||||
|
"--add-brackets --mode=c --suffix=none " \
|
||||||
|
"#{style_what}"
|
||||||
|
execute(command, false)
|
||||||
|
report "Styling C:PASS"
|
||||||
|
end
|
||||||
|
|
||||||
def report_summary
|
def report_summary
|
||||||
summary = UnityTestSummary.new
|
summary = UnityTestSummary.new
|
||||||
summary.root = File.expand_path(File.dirname(__FILE__)) + '/'
|
summary.root = File.expand_path(File.dirname(__FILE__)) + '/'
|
||||||
@@ -374,6 +386,15 @@ module RakefileHelpers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run_examples()
|
||||||
|
[ "cd #{File.join("..","examples","make_example")} && make clean && make setup && make test",
|
||||||
|
"cd #{File.join("..","examples","temp_sensor")} && rake ci"
|
||||||
|
].each do |cmd|
|
||||||
|
report "Testing '#{cmd}'"
|
||||||
|
execute(cmd, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def fail_out(msg)
|
def fail_out(msg)
|
||||||
puts msg
|
puts msg
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|||||||
@@ -13,34 +13,34 @@ describe CMockConfig, "Verify CMockConfig Module" do
|
|||||||
|
|
||||||
it "use default settings when no parameters are specified" do
|
it "use default settings when no parameters are specified" do
|
||||||
config = CMockConfig.new
|
config = CMockConfig.new
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path)
|
||||||
assert_nil(CMockConfig::CMockDefaultOptions[:includes])
|
assert_nil(CMockConfig::CMOCK_DEFAULT_OPTIONS[:includes])
|
||||||
assert_nil(config.includes)
|
assert_nil(config.includes)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:attributes], config.attributes)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:plugins], config.plugins)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_externs], config.treat_externs)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_inlines], config.treat_inlines)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_inlines], config.treat_inlines)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:inline_function_patterns], config.inline_function_patterns)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:inline_function_patterns], config.inline_function_patterns)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "replace only options specified in a hash" do
|
it "replace only options specified in a hash" do
|
||||||
test_includes = ['hello']
|
test_includes = ['hello']
|
||||||
test_attributes = ['blah', 'bleh']
|
test_attributes = ['blah', 'bleh']
|
||||||
config = CMockConfig.new(:includes => test_includes, :attributes => test_attributes)
|
config = CMockConfig.new(:includes => test_includes, :attributes => test_attributes)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path)
|
||||||
assert_equal(test_includes, config.includes)
|
assert_equal(test_includes, config.includes)
|
||||||
assert_equal(test_attributes, config.attributes)
|
assert_equal(test_attributes, config.attributes)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:plugins], config.plugins)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_externs], config.treat_externs)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_inlines], config.treat_inlines)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_inlines], config.treat_inlines)
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:inline_function_patterns], config.inline_function_patterns)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:inline_function_patterns], config.inline_function_patterns)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "replace only options specified in a yaml file" do
|
it "replace only options specified in a yaml file" do
|
||||||
test_plugins = [:soda, :pizza]
|
test_plugins = [:soda, :pizza]
|
||||||
config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml")
|
config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml")
|
||||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path)
|
||||||
assert_nil(CMockConfig::CMockDefaultOptions[:includes])
|
assert_nil(CMockConfig::CMOCK_DEFAULT_OPTIONS[:includes])
|
||||||
assert_nil(config.includes)
|
assert_nil(config.includes)
|
||||||
assert_equal(test_plugins, config.plugins)
|
assert_equal(test_plugins, config.plugins)
|
||||||
assert_equal(:include, config.treat_externs)
|
assert_equal(:include, config.treat_externs)
|
||||||
|
|||||||
@@ -1035,7 +1035,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
|||||||
{ :type=>"int", :name => "param8", :ptr? => false, :const? => true, :const_ptr? => false }],
|
{ :type=>"int", :name => "param8", :ptr? => false, :const? => true, :const_ptr? => false }],
|
||||||
:args_call => "param1, param2, param3, param4, param5, param6, param7, param8",
|
:args_call => "param1, param2, param3, param4, param5, param6, param7, param8",
|
||||||
:contains_ptr? => true
|
:contains_ptr? => true
|
||||||
}]
|
}].freeze
|
||||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
Submodule vendor/unity updated: 8c4ae7aacd...615cf2349e
Reference in New Issue
Block a user