Search in sources :

Example 1 with DefaultSwiftXCTestSuite

use of org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite in project gradle by gradle.

the class XCTestConventionPlugin method apply.

@Override
public void apply(ProjectInternal project) {
    project.getPluginManager().apply(SwiftBasePlugin.class);
    project.getPluginManager().apply(NativeTestingBasePlugin.class);
    // Create test suite component
    final DefaultSwiftXCTestSuite testComponent = createTestSuite(project);
    project.afterEvaluate(new Action<Project>() {

        @Override
        public void execute(final Project project) {
            String operatingSystemSuffix = "";
            OperatingSystemFamily operatingSystem = objectFactory.named(OperatingSystemFamily.class, DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName());
            Usage runtimeUsage = objectFactory.named(Usage.class, Usage.NATIVE_RUNTIME);
            Provider<String> group = project.provider(new Callable<String>() {

                @Override
                public String call() throws Exception {
                    return project.getGroup().toString();
                }
            });
            Provider<String> version = project.provider(new Callable<String>() {

                @Override
                public String call() throws Exception {
                    return project.getVersion().toString();
                }
            });
            AttributeContainer attributesDebug = attributesFactory.mutable();
            attributesDebug.attribute(Usage.USAGE_ATTRIBUTE, runtimeUsage);
            attributesDebug.attribute(DEBUGGABLE_ATTRIBUTE, true);
            attributesDebug.attribute(OPTIMIZED_ATTRIBUTE, false);
            NativeVariantIdentity debugVariant = new NativeVariantIdentity("debug" + operatingSystemSuffix, testComponent.getModule(), group, version, true, false, operatingSystem, null, new DefaultUsageContext("debug" + operatingSystemSuffix + "-runtime", runtimeUsage, attributesDebug));
            ToolChainSelector.Result<SwiftPlatform> result = toolChainSelector.select(SwiftPlatform.class);
            // Create test suite executable
            DefaultSwiftXCTestBinary binary;
            if (result.getTargetPlatform().getOperatingSystem().isMacOsX()) {
                binary = (DefaultSwiftXCTestBinary) testComponent.addBundle("executable", debugVariant, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
            } else {
                binary = (DefaultSwiftXCTestBinary) testComponent.addExecutable("executable", debugVariant, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
            }
            testComponent.getTestBinary().set(binary);
            // TODO: Publishing for test executable?
            final ProductionSwiftComponent mainComponent = project.getComponents().withType(ProductionSwiftComponent.class).findByName("main");
            if (mainComponent != null) {
                testComponent.getTestedComponent().set(mainComponent);
                // Test configuration extends main configuration
                testComponent.getImplementationDependencies().extendsFrom(mainComponent.getImplementationDependencies());
                project.getDependencies().add(binary.getImportPathConfiguration().getName(), project);
            }
            testComponent.getBinaries().whenElementKnown(DefaultSwiftXCTestBinary.class, new Action<DefaultSwiftXCTestBinary>() {

                @Override
                public void execute(DefaultSwiftXCTestBinary binary) {
                    // Create test suite test task
                    XCTest testingTask = createTestingTask(project);
                    binary.getRunTask().set(testingTask);
                    // Configure tasks
                    configureTestingTask(binary, testingTask);
                    configureTestSuiteBuildingTasks((ProjectInternal) project, binary);
                    configureTestSuiteWithTestedComponentWhenAvailable(project, testComponent, binary);
                }
            });
            testComponent.getBinaries().realizeNow();
        }
    });
}
Also used : OperatingSystemFamily(org.gradle.nativeplatform.OperatingSystemFamily) Usage(org.gradle.api.attributes.Usage) Action(org.gradle.api.Action) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) AttributeContainer(org.gradle.api.attributes.AttributeContainer) NativeVariantIdentity(org.gradle.language.cpp.internal.NativeVariantIdentity) Callable(java.util.concurrent.Callable) Provider(org.gradle.api.provider.Provider) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) Project(org.gradle.api.Project) DefaultSwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBinary) DefaultUsageContext(org.gradle.language.cpp.internal.DefaultUsageContext) DefaultSwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite) SwiftPlatform(org.gradle.language.swift.SwiftPlatform) XCTest(org.gradle.nativeplatform.test.xctest.tasks.XCTest)

Example 2 with DefaultSwiftXCTestSuite

use of org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite in project gradle by gradle.

the class XCTestConventionPlugin method createTestSuite.

private DefaultSwiftXCTestSuite createTestSuite(final Project project) {
    // TODO - Reuse logic from Swift*Plugin
    // TODO - component name and extension name aren't the same
    // TODO - should use `src/xctest/swift` as the convention?
    // Add the test suite and extension
    DefaultSwiftXCTestSuite testSuite = componentFactory.newInstance(SwiftXCTestSuite.class, DefaultSwiftXCTestSuite.class, "test");
    project.getExtensions().add(SwiftXCTestSuite.class, "xctest", testSuite);
    project.getComponents().add(testSuite);
    // Setup component
    testSuite.getModule().set(GUtil.toCamelCase(project.getName() + "Test"));
    return testSuite;
}
Also used : DefaultSwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite)

Aggregations

DefaultSwiftXCTestSuite (org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite)2 Callable (java.util.concurrent.Callable)1 Action (org.gradle.api.Action)1 Project (org.gradle.api.Project)1 AttributeContainer (org.gradle.api.attributes.AttributeContainer)1 Usage (org.gradle.api.attributes.Usage)1 Provider (org.gradle.api.provider.Provider)1 DefaultUsageContext (org.gradle.language.cpp.internal.DefaultUsageContext)1 NativeVariantIdentity (org.gradle.language.cpp.internal.NativeVariantIdentity)1 ProductionSwiftComponent (org.gradle.language.swift.ProductionSwiftComponent)1 SwiftPlatform (org.gradle.language.swift.SwiftPlatform)1 OperatingSystemFamily (org.gradle.nativeplatform.OperatingSystemFamily)1 DefaultSwiftXCTestBinary (org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBinary)1 XCTest (org.gradle.nativeplatform.test.xctest.tasks.XCTest)1 PlatformToolProvider (org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider)1