2017-04-18 43 views
0

我有在gradle這個本機C應用gradle這個項目(2.10版本)來測試本機應用程序:如何使用CUNIT從多個組件由多個部件

components { 

    component_1(NativeLibrarySpec) 
    component_2(NativeLibrarySpec) 
    ... 
    component_n(NativeLibrarySpec) 

    main_component(NativeExecutableSpec){ 
     sources { 
      c.lib library: "component_1", linkage: "static" 
      c.lib library: "component_2", linkage: "static" 
      ... 
      c.lib library: "component_n", linkage: "static" 
     } 

    } 
} 

具有應用的主要思想在這種形式下更容易測試各個組件。然而,我有兩個大問題:

main_component是一個應用程序,因此有一個主要功能,併產生此錯誤:multiple definition of 'main' ... gradle_cunit_main.c:(.text+0x0): first defined here。這是我們期望的,並在文檔中提到,但我想知道是否有辦法避免這個問題,例如,阻止主要組件包含在測試中。這涉及到下一個問題

的CUNIT插件(截至gradle這個2.10版本)抱怨,當我嘗試定義要測試的組成部分如下:

testSuites { 
    component_1Test(CUnitTestSuiteSpec){ 
      testing $.components.component_1 
     } 
    } 
} 

gradle這個抱怨:

Cannot create 'testSuites.component_1Test' using creation rule 'component_1Test(org.gradle.nativeplatform.test.cunit.CUnitTestSuiteSpec) { ... } @ build.gradle line 68, column 9' as the rule 'CUnitPlugin.Rules#createCUnitTestSuitePerComponent > create(component_1Test)' is already registered to create this model element

總之,我想指示cunit插件僅測試一些組件,並防止主要組件(包含主函數)被編譯用於測試。再次請注意,我使用的是gradle 2.10,無法升級到更新的版本,因爲這會扼制我們的CI工具鏈。

在此先感謝您的意見。

回答

0

下面是如何構造的項目,以允許部件的單元測試,但防止主程序的單元測試:在分割一個子項目的組件和cunit插件應用到子項目,如下所示:

project(':libs'){ 
apply plugin: 'c' 
apply plugin: 'cunit' 
model{ 

    repositories { 
     libs(PrebuiltLibraries) { 
      cunit { 
       headers.srcDir "/usr/include/" 
        binaries.withType(StaticLibraryBinary) { 
         staticLibraryFile = file("/usr/lib/x86_64-linux-gnu/libcunit.a") 
        } 
      } 
     } 
    } 

    components { 
     component_1(NativeLibrarySpec) 
     component_2(NativeLibrarySpec) 
     ... 
     component_n(NativeLibrarySpec) 
    } 

    binaries { 
     withType(CUnitTestSuiteBinarySpec) { 
      lib library: "cunit", linkage: "static" 
     } 
    } 
} 
} 
apply plugin: 'c' 
model { 
    components{ 
     myprogram(NativeExecutableSpec) { 
      sources.c { 
       lib project: ':libs', library: 'component_1', linkage: 'static' 
       lib project: ':libs', library: 'component_2', linkage: 'static' 
       lib project: ':libs', library: "component_n", linkage: 'static' 
       source { 
        srcDir "src/myprogram/c" 
          include "**/*.c" 
       } 
      } 
     } 
    } 
}