aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-11-06 19:49:16 +0100
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-11-06 20:20:32 +0100
commit67c84b1036ad02ba2384fa75fb28e779a488f3d4 (patch)
treec70665241fab2a4947f0941659b8e6421eabb44c /src/test/java/com/google/devtools/build/lib
parent11517396816697ad1c48a71e47f37d9206225741 (diff)
Break dependency on vfs from the interface of syntax and cmdline.
These libs are exposed externally, implying that the vfs is also exposed externally. We break out PathFragment from vfs to still use this in their interface. This class is a much smaller dependency than the entire vfs. PiperOrigin-RevId: 174729373
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java7
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java7
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java6
6 files changed, 24 insertions, 10 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java b/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java
index e92d3af074..2a4dbeaa4e 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java
@@ -27,6 +27,7 @@ import com.google.devtools.build.lib.syntax.ParserInputSource;
import com.google.devtools.build.lib.syntax.SkylarkSemantics;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
import java.util.List;
@@ -150,8 +151,11 @@ public class WorkspaceFactoryTest {
root);
Exception exception = null;
try {
+ byte[] bytes =
+ FileSystemUtils.readWithKnownFileSize(
+ workspaceFilePath, workspaceFilePath.getFileSize());
factory.parse(
- ParserInputSource.create(workspaceFilePath),
+ ParserInputSource.create(bytes, workspaceFilePath.asFragment()),
SkylarkSemantics.DEFAULT_SEMANTICS,
eventHandler);
} catch (BuildFileContainsErrorsException e) {
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java b/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java
index e487f3fdb4..742f616496 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java
@@ -38,6 +38,7 @@ import com.google.devtools.build.lib.syntax.SkylarkSemantics;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.util.Pair;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
@@ -109,7 +110,8 @@ public class PackageFactoryApparatus {
* Parses the {@code buildFile} into a {@link BuildFileAST}.
*/
public BuildFileAST ast(Path buildFile) throws IOException {
- ParserInputSource inputSource = ParserInputSource.create(buildFile);
+ byte[] bytes = FileSystemUtils.readWithKnownFileSize(buildFile, buildFile.getFileSize());
+ ParserInputSource inputSource = ParserInputSource.create(bytes, buildFile.asFragment());
return BuildFileAST.parseBuildFile(inputSource, eventHandler);
}
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
index bb588ecfe4..07079d9d09 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
@@ -670,9 +670,10 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
* usually write those files using UTF-8 encoding. Currently, the string-valued 'substitutions'
* parameter of the template_action function contains a hack that assumes its input is a UTF-8
* encoded string which has been ingested as Latin 1. The hack converts the string to its
- * "correct" UTF-8 value. Once {@link com.google.devtools.build.lib.syntax.ParserInputSource#create(com.google.devtools.build.lib.vfs.Path)}
- * parses files using UTF-8 and the hack for the substituations parameter is removed, this test
- * will fail.
+ * "correct" UTF-8 value. Once {@link
+ * com.google.devtools.build.lib.syntax.ParserInputSource#create(byte[],
+ * com.google.devtools.build.lib.vfs.PathFragment)} parses files using UTF-8 and the hack for the
+ * substituations parameter is removed, this test will fail.
*/
@Test
public void testCreateTemplateActionWithWrongEncoding() throws Exception {
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
index aef5f82c27..f1aa92f02a 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
@@ -20,6 +20,7 @@ import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.testutil.Scratch;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
import org.junit.Test;
@@ -45,7 +46,8 @@ public class BuildFileASTTest extends EvaluationTestCase {
*/
private BuildFileAST parseBuildFile(String... lines) throws IOException {
Path file = scratch.file("/a/build/file/BUILD", lines);
- ParserInputSource inputSource = ParserInputSource.create(file, file.getFileSize());
+ byte[] bytes = FileSystemUtils.readWithKnownFileSize(file, file.getFileSize());
+ ParserInputSource inputSource = ParserInputSource.create(bytes, file.asFragment());
return BuildFileAST.parseBuildFile(inputSource, getEventHandler());
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
index ce459d2eb8..fc8fb6b1a7 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
@@ -18,6 +18,7 @@ import static com.google.devtools.build.lib.util.StringUtilities.joinLines;
import static org.junit.Assert.fail;
import com.google.devtools.build.lib.testutil.Scratch;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.IOException;
@@ -36,7 +37,8 @@ public class ParserInputSourceTest {
public void testCreateFromFile() throws IOException {
String content = joinLines("Line 1", "Line 2", "Line 3", "");
Path file = scratch.file("/tmp/my/file.txt", content.getBytes(StandardCharsets.UTF_8));
- ParserInputSource input = ParserInputSource.create(file);
+ byte[] bytes = FileSystemUtils.readWithKnownFileSize(file, file.getFileSize());
+ ParserInputSource input = ParserInputSource.create(bytes, file.asFragment());
assertThat(new String(input.getContent())).isEqualTo(content);
assertThat(input.getPath().toString()).isEqualTo("/tmp/my/file.txt");
}
@@ -65,7 +67,8 @@ public class ParserInputSourceTest {
public void testIOExceptionIfInputFileDoesNotExistForSingleArgConstructor() {
try {
Path path = scratch.resolve("/does/not/exist");
- ParserInputSource.create(path);
+ byte[] bytes = FileSystemUtils.readWithKnownFileSize(path, path.getFileSize());
+ ParserInputSource.create(bytes, path.asFragment());
fail();
} catch (IOException e) {
String expected = "/does/not/exist (No such file or directory)";
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java
index 39f46d03b2..bdeb5ae680 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
import com.google.devtools.build.lib.testutil.Scratch;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
import java.util.ArrayList;
@@ -24,7 +25,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-
/** Tests for @{code SyntaxTreeVisitor} */
@RunWith(JUnit4.class)
public class SyntaxTreeVisitorTest {
@@ -34,7 +34,9 @@ public class SyntaxTreeVisitorTest {
/** Parses the contents of the specified string and returns the AST. */
private BuildFileAST parse(String... lines) throws IOException {
Path file = scratch.file("/a/build/file/BUILD", lines);
- return BuildFileAST.parseSkylarkFile(file, null /* reporter */);
+ byte[] bytes = FileSystemUtils.readWithKnownFileSize(file, file.getFileSize());
+ return BuildFileAST.parseSkylarkFile(
+ bytes, file.getDigest(), file.asFragment(), /* reporter */ null);
}
@Test