aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2015-09-18 08:18:11 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-09-21 08:56:12 +0000
commitd9e733d8cd64450ab8690ab3227bba6b254e5898 (patch)
tree7c22fd2c399ce7d5ba00344c73bd9eb74146a343 /src/test/java/com/google/devtools/build
parent47cb916ec6f41b8ecbd377ed875f842c3d349b12 (diff)
Remove support for the deprecated include() statement in order to be able to separate Skylark from the rest of the code so that Label parsing can be simplified.
This is another go at []: now that the tests were fixed in [] and [] it can be submitted again. -- MOS_MIGRATED_REVID=103364881
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java127
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/EvaluationTestCase.java5
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java18
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java14
5 files changed, 11 insertions, 156 deletions
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 e1f7271f3e..82c6aa515f 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
@@ -107,8 +107,7 @@ public class PackageFactoryApparatus {
*/
public BuildFileAST ast(Path buildFile) throws IOException {
ParserInputSource inputSource = ParserInputSource.create(buildFile);
- return BuildFileAST.parseBuildFile(inputSource, events.reporter(), locator,
- /*parsePython=*/false);
+ return BuildFileAST.parseBuildFile(inputSource, events.reporter(), /*parsePython=*/false);
}
/**
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 00e9062d63..ecbb85bc34 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
@@ -48,8 +48,6 @@ public class BuildFileASTTest extends EvaluationTestCase {
}
}
- private CachingPackageLocator locator = new ScratchPathPackageLocator();
-
@Override
public Environment newEnvironment() throws Exception {
return newBuildEnvironment();
@@ -61,7 +59,7 @@ public class BuildFileASTTest extends EvaluationTestCase {
*/
private BuildFileAST parseBuildFile(String... lines) throws IOException {
Path file = scratch.file("/a/build/file/BUILD", lines);
- return BuildFileAST.parseBuildFile(file, getEventHandler(), locator, false);
+ return BuildFileAST.parseBuildFile(file, getEventHandler(), false);
}
@Test
@@ -71,7 +69,7 @@ public class BuildFileASTTest extends EvaluationTestCase {
"",
"x = [1,2,'foo',4] + [1,2, \"%s%d\" % ('foo', 1)]");
- BuildFileAST buildfile = BuildFileAST.parseBuildFile(buildFile, getEventHandler(), null, false);
+ BuildFileAST buildfile = BuildFileAST.parseBuildFile(buildFile, getEventHandler(), false);
assertTrue(buildfile.exec(env, getEventHandler()));
@@ -92,7 +90,7 @@ public class BuildFileASTTest extends EvaluationTestCase {
"z = x + y");
setFailFast(false);
- BuildFileAST buildfile = BuildFileAST.parseBuildFile(buildFile, getEventHandler(), null, false);
+ BuildFileAST buildfile = BuildFileAST.parseBuildFile(buildFile, getEventHandler(), false);
assertFalse(buildfile.exec(env, getEventHandler()));
Event e = assertContainsEvent("unsupported operand type(s) for +: 'int' and 'List'");
@@ -181,123 +179,4 @@ public class BuildFileASTTest extends EvaluationTestCase {
// This message should not be printed anymore.
assertNull(findEvent(getEventCollector(), "contains syntax error(s)"));
}
-
- @Test
- public void testInclude() throws Exception {
- scratch.file("/foo/bar/BUILD",
- "c = 4\n"
- + "d = 5\n");
- Path buildFile = scratch.file("/BUILD",
- "a = 2\n"
- + "include(\"//foo/bar:BUILD\")\n"
- + "b = 4\n");
-
- BuildFileAST buildFileAST = BuildFileAST.parseBuildFile(buildFile, getEventHandler(),
- locator, false);
-
- assertFalse(buildFileAST.containsErrors());
- assertThat(buildFileAST.getStatements()).hasSize(5);
- }
-
- @Test
- public void testInclude2() throws Exception {
- scratch.file("/foo/bar/defs",
- "a = 1\n");
- Path buildFile = scratch.file("/BUILD",
- "include(\"//foo/bar:defs\")\n"
- + "b = a + 1\n");
-
- BuildFileAST buildFileAST = BuildFileAST.parseBuildFile(buildFile, getEventHandler(),
- locator, false);
-
- assertFalse(buildFileAST.containsErrors());
- assertThat(buildFileAST.getStatements()).hasSize(3);
-
- setFailFast(false);
- assertFalse(buildFileAST.exec(env, getEventHandler()));
- assertEquals(2, env.lookup("b"));
- }
-
- @Test
- public void testMultipleIncludes() throws Exception {
- String fileA =
- "include(\"//foo:fileB\")\n"
- + "include(\"//foo:fileC\")\n";
- scratch.file("/foo/fileB",
- "b = 3\n"
- + "include(\"//foo:fileD\")\n");
- scratch.file("/foo/fileC",
- "include(\"//foo:fileD\")\n"
- + "c = b + 2\n");
- scratch.file("/foo/fileD",
- "b = b + 1\n"); // this code is included twice
-
- BuildFileAST buildFileAST = parseBuildFile(fileA);
- assertFalse(buildFileAST.containsErrors());
- assertThat(buildFileAST.getStatements()).hasSize(8);
-
- setFailFast(false);
- assertFalse(buildFileAST.exec(env, getEventHandler()));
- assertEquals(5, env.lookup("b"));
- assertEquals(7, env.lookup("c"));
- }
-
- @Test
- public void testFailInclude() throws Exception {
- setFailFast(false);
- BuildFileAST buildFileAST = parseBuildFile("include(\"//nonexistent\")");
- assertThat(buildFileAST.getStatements()).hasSize(1);
- assertContainsEvent("Include of '//nonexistent' failed");
- }
-
-
- @Test
- public void testFailInclude2() throws Exception {
- setFailFast(false);
- Path buildFile = scratch.file("/foo/bar/BUILD",
- "include(\"//nonexistent:foo\")\n");
- BuildFileAST buildFileAST = BuildFileAST.parseBuildFile(
- buildFile, getEventHandler(), Environment.EMPTY_PACKAGE_LOCATOR, false);
- assertThat(buildFileAST.getStatements()).hasSize(1);
- assertContainsEvent("Package 'nonexistent' not found");
- }
-
- @Test
- public void testInvalidInclude() throws Exception {
- setFailFast(false);
- BuildFileAST buildFileAST = parseBuildFile("include(2)");
- assertThat(buildFileAST.getStatements()).isEmpty();
- assertContainsEvent("syntax error at '2'");
- }
-
- @Test
- public void testRecursiveInclude() throws Exception {
- setFailFast(false);
- Path buildFile = scratch.file("/foo/bar/BUILD",
- "include(\"//foo/bar:BUILD\")\n");
-
- BuildFileAST.parseBuildFile(buildFile, getEventHandler(), locator, false);
- assertContainsEvent("Recursive inclusion");
- }
-
- @Test
- public void testParseErrorInclude() throws Exception {
- setFailFast(false);
-
- scratch.file("/foo/bar/file",
- "a = 2 + % 3\n"); // parse error
-
- parseBuildFile("include(\"//foo/bar:file\")");
-
- // Check the location is properly reported
- Event event = assertContainsEvent("syntax error at '%': expected expression");
- assertEquals("/foo/bar/file:1:9", event.getLocation().print());
- }
-
- @Test
- public void testNonExistentIncludeReported() throws Exception {
- setFailFast(false);
- BuildFileAST buildFileAST = parseBuildFile("include('//foo:bar')");
- assertThat(buildFileAST.getStatements()).hasSize(1);
- }
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTestCase.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTestCase.java
index e26234af0c..553385d58b 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTestCase.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
+import com.google.common.base.Joiner;
import com.google.common.truth.Ordered;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventCollector;
@@ -137,7 +138,9 @@ public class EvaluationTestCase {
/** Parses an Expression from string without a supporting file */
Expression parseExpression(String... input) {
- return Parser.parseExpression(env.createLexer(input), getEventHandler());
+ return Parser.parseExpression(
+ ParserInputSource.create(Joiner.on("\n").join(input), null),
+ getEventHandler());
}
public EvaluationTestCase update(String varname, Object value) throws Exception {
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
index 75913b42d5..9dc2a15db0 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.syntax.DictionaryLiteral.DictionaryEntryLiteral;
@@ -60,9 +61,8 @@ public class ParserTest extends EvaluationTestCase {
/** Parses a build code (not Skylark) with PythonProcessing enabled */
private List<Statement> parseFileWithPython(String... input) {
return Parser.parseFile(
- buildEnvironment.createLexer(input),
+ ParserInputSource.create(Joiner.on("\n").join(input), null),
getEventHandler(),
- Environment.EMPTY_PACKAGE_LOCATOR,
/*parsePython=*/true).statements;
}
@@ -1252,18 +1252,4 @@ public class ParserTest extends EvaluationTestCase {
" else: return a");
assertContainsEvent("syntax error at 'else'");
}
-
- @Test
- public void testIncludeFailureSkylark() throws Exception {
- setFailFast(false);
- parseFileForSkylark("include('//foo:bar')");
- assertContainsEvent("function 'include' does not exist");
- }
-
- @Test
- public void testIncludeFailure() throws Exception {
- setFailFast(false);
- parseFile("include('nonexistent')\n");
- assertContainsEvent("Invalid label 'nonexistent'");
- }
}
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 72edba4765..76f70ad4ea 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
@@ -15,8 +15,6 @@ package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.packages.CachingPackageLocator;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
@@ -35,20 +33,10 @@ public class SyntaxTreeVisitorTest {
private Scratch scratch = new Scratch();
- private class ScratchPathPackageLocator implements CachingPackageLocator {
- @Override
- public Path getBuildFileForPackage(PackageIdentifier packageName) {
- return scratch.resolve(packageName.getPackageFragment()).getRelative("BUILD");
- }
- }
-
- private CachingPackageLocator locator = new ScratchPathPackageLocator();
-
/** 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 */, locator, null /*validationEnvironment*/);
+ return BuildFileAST.parseSkylarkFile(file, null /* reporter */, null /*validationEnvironment*/);
}
@Test