How can I configure a source set for a GoogleTest component?

Hello,

I am using the google-test plugin. If I configure a library like so,

model {
  components {
    // define libraries and executables to be built
    myapp_common(NativeLibrarySpec) {
      targetPlatform "arm"
      sources {
        cpp {
          lib library: 'opencv_core', linkage: 'shared'
          lib library: 'opencv_highgui', linkage: 'shared'
          lib library: 'opencv_imgproc', linkage: 'shared'

          source {
            srcDirs 'common/src'
            include "*.cpp"
          }

          exportedHeaders {
            srcDirs "common/include"
          }
        }
      }
    }
  }

the google-test plugin creates a component named “myapp_commonTest” like this:

GoogleTest test suite 'myapp_commonTest'
-----------------------------------------

Source sets
    C++ source 'myapp_commonTest:cpp'
        srcDir: src/myapp_commonTest/cpp

Binaries
    Google test exe 'myapp_commonTest:googleTestExe'
        build using task: :myapp_commonTestGoogleTestExe
        run using task: :runMyapp_commonTestGoogleTestExe
        platform: arm
        build type: debug
        flavor: default
        tool chain: Tool chain 'idxArm' (GNU GCC)
        executable file: ../../../../catone-gradle-build/binaries/myapp_commonTestGoogleTestExe/myapp_commonTest

I would like to change the srcDir on the myapp_commonTest component source set, but am having trouble figuring out how. I tried configuring it like this:

model {
  components {
    myapp_commonTest(GoogleTestTestSuiteSpec) {
      sources {
        cpp {
          source {
            srcDir 'common/tests'
            include '**/*.cpp'
          }
        }
      }
    }
  }
}

but this ends up giving me a new component and another test component named “myapp_commonTestTest.” It doesn’t configure the existing myapp_commonTest component as I expect it to. What am I missing? How can I configure the source set for the test component binary?

Thank you,
Derek

I have a similar issue.
I can’t figure out how to configure the google test suite sources.
Any attempt to do something similar to what was done above just creates another component with no binaries.

We need to update the samples to include how to configure this.

The test suite components are available through a testSuites container, so you should be able to do something like this:

apply plugin: 'cpp'
apply plugin: 'google-test'

model {
    components {
        lib(NativeLibrarySpec)
    }
    testSuites {
        libTest {
            sources {
                cpp.source.srcDir 'something/else'
            }
        }
    }
}

Thanks!
That solved the issue for me.

Thank you Sterling. Works as described!
I agree that updating the sample would be very helpful. Also, I wasn’t able to find documentation of the testSuites container. Is it currently undocumented?
-Derek

Yes, it’s undocumented. I think this just slipped through since not much was using it. I’ll see about getting this into 2.8.

Hi Sterling,
Could you provide more details on this?
What is something/else