Search in sources :

Example 31 with TestFile

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

the class UriScriptSourceTest method convenienceMethodScriptForFileThatHasContent.

@Test
public void convenienceMethodScriptForFileThatHasContent() {
    new TestFile(scriptFile).write("content");
    ScriptSource source = UriScriptSource.file("<file-type>", scriptFile);
    assertThat(source, instanceOf(UriScriptSource.class));
    assertThat(source.getResource().getFile(), equalTo(scriptFile));
    assertThat(source.getResource().getCharset(), equalTo(Charset.forName("utf-8")));
    assertThat(source.getResource().getLocation().getFile(), equalTo(scriptFile));
    assertThat(source.getResource().getLocation().getURI(), equalTo(scriptFileUri));
    assertThat(source.getResource().getText(), equalTo("content"));
    assertFalse(source.getResource().isContentCached());
    assertFalse(source.getResource().getHasEmptyContent());
    assertTrue(source.getResource().getExists());
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) Test(org.junit.Test)

Example 32 with TestFile

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

the class IntegrationTestBuildContext method getFatToolingApiJar.

public TestFile getFatToolingApiJar() {
    TestFile toolingApiShadedJarDir = file("integTest.toolingApiShadedJarDir", "subprojects/tooling-api/build/shaded-jar");
    TestFile fatToolingApiJar = new TestFile(toolingApiShadedJarDir, String.format("gradle-tooling-api-shaded-%s.jar", getVersion().getBaseVersion().getVersion()));
    if (!fatToolingApiJar.exists()) {
        throw new IllegalStateException(String.format("The fat Tooling API JAR file does not exist: %s", fatToolingApiJar.getAbsolutePath()));
    }
    return fatToolingApiJar;
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile)

Example 33 with TestFile

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

the class Sample method apply.

public Statement apply(final Statement base, FrameworkMethod method, Object target) {
    sampleName = getSampleName(method);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            if (sampleName != null) {
                String hintForMissingSample = String.format("If '%s' is a new sample, try running 'gradle intTestImage'.", sampleName);
                TestFile srcDir = new IntegrationTestBuildContext().getSamplesDir().file(sampleName).assertIsDir(hintForMissingSample);
                logger.debug("Copying sample '{}' to test directory.", sampleName);
                srcDir.copyTo(getDir());
            } else {
                logger.debug("No sample specified for this test, skipping.");
            }
            base.evaluate();
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) TestFile(org.gradle.test.fixtures.file.TestFile) IntegrationTestBuildContext(org.gradle.integtests.fixtures.executer.IntegrationTestBuildContext)

Example 34 with TestFile

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

the class ForkingGradleExecuter 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()) {

        @Override
        public File getWorkingDir() {
            // the working directory is not canonicalised
            return ForkingGradleExecuter.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 35 with TestFile

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

the class WebProjectIntegrationTest method canCustomizeArchiveNamesUsingConventionProperties.

@Test
public void canCustomizeArchiveNamesUsingConventionProperties() {
    testFile("settings.gradle").writelns("rootProject.name = 'test'");
    TestFile buildFile = testFile("build.gradle");
    buildFile.writelns("apply plugin: 'war'", "buildDir = 'output'", "libsDirName = 'archives'", "archivesBaseName = 'test'", "version = '0.5-RC2'");
    testFile("src/main/resources/org/gradle/resource.file").write("some resource");
    usingBuildFile(buildFile).withTasks("assemble").run();
    testFile("output/archives/test-0.5-RC2.war").assertIsFile();
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) Test(org.junit.Test) AbstractIntegrationTest(org.gradle.integtests.fixtures.AbstractIntegrationTest)

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