aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-12-22 00:56:58 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-22 00:58:31 -0800
commite63a867feb2483851b5169894ff7b3c0bdb26581 (patch)
tree68306264ab9dc8f2383f987a42fb768b2d6436a8 /src/test/java/com/google/devtools/build/lib
parent85e8d51c72c5dcb4d1f6a8f3186149339ca59fac (diff)
Redo FileType to reduce generated garbage.
* Change FileType to no longer assume it operates on just the base name (it can now be given a full path). * Move the responsibility to specific classes (Artifact, Path, PathFragment) to decide how they want to offer up a string that includes the file name. * Flip the order in which users are expected to check Artifact type, from FileType#matches(Artifact) to Artifact#isFileType(FileType). This looks natural and should encourage developers to use efficient file type checking methods. * Change CppCompileAction to use the new API. RELNOTES: None PiperOrigin-RevId: 179903239
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r--src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java101
1 files changed, 50 insertions, 51 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java b/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java
index 30bb95d363..9662ca5fa6 100644
--- a/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java
@@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
-import com.google.devtools.build.lib.util.FileType.HasFilename;
+import com.google.devtools.build.lib.util.FileType.HasFileType;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
@@ -37,15 +37,15 @@ public class FileTypeTest {
private static final FileType JAVA_SOURCE = FileType.of(".java");
private static final FileType PYTHON_SOURCE = FileType.of(".py");
- private static final class HasFilenameImpl implements HasFilename {
+ private static final class HasFileTypeImpl implements HasFileType {
private final String path;
- private HasFilenameImpl(String path) {
+ private HasFileTypeImpl(String path) {
this.path = path;
}
@Override
- public String getFilename() {
+ public String filePathForFileTypeMatcher() {
return path;
}
@@ -101,11 +101,11 @@ public class FileTypeTest {
assertThat(allowedTypes.matches("style.css")).isFalse();
}
- private List<HasFilename> getArtifacts() {
- return Lists.<HasFilename>newArrayList(
- new HasFilenameImpl("Foo.java"),
- new HasFilenameImpl("bar.cc"),
- new HasFilenameImpl("baz.py"));
+ private List<HasFileType> getArtifacts() {
+ return Lists.newArrayList(
+ new HasFileTypeImpl("Foo.java"),
+ new HasFileTypeImpl("bar.cc"),
+ new HasFileTypeImpl("baz.py"));
}
private String filterAll(FileType... fileTypes) {
@@ -128,18 +128,13 @@ public class FileTypeTest {
.isEqualTo("Foo.java bar.cc baz.py");
}
- private HasFilename filename(final String name) {
- return new HasFilename() {
- @Override
- public String getFilename() {
- return name;
- }
- };
+ private HasFileType filename(final String name) {
+ return () -> name;
}
@Test
public void checkingSingleWithTypePredicate() throws Exception {
- FileType.HasFilename item = filename("config.txt");
+ HasFileType item = filename("config.txt");
assertThat(FileType.contains(item, TEXT)).isTrue();
assertThat(FileType.contains(item, CFG)).isFalse();
@@ -147,10 +142,8 @@ public class FileTypeTest {
@Test
public void checkingListWithTypePredicate() throws Exception {
- ImmutableList<FileType.HasFilename> unfiltered = ImmutableList.of(
- filename("config.txt"),
- filename("index.html"),
- filename("README.txt"));
+ ImmutableList<HasFileType> unfiltered =
+ ImmutableList.of(filename("config.txt"), filename("index.html"), filename("README.txt"));
assertThat(FileType.contains(unfiltered, TEXT)).isTrue();
assertThat(FileType.contains(unfiltered, CFG)).isFalse();
@@ -158,11 +151,12 @@ public class FileTypeTest {
@Test
public void filteringWithTypePredicate() throws Exception {
- ImmutableList<FileType.HasFilename> unfiltered = ImmutableList.of(
- filename("config.txt"),
- filename("index.html"),
- filename("README.txt"),
- filename("archive.zip"));
+ ImmutableList<HasFileType> unfiltered =
+ ImmutableList.of(
+ filename("config.txt"),
+ filename("index.html"),
+ filename("README.txt"),
+ filename("archive.zip"));
assertThat(FileType.filter(unfiltered, TEXT)).containsExactly(unfiltered.get(0),
unfiltered.get(2)).inOrder();
@@ -170,11 +164,12 @@ public class FileTypeTest {
@Test
public void filteringWithMatcherPredicate() throws Exception {
- ImmutableList<FileType.HasFilename> unfiltered = ImmutableList.of(
- filename("config.txt"),
- filename("index.html"),
- filename("README.txt"),
- filename("archive.zip"));
+ ImmutableList<HasFileType> unfiltered =
+ ImmutableList.of(
+ filename("config.txt"),
+ filename("index.html"),
+ filename("README.txt"),
+ filename("archive.zip"));
assertThat(FileType.filter(unfiltered, TEXT::matches))
.containsExactly(unfiltered.get(0), unfiltered.get(2))
@@ -183,22 +178,24 @@ public class FileTypeTest {
@Test
public void filteringWithAlwaysFalse() throws Exception {
- ImmutableList<FileType.HasFilename> unfiltered = ImmutableList.of(
- filename("config.txt"),
- filename("index.html"),
- filename("binary"),
- filename("archive.zip"));
+ ImmutableList<HasFileType> unfiltered =
+ ImmutableList.of(
+ filename("config.txt"),
+ filename("index.html"),
+ filename("binary"),
+ filename("archive.zip"));
assertThat(FileType.filter(unfiltered, FileTypeSet.NO_FILE)).isEmpty();
}
@Test
public void filteringWithAlwaysTrue() throws Exception {
- ImmutableList<FileType.HasFilename> unfiltered = ImmutableList.of(
- filename("config.txt"),
- filename("index.html"),
- filename("binary"),
- filename("archive.zip"));
+ ImmutableList<HasFileType> unfiltered =
+ ImmutableList.of(
+ filename("config.txt"),
+ filename("index.html"),
+ filename("binary"),
+ filename("archive.zip"));
assertThat(FileType.filter(unfiltered, FileTypeSet.ANY_FILE)).containsExactly(unfiltered.get(0),
unfiltered.get(1), unfiltered.get(2), unfiltered.get(3)).inOrder();
@@ -206,11 +203,12 @@ public class FileTypeTest {
@Test
public void exclusionWithTypePredicate() throws Exception {
- ImmutableList<FileType.HasFilename> unfiltered = ImmutableList.of(
- filename("config.txt"),
- filename("index.html"),
- filename("README.txt"),
- filename("server.cfg"));
+ ImmutableList<HasFileType> unfiltered =
+ ImmutableList.of(
+ filename("config.txt"),
+ filename("index.html"),
+ filename("README.txt"),
+ filename("server.cfg"));
assertThat(FileType.except(unfiltered, TEXT)).containsExactly(unfiltered.get(1),
unfiltered.get(3)).inOrder();
@@ -218,11 +216,12 @@ public class FileTypeTest {
@Test
public void listFiltering() throws Exception {
- ImmutableList<FileType.HasFilename> unfiltered = ImmutableList.of(
- filename("config.txt"),
- filename("index.html"),
- filename("README.txt"),
- filename("server.cfg"));
+ ImmutableList<HasFileType> unfiltered =
+ ImmutableList.of(
+ filename("config.txt"),
+ filename("index.html"),
+ filename("README.txt"),
+ filename("server.cfg"));
FileTypeSet filter = FileTypeSet.of(HTML, CFG);
assertThat(FileType.filterList(unfiltered, filter)).containsExactly(unfiltered.get(1),