Search in sources :

Example 11 with TestFile

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

the class ProjectLoadingIntegrationTest method buildFailsWhenSpecifiedSettingsFileDoesNotContainMatchingProject.

@Test
public void buildFailsWhenSpecifiedSettingsFileDoesNotContainMatchingProject() {
    TestFile settingsFile = testFile("settings.gradle");
    settingsFile.write("// empty");
    TestFile projectDir = testFile("project dir");
    TestFile buildFile = projectDir.file("build.gradle").createFile();
    ExecutionFailure result = usingProjectDir(projectDir).usingSettingsFile(settingsFile).runWithFailure();
    result.assertHasDescription(String.format("No projects in this build have project directory '%s'.", projectDir));
    result = usingBuildFile(buildFile).usingSettingsFile(settingsFile).runWithFailure();
    result.assertHasDescription(String.format("No projects in this build have build file '%s'.", buildFile));
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) ExecutionFailure(org.gradle.integtests.fixtures.executer.ExecutionFailure) Test(org.junit.Test) AbstractIntegrationTest(org.gradle.integtests.fixtures.AbstractIntegrationTest)

Example 12 with TestFile

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

the class ProjectLoadingIntegrationTest method handlesSimilarlyNamedBuildFilesInSameDirectory.

@Test
public void handlesSimilarlyNamedBuildFilesInSameDirectory() {
    TestFile buildFile1 = testFile("similarly-named build.gradle").write("task build");
    TestFile buildFile2 = testFile("similarly_named_build_gradle").write("task 'other-build'");
    usingBuildFile(buildFile1).withTasks("build").run();
    usingBuildFile(buildFile2).withTasks("other-build").run();
    usingBuildFile(buildFile1).withTasks("build").run();
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) Test(org.junit.Test) AbstractIntegrationTest(org.gradle.integtests.fixtures.AbstractIntegrationTest)

Example 13 with TestFile

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

the class MapFileTreeTest method doesNotOverwriteFileWhenGeneratedContentRemainsTheSame.

@Test
public void doesNotOverwriteFileWhenGeneratedContentRemainsTheSame() {
    Action<OutputStream> action = getAction();
    tree.add("path/file.txt", action);
    assertVisits(tree, toList("path/file.txt"), toList("path"));
    TestFile file = rootDir.file("path/file.txt");
    file.assertContents(equalTo("content"));
    TestFile.Snapshot snapshot = file.snapshot();
    try {
        // make sure file modification time would change if file would get written
        Thread.sleep(1000L);
    } catch (InterruptedException e) {
    // ignore
    }
    assertVisits(tree, toList("path/file.txt"), toList("path"));
    file.assertContents(equalTo("content"));
    file.assertHasNotChangedSince(snapshot);
}
Also used : OutputStream(java.io.OutputStream) TestFile(org.gradle.test.fixtures.file.TestFile) Test(org.junit.Test)

Example 14 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 15 with TestFile

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

the class TarFileTreeTest method readsGzippedTarFile.

@Test
public void readsGzippedTarFile() {
    TestFile tgz = tmpDir.getTestDirectory().file("test.tgz");
    rootDir.file("subdir/file1.txt").write("content");
    rootDir.file("subdir2/file2.txt").write("content");
    rootDir.tgzTo(tgz);
    TarFileTree tree = new TarFileTree(tarFile, new MaybeCompressedFileResource(new FileResource(tgz)), expandDir, fileSystem(), fileSystem(), directoryFileTreeFactory());
    assertVisits(tree, toList("subdir/file1.txt", "subdir2/file2.txt"), toList("subdir", "subdir2"));
    assertSetContainsForAllTypes(tree, toList("subdir/file1.txt", "subdir2/file2.txt"));
}
Also used : MaybeCompressedFileResource(org.gradle.api.internal.file.MaybeCompressedFileResource) TestFile(org.gradle.test.fixtures.file.TestFile) MaybeCompressedFileResource(org.gradle.api.internal.file.MaybeCompressedFileResource) FileResource(org.gradle.api.internal.file.FileResource) Test(org.junit.Test)

Aggregations

TestFile (org.gradle.test.fixtures.file.TestFile)34 Test (org.junit.Test)23 AbstractIntegrationTest (org.gradle.integtests.fixtures.AbstractIntegrationTest)18 File (java.io.File)5 OutputStream (java.io.OutputStream)2 FileResource (org.gradle.api.internal.file.FileResource)2 MaybeCompressedFileResource (org.gradle.api.internal.file.MaybeCompressedFileResource)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ExecutionFailure (org.gradle.integtests.fixtures.executer.ExecutionFailure)1 IntegrationTestBuildContext (org.gradle.integtests.fixtures.executer.IntegrationTestBuildContext)1 DefaultExecHandleBuilder (org.gradle.process.internal.DefaultExecHandleBuilder)1 Statement (org.junit.runners.model.Statement)1