This repository has been archived by the owner on May 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented removal .css counterpart for deleted sass source file
- Loading branch information
Showing
2 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
plugin/src/test/java/org/kravemir/gradle/sass/tests/IncrementalTasksTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.kravemir.gradle.sass.tests; | ||
|
||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.gradle.testkit.runner.TaskOutcome; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author Miroslav Kravec | ||
*/ | ||
public class IncrementalTasksTest { | ||
|
||
@Rule | ||
public final TemporaryFolder testProjectDir = new TemporaryFolder(); | ||
|
||
private File fooScss; | ||
|
||
|
||
@Before | ||
public void setup() throws IOException { | ||
File buildFile = testProjectDir.newFile("build.gradle"); | ||
writeFile(buildFile, "plugins {\n id 'org.kravemir.gradle.sass'\n }\nsass{\nmain{}}"); | ||
|
||
Path mainSassPath = Paths.get(testProjectDir.getRoot().getPath(),"src","main","sass"); | ||
Files.createDirectories(mainSassPath); | ||
|
||
File mainScss = mainSassPath.resolve("main.scss").toFile(); | ||
mainScss.createNewFile(); | ||
|
||
fooScss = mainSassPath.resolve("foo.scss").toFile(); | ||
fooScss.createNewFile(); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void testFooDeletion() { | ||
BuildResult result = GradleRunner.create() | ||
.withProjectDir(testProjectDir.getRoot()) | ||
.withArguments("mainSass") | ||
.withPluginClasspath() | ||
.build(); | ||
|
||
assertEquals("check that ':mainSass' task succeeded", result.task(":mainSass").getOutcome(), TaskOutcome.SUCCESS); | ||
|
||
Path mainSassBuildRoot = Paths.get(testProjectDir.getRoot().getPath(), "build", "sass", "main"); | ||
assertTrue(mainSassBuildRoot.resolve(Paths.get("main.css")).toFile().exists()); | ||
assertTrue(mainSassBuildRoot.resolve(Paths.get("foo.css")).toFile().exists()); | ||
|
||
fooScss.delete(); | ||
|
||
BuildResult result2 = GradleRunner.create() | ||
.withProjectDir(testProjectDir.getRoot()) | ||
.withArguments("mainSass") | ||
.withPluginClasspath() | ||
.build(); | ||
|
||
assertEquals("check that ':mainSass' task succeeded", result2.task(":mainSass").getOutcome(), TaskOutcome.SUCCESS); | ||
|
||
assertTrue(mainSassBuildRoot.resolve(Paths.get("main.css")).toFile().exists()); | ||
assertFalse(mainSassBuildRoot.resolve(Paths.get("foo.css")).toFile().exists()); | ||
} | ||
|
||
|
||
private void writeFile(File destination, String content) throws IOException { | ||
BufferedWriter output = null; | ||
try { | ||
output = new BufferedWriter(new FileWriter(destination)); | ||
output.write(content); | ||
} finally { | ||
if (output != null) { | ||
output.close(); | ||
} | ||
} | ||
} | ||
} |