2017-08-05 41 views
0

有沒有辦法將我的項目切換到使用耙子作爲其構建系統?我有一個使用Make作爲其構建系統的大型項目,並希望爲單元測試添加CMock功能(我已經成功使用Unity),但是沒有發現關於將CMock與Makefiles集成的信息(相反,它似乎是世界上的如果他們希望CMock能夠使用他們的項目,就可以使用Ruby的耙子作爲他們的構建系統)。如何整合CMock單元測試框架與製作

我已經能夠運行CMock示例測試,其中包括一個(看似未完成的?)'make'示例。

我已經修改了測試代碼中的「make_example」於以下內容:

#include "mock_foo.h" 
#include "unity.h" 

void setUp(void) {} 

void tearDown(void) {} 

void test_main_should_initialize_foo(void) { 
     foo_init_Ignore(); 
     TEST_IGNORE_MESSAGE("TODO: Implement main!"); 
} 
然而

,運行從與Makefile文件的文件夾「讓」的時候,似乎UNITY_LINE_TYPE是不確定的(如東西從我的依賴鏈丟失):

make 
mkdir -p ./build 
mkdir -p ./build/obj 
ruby ../../scripts/create_makefile.rb --silent 
cc -o build/test/obj/test_main.o -c test/test_main.c -DTEST -I ./src -I /home/user/Documents/gitrepos/cmock/vendor/unity/src -I /home/user/Documents/gitrepos/cmock/src -I ./build/test/mocks 
In file included from test/test_main.c:1:0: 
./build/test/mocks/mock_foo.h:27:27: error: unknown type name ‘UNITY_LINE_TYPE’ 
void foo_init_CMockExpect(UNITY_LINE_TYPE cmock_line); 
         ^
build/test/MakefileTestSupport:29: recipe for target 'build/test/obj/test_main.o' failed 
make: *** [build/test/obj/test_main.o] Error 1 

有沒有人使用Makefiles和CMock成功實現了一個項目?

回答

0

原來我在這裏是我自己的一些vim/clang格式配置的受害者。

的make_example(雖然不是開箱非常有用)並編譯和正確使用CMock的模擬框架如果的「unity.h」進口量的「mock_ XXX .H」前放置運行測試在你的測試實現中(我肯定會在文檔中調用它)。

下面是一個工作試驗(從cmock /示例/ make_example稍微修改test_main.c)的一個例子:

#include "unity.h" 
#include "mock_foo.h" 

void setUp(void) 
{ 
} 

void tearDown(void) 
{ 
} 

void test_main_should_initialize_foo(void) 
{ 
    foo_init_Expect(); 
    foo_init(); 
} 

但是,由於我的VIM /鐺格式被設置爲 'SortIncludes:真' ,我的包括被重新排序生產:

#include "mock_foo.h" // <---- the mocks must be included *after* unity.h 
#include "unity.h" 

void setUp(void) 
{ 
} 

void tearDown(void) 
{ 
} 

void test_main_should_initialize_foo(void) 
{ 
    foo_init_Expect(); 
    foo_init(); 
} 

就像我一樣:wq在vim。

這當然會導致CMock的問題,因爲它需要的unity.h定義想通了,它試圖產生mock_foo.h之前,讓我得到我上面張貼的錯誤:

... 
In file included from test/test_main.c:1:0: 
./build/test/mocks/mock_foo.h:27:27: error: unknown type name ‘UNITY_LINE_TYPE’ 
void foo_init_CMockExpect(UNITY_LINE_TYPE cmock_line); 
... 

我的Makefile文件(從CMock例子不變),爲後人:

CC ?= gcc 
BUILD_DIR ?= ./build 
SRC_DIR ?= ./src 
TEST_DIR ?= ./test 
TEST_BUILD_DIR ?= ${BUILD_DIR}/test 
TEST_MAKEFILE = ${TEST_BUILD_DIR}/MakefileTestSupport 
OBJ ?= ${BUILD_DIR}/obj 
OBJ_DIR = ${OBJ} 

default: all 

all: setup test ${BUILD_DIR}/main run 

setup: 
    mkdir -p ${BUILD_DIR} 
    mkdir -p ${OBJ} 
    ruby ../../scripts/create_makefile.rb --silent 

clean: 
    rm -rf ${BUILD_DIR} 

${BUILD_DIR}/main: ${SRC_DIR}/main.c ${SRC_DIR}/foo.c 
    ${CC} $< -o [email protected] 

run: 
    ./build/main || true 

test: setup 

-include ${TEST_MAKEFILE} 

我發現這個被發現UNITY_LINE_TYPE在unity.h定義以及如何unity.h被包括在我的測試關注發生,看到它在之後包括'mock_foo.h'(對我來說沒有任何問題),然後和一些工作的rake例子(在../temp_sensor中)比較,我注意到所有的'unity.h'包含在所有'mock_ xxx .h'包括(我還沒有用vim觸及過這些)。

不要讓你的工具變成傻瓜。