Search in sources :

Example 1 with TestFile

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

the class MapFileTreeTest method overwritesFileWhenGeneratedContentChanges.

@Test
public void overwritesFileWhenGeneratedContentChanges() {
    final AtomicReference<String> currentContentReference = new AtomicReference<String>("content");
    tree.add("path/file.txt", new Action<OutputStream>() {

        @Override
        public void execute(OutputStream outputStream) {
            try {
                outputStream.write(currentContentReference.get().getBytes());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
    assertVisits(tree, toList("path/file.txt"), toList("path"));
    TestFile file = rootDir.file("path/file.txt");
    file.assertContents(equalTo("content"));
    TestFile.Snapshot snapshot = file.snapshot();
    currentContentReference.set("updated content");
    assertVisits(tree, toList("path/file.txt"), toList("path"));
    file.assertContents(equalTo("updated content"));
    file.assertHasChangedSince(snapshot);
}
Also used : OutputStream(java.io.OutputStream) TestFile(org.gradle.test.fixtures.file.TestFile) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Test(org.junit.Test)

Example 2 with TestFile

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

the class JvmSourceFile method writeToDir.

public TestFile writeToDir(TestFile base) {
    TestFile file = base.file(path, name);
    writeToFile(file);
    return file;
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile)

Example 3 with TestFile

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

the class WebProjectIntegrationTest method generatesArtifactsWhenVersionIsEmpty.

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

Example 4 with TestFile

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

the class SourceFile method writeToDir.

public TestFile writeToDir(TestFile base) {
    TestFile file = base.file(path, name);
    writeToFile(file);
    return file;
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile)

Example 5 with TestFile

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

the class IntegrationTestBuildContext method file.

protected static TestFile file(String propertyName, String defaultFile) {
    String defaultPath;
    if (defaultFile == null) {
        defaultPath = null;
    } else if (new File(defaultFile).isAbsolute()) {
        defaultPath = defaultFile;
    } else {
        defaultPath = TEST_DIR.file(defaultFile).getAbsolutePath();
    }
    String path = System.getProperty(propertyName, defaultPath);
    if (path == null) {
        throw new RuntimeException(String.format("You must set the '%s' property to run the integration tests. The default passed was: '%s'", propertyName, defaultFile));
    }
    return new TestFile(new File(path));
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) TestFile(org.gradle.test.fixtures.file.TestFile) File(java.io.File)

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