mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-24 12:09:55 +00:00
Add ability to generate skeleton from header. woo!
This commit is contained in:
+1
-1
@@ -92,7 +92,7 @@ namespace :test do
|
||||
#individual system tests
|
||||
FileList['system/test_interactions/*.yml'].each do |test|
|
||||
basename = File.basename(test,'.*')
|
||||
desc "Run system test #{basename}"
|
||||
#desc "Run system test #{basename}"
|
||||
task basename do
|
||||
run_system_test_interactions([test])
|
||||
end
|
||||
|
||||
@@ -66,6 +66,7 @@ class SystemTestGenerator
|
||||
|
||||
generate_test_file(yaml_hash, namix, name)
|
||||
generate_source_file(yaml_hash, namix, name)
|
||||
generate_skeleton_file(yaml_hash, namix, name)
|
||||
end
|
||||
|
||||
def generate_types_file(yaml_hash, namix)
|
||||
@@ -136,11 +137,22 @@ class SystemTestGenerator
|
||||
includes << (namix + MOCKABLE_H) if not yaml_hash[:systest][:mockable].nil?
|
||||
includes << header_file
|
||||
|
||||
write_source_file(GENERATED_PATH + name + C_EXTENSION, includes.flatten) do |out|
|
||||
out.puts(source[:code])
|
||||
unless (source[:code].nil?)
|
||||
write_source_file(GENERATED_PATH + name + C_EXTENSION, includes.flatten) do |out|
|
||||
out.puts(source[:code])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def generate_skeleton_file(yaml_hash, namix, name)
|
||||
source = yaml_hash[:systest][:skeleton]
|
||||
return if source.nil?
|
||||
|
||||
require 'cmock.rb'
|
||||
cmock = CMock.new(GENERATED_PATH + namix + 'cmock' + YAML_EXTENSION)
|
||||
cmock.setup_skeletons("#{$cfg['compiler']['source_path']}#{name}.h")
|
||||
end
|
||||
|
||||
def write_header_file(filename, upcase_name, include_list=[])
|
||||
File.open(filename, 'w') do |out|
|
||||
out.puts("#ifndef _#{upcase_name}")
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
---
|
||||
:cmock:
|
||||
:plugins:
|
||||
- # none
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
#define UINT32 unsigned int
|
||||
|
||||
:mockable: |
|
||||
UINT32 something(int a);
|
||||
|
||||
:skeleton: skeleton.h
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
void function_a(void);
|
||||
int function_b(int a, int b);
|
||||
const char* function_c(void);
|
||||
|
||||
# we are purposefully not including a :code section because it will be generated with skeleton
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'generate an empty shell for functions with no return values'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'return numerical zero for numerical return values'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, function_b(1, 2));
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'return null for pointer return values'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
TEST_ASSERT_NULL(function_c());
|
||||
}
|
||||
|
||||
|
||||
...
|
||||
@@ -0,0 +1,75 @@
|
||||
---
|
||||
:cmock:
|
||||
:plugins:
|
||||
- # none
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
#define UINT32 unsigned int
|
||||
|
||||
:mockable: |
|
||||
UINT32 something(int a);
|
||||
|
||||
:skeleton: skeleton_update.h
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
void function_a(void);
|
||||
int function_b(int a, int b);
|
||||
const char* function_c(void);
|
||||
|
||||
# note that this code section exists and will be updated by the skeleton generator
|
||||
:code: |
|
||||
const char* donuts = "donuts";
|
||||
const char* function_c(void)
|
||||
{
|
||||
return donuts;
|
||||
}
|
||||
|
||||
int function_d(void)
|
||||
{
|
||||
return 77;
|
||||
}
|
||||
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
extern int function_d();
|
||||
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'generate an empty shell for functions with no return values'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'return numerical zero for numerical return values'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, function_b(1, 2));
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'not overwrite functions that already exist'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_STRING("donuts", function_c());
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'leave functions it has never heard of'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(77, function_d());
|
||||
}
|
||||
|
||||
|
||||
...
|
||||
Reference in New Issue
Block a user