Search in sources :

Example 21 with TestFile

use of org.gradle.test.fixtures.file.TestFile in project gradle by gradle.

the class ProjectLoadingIntegrationTest method ignoresMultiProjectBuildInParentDirectoryWhichDoesNotMeetDefaultProjectCriteria.

@Test
public void ignoresMultiProjectBuildInParentDirectoryWhichDoesNotMeetDefaultProjectCriteria() {
    testFile("settings.gradle").write("include 'another'");
    testFile("gradle.properties").writelns("prop=value2", "otherProp=value");
    TestFile subDirectory = getTestDirectory().file("subdirectory");
    TestFile buildFile = subDirectory.file("build.gradle");
    buildFile.writelns("task('do-stuff') {", "doLast {", "assert prop == 'value'", "assert !project.hasProperty('otherProp')", "}", "}");
    testFile("subdirectory/gradle.properties").write("prop=value");
    inDirectory(subDirectory).withTasks("do-stuff").expectDeprecationWarning().run();
    usingProjectDir(subDirectory).withTasks("do-stuff").expectDeprecationWarning().run();
    usingBuildFile(buildFile).withTasks("do-stuff").expectDeprecationWarning().run();
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) Test(org.junit.Test) AbstractIntegrationTest(org.gradle.integtests.fixtures.AbstractIntegrationTest)

Example 22 with TestFile

use of org.gradle.test.fixtures.file.TestFile in project gradle by gradle.

the class ProjectLoadingIntegrationTest method noDeprecationWarningAppearsWhenUsingRootProject.

@Test
public void noDeprecationWarningAppearsWhenUsingRootProject() {
    testFile("settings.gradle").write("include 'another'");
    TestFile subDirectory = getTestDirectory().file("sub");
    subDirectory.file("build.gradle").write("");
    usingProjectDir(getTestDirectory()).inDirectory(subDirectory).withTasks("help").run();
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) Test(org.junit.Test) AbstractIntegrationTest(org.gradle.integtests.fixtures.AbstractIntegrationTest)

Example 23 with TestFile

use of org.gradle.test.fixtures.file.TestFile in project gradle by gradle.

the class NoDaemonGradleExecuter method createExecHandleBuilder.

private DefaultExecHandleBuilder createExecHandleBuilder() {
    TestFile gradleHomeDir = getDistribution().getGradleHomeDir();
    if (!gradleHomeDir.isDirectory()) {
        fail(gradleHomeDir + " is not a directory.\n" + "If you are running tests from IDE make sure that gradle tasks that prepare the test image were executed. Last time it was 'intTestImage' task.");
    }
    NativeServicesTestFixture.initialize();
    DefaultExecHandleBuilder builder = new DefaultExecHandleBuilder(TestFiles.resolver(), Executors.newCachedThreadPool()) {

        @Override
        public File getWorkingDir() {
            // the working directory is not canonicalised
            return NoDaemonGradleExecuter.this.getWorkingDir();
        }
    };
    // Clear the user's environment
    builder.environment("GRADLE_HOME", "");
    builder.environment("JAVA_HOME", "");
    builder.environment("GRADLE_OPTS", "");
    builder.environment("JAVA_OPTS", "");
    GradleInvocation invocation = buildInvocation();
    builder.environment(invocation.environmentVars);
    builder.workingDir(getWorkingDir());
    builder.setStandardInput(connectStdIn());
    builder.args(invocation.args);
    ExecHandlerConfigurer configurer = OperatingSystem.current().isWindows() ? new WindowsConfigurer() : new UnixConfigurer();
    configurer.configure(builder);
    getLogger().debug(String.format("Execute in %s with: %s %s", builder.getWorkingDir(), builder.getExecutable(), builder.getArgs()));
    return builder;
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) DefaultExecHandleBuilder(org.gradle.process.internal.DefaultExecHandleBuilder)

Example 24 with TestFile

use of org.gradle.test.fixtures.file.TestFile in project gradle by gradle.

the class Resources method findResource.

/**
 * Locates the resource with the given name, relative to the current test class.
 * @return the resource, or null if not found.
 */
public TestFile findResource(String name) {
    assertNotNull(testClass);
    URL resource = testClass.getResource(name);
    if (resource == null) {
        return null;
    }
    assertEquals(String.format("Cannot handle resource URI %s", resource), "file", resource.getProtocol());
    File file;
    try {
        file = new File(resource.toURI());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    return new TestFile(file);
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) URISyntaxException(java.net.URISyntaxException) TestFile(org.gradle.test.fixtures.file.TestFile) File(java.io.File) URL(java.net.URL)

Example 25 with TestFile

use of org.gradle.test.fixtures.file.TestFile in project gradle by gradle.

the class MSBuildExecutor method withSolution.

public MSBuildExecutor withSolution(SolutionFile visualStudioSolution) {
    TestFile solutionFile = new TestFile(visualStudioSolution.getFile());
    solutionFile.assertIsFile();
    return addArguments(solutionFile.getAbsolutePath());
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile)

Aggregations

TestFile (org.gradle.test.fixtures.file.TestFile)53 Test (org.junit.Test)33 AbstractIntegrationTest (org.gradle.integtests.fixtures.AbstractIntegrationTest)25 File (java.io.File)5 ExecutionFailure (org.gradle.integtests.fixtures.executer.ExecutionFailure)4 OutputStream (java.io.OutputStream)2 URI (java.net.URI)2 MaybeCompressedFileResource (org.gradle.api.internal.file.MaybeCompressedFileResource)2 LocalResourceAdapter (org.gradle.api.resources.internal.LocalResourceAdapter)2 SourceFile (org.gradle.integtests.fixtures.SourceFile)2 DefaultExecHandleBuilder (org.gradle.process.internal.DefaultExecHandleBuilder)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ExecutionResult (org.gradle.integtests.fixtures.executer.ExecutionResult)1 IntegrationTestBuildContext (org.gradle.integtests.fixtures.executer.IntegrationTestBuildContext)1 AvailableToolChains (org.gradle.nativeplatform.fixtures.AvailableToolChains)1 ExecOutput (org.gradle.test.fixtures.file.ExecOutput)1