aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2018-03-01 08:07:14 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-01 08:09:26 -0800
commit940dbc531bf79907806bcf4f09543b3a2468d9b1 (patch)
tree5ee410c3cefa2e1913e57d2bd7b22235e13d2b72 /src/test
parent06e687495b4c85f86215c7cc7f1a01dc7f6709f9 (diff)
Remove --incompatible_load_argument_is_label flag
RELNOTES: Removed flag `--incompatible_load_argument_is_label`. PiperOrigin-RevId: 187479614
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkDefinedAspectsTest.java5
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java46
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java21
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkImportsTest.java64
4 files changed, 26 insertions, 110 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkDefinedAspectsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkDefinedAspectsTest.java
index 7bbd834937..d4ad66d66b 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkDefinedAspectsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkDefinedAspectsTest.java
@@ -1191,10 +1191,7 @@ public class SkylarkDefinedAspectsTest extends AnalysisTestCase {
} catch (ViewCreationFailedException e) {
// expect to fail.
}
- assertContainsEvent(
- "Every .bzl file must have a corresponding package, but 'foo' does not have one. "
- + "Please create a BUILD file in the same or any parent directory. "
- + "Note that this BUILD file does not need to do anything except exist.");
+ assertContainsEvent("Extension file not found. Unable to load package for '//foo:aspect.bzl'");
}
@Test
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 85ffb0ef5b..0e4efa1d81 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
@@ -1119,15 +1119,8 @@ public class ParserTest extends EvaluationTestCase {
}
@Test
- public void testValidRelativeImportPathInPackageDir() throws Exception {
- validNonAbsoluteImportTest("file", /*containing*/ "//some/skylark:BUILD",
- /*expected*/ "//some/skylark:file.bzl");
- }
-
- @Test
- public void testValidRelativeImportPathInPackageSubdir() throws Exception {
- validNonAbsoluteImportTest("file", /*containing*/ "//some/path/to:skylark/parent.bzl",
- /*expected*/ "//some/path/to:skylark/file.bzl");
+ public void testRelativeImportPathInIsInvalid() throws Exception {
+ invalidImportTest("file", SkylarkImports.INVALID_PATH_SYNTAX);
}
@Test
@@ -1142,7 +1135,7 @@ public class ParserTest extends EvaluationTestCase {
@Test
public void testInvalidRelativePathInvalidFilename() throws Exception {
- invalidImportTest("\tfile", SkylarkImports.INVALID_FILENAME_PREFIX);
+ invalidImportTest("\tfile", SkylarkImports.INVALID_PATH_SYNTAX);
}
private void validAbsoluteImportLabelTest(String importString)
@@ -1220,39 +1213,36 @@ public class ParserTest extends EvaluationTestCase {
@Test
public void testLoadNoSymbol() throws Exception {
setFailFast(false);
- parseFileForSkylark("load('/foo/bar/file')\n");
+ parseFileForSkylark("load('//foo/bar:file.bzl')\n");
assertContainsError("expected at least one symbol to load");
}
@Test
public void testLoadOneSymbol() throws Exception {
- List<Statement> statements = parseFileForSkylark(
- "load('/foo/bar/file', 'fun_test')\n");
+ List<Statement> statements = parseFileForSkylark("load('//foo/bar:file.bzl', 'fun_test')\n");
LoadStatement stmt = (LoadStatement) statements.get(0);
- assertThat(stmt.getImport().getValue()).isEqualTo("/foo/bar/file");
+ assertThat(stmt.getImport().getValue()).isEqualTo("//foo/bar:file.bzl");
assertThat(stmt.getSymbols()).hasSize(1);
Identifier sym = stmt.getSymbols().get(0);
int startOffset = sym.getLocation().getStartOffset();
int endOffset = sym.getLocation().getEndOffset();
- assertThat(startOffset).named("getStartOffset()").isEqualTo(22);
+ assertThat(startOffset).named("getStartOffset()").isEqualTo(27);
assertThat(endOffset).named("getEndOffset()").isEqualTo(startOffset + 10);
}
@Test
public void testLoadOneSymbolWithTrailingComma() throws Exception {
- List<Statement> statements = parseFileForSkylark(
- "load('/foo/bar/file', 'fun_test',)\n");
+ List<Statement> statements = parseFileForSkylark("load('//foo/bar:file.bzl', 'fun_test',)\n");
LoadStatement stmt = (LoadStatement) statements.get(0);
- assertThat(stmt.getImport().getValue()).isEqualTo("/foo/bar/file");
+ assertThat(stmt.getImport().getValue()).isEqualTo("//foo/bar:file.bzl");
assertThat(stmt.getSymbols()).hasSize(1);
}
@Test
public void testLoadMultipleSymbols() throws Exception {
- List<Statement> statements = parseFileForSkylark(
- "load('file', 'foo', 'bar')\n");
+ List<Statement> statements = parseFileForSkylark("load(':file.bzl', 'foo', 'bar')\n");
LoadStatement stmt = (LoadStatement) statements.get(0);
- assertThat(stmt.getImport().getValue()).isEqualTo("file");
+ assertThat(stmt.getImport().getValue()).isEqualTo(":file.bzl");
assertThat(stmt.getSymbols()).hasSize(2);
}
@@ -1286,8 +1276,8 @@ public class ParserTest extends EvaluationTestCase {
@Test
public void testLoadAlias() throws Exception {
- List<Statement> statements = parseFileForSkylark(
- "load('/foo/bar/file', my_alias = 'lawl')\n");
+ List<Statement> statements =
+ parseFileForSkylark("load('//foo/bar:file.bzl', my_alias = 'lawl')\n");
LoadStatement stmt = (LoadStatement) statements.get(0);
ImmutableList<Identifier> actualSymbols = stmt.getSymbols();
@@ -1296,7 +1286,7 @@ public class ParserTest extends EvaluationTestCase {
assertThat(sym.getName()).isEqualTo("my_alias");
int startOffset = sym.getLocation().getStartOffset();
int endOffset = sym.getLocation().getEndOffset();
- assertThat(startOffset).named("getStartOffset()").isEqualTo(22);
+ assertThat(startOffset).named("getStartOffset()").isEqualTo(27);
assertThat(endOffset).named("getEndOffset()").isEqualTo(startOffset + 8);
}
@@ -1308,7 +1298,7 @@ public class ParserTest extends EvaluationTestCase {
private void runLoadAliasTestForSymbols(String loadSymbolString, String... expectedSymbols) {
List<Statement> statements =
- parseFileForSkylark(String.format("load('/foo/bar/file', %s)\n", loadSymbolString));
+ parseFileForSkylark(String.format("load('//foo/bar:file.bzl', %s)\n", loadSymbolString));
LoadStatement stmt = (LoadStatement) statements.get(0);
ImmutableList<Identifier> actualSymbols = stmt.getSymbols();
@@ -1326,13 +1316,13 @@ public class ParserTest extends EvaluationTestCase {
@Test
public void testLoadAliasSyntaxError() throws Exception {
setFailFast(false);
- parseFileForSkylark("load('/foo', test1 = )\n");
+ parseFileForSkylark("load('//foo:bzl', test1 = )\n");
assertContainsError("syntax error at ')': expected string");
- parseFileForSkylark("load('/foo', test2 = 1)\n");
+ parseFileForSkylark("load(':foo.bzl', test2 = 1)\n");
assertContainsError("syntax error at '1': expected string");
- parseFileForSkylark("load('/foo', test3 = old)\n");
+ parseFileForSkylark("load(':foo.bzl', test3 = old)\n");
assertContainsError("syntax error at 'old': expected string");
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index a73006941e..9711dea3f5 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -1670,39 +1670,20 @@ public class SkylarkEvaluationTest extends EvaluationTest {
@Test
public void testLoadStatementWithAbsolutePath() throws Exception {
- env = newEnvironmentWithSkylarkOptions("--incompatible_load_argument_is_label");
checkEvalErrorContains(
"First argument of 'load' must be a label and start with either '//', ':', or '@'.",
"load('/tmp/foo', 'arg')");
}
@Test
- public void testAllowLoadStatementWithAbsolutePath() throws Exception {
- env = newEnvironmentWithSkylarkOptions("--incompatible_load_argument_is_label=false");
- checkEvalErrorDoesNotContain(
- "First argument of 'load' must be a label and start with either '//', ':', or '@'.",
- "load('/tmp/foo', 'arg')");
- }
-
- @Test
public void testLoadStatementWithRelativePath() throws Exception {
- env = newEnvironmentWithSkylarkOptions("--incompatible_load_argument_is_label");
checkEvalErrorContains(
"First argument of 'load' must be a label and start with either '//', ':', or '@'.",
"load('foo', 'arg')");
}
@Test
- public void testAllowLoadStatementWithRelativePath() throws Exception {
- env = newEnvironmentWithSkylarkOptions("--incompatible_load_argument_is_label=false");
- checkEvalErrorDoesNotContain(
- "First argument of 'load' must be a label and start with either '//', ':', or '@'.",
- "load('foo', 'arg')");
- }
-
- @Test
public void testLoadStatementWithExternalLabel() throws Exception {
- env = newEnvironmentWithSkylarkOptions("--incompatible_load_argument_is_label");
checkEvalErrorDoesNotContain(
"First argument of 'load' must be a label and start with either '//', ':', or '@'.",
"load('@other//foo.bzl', 'arg')");
@@ -1710,7 +1691,6 @@ public class SkylarkEvaluationTest extends EvaluationTest {
@Test
public void testLoadStatementWithAbsoluteLabel() throws Exception {
- env = newEnvironmentWithSkylarkOptions("--incompatible_load_argument_is_label");
checkEvalErrorDoesNotContain(
"First argument of 'load' must be a label and start with either '//', ':', or '@'.",
"load('//foo.bzl', 'arg')");
@@ -1718,7 +1698,6 @@ public class SkylarkEvaluationTest extends EvaluationTest {
@Test
public void testLoadStatementWithRelativeLabel() throws Exception {
- env = newEnvironmentWithSkylarkOptions("--incompatible_load_argument_is_label");
checkEvalErrorDoesNotContain(
"First argument of 'load' must be a label and start with either '//', ':', or '@'.",
"load(':foo.bzl', 'arg')");
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkImportsTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkImportsTest.java
index 3488047237..c1168dd380 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkImportsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkImportsTest.java
@@ -66,25 +66,6 @@ public class SkylarkImportsTest {
/*expected path*/ "/some/skylark/file.bzl");
}
- @Test
- public void testValidAbsolutePath() throws Exception {
- String pathToTest = "/some/skylark/file";
- SkylarkImport importForPath = SkylarkImports.create(pathToTest);
-
- assertThat(importForPath.hasAbsolutePath()).named("hasAbsolutePath()").isTrue();
- assertThat(importForPath.getImportString()).named("getImportString()").isEqualTo(pathToTest);
-
- Label irrelevantContainingFile = Label.parseAbsoluteUnchecked("//another/path:BUILD");
- assertThat(importForPath.getAbsolutePath()).named("getAbsolutePath()")
- .isEqualTo(PathFragment.create("//some/skylark/file.bzl"));
-
- assertThat(importForPath.asPathFragment()).named("asPathFragment()")
- .isEqualTo(PathFragment.create("/some/skylark/file.bzl"));
-
- thrown.expect(IllegalStateException.class);
- importForPath.getLabel(irrelevantContainingFile);
- }
-
private void validRelativeLabelTest(String labelString,
String containingLabelString, String expectedLabelString, String expectedPathString)
throws Exception {
@@ -137,40 +118,6 @@ public class SkylarkImportsTest {
/*expected path*/ "subdir/containing/file.bzl");
}
- private void validRelativePathTest(String pathString, String containingLabelString,
- String expectedLabelString, String expectedPathString) throws Exception {
- SkylarkImport importForPath = SkylarkImports.create(pathString);
-
- assertThat(importForPath.hasAbsolutePath()).named("hasAbsolutePath()").isFalse();
-
- // The import label is relative to the parent's directory not the parent's package.
- Label containingLabel = Label.parseAbsolute(containingLabelString);
- assertThat(importForPath.getLabel(containingLabel)).named("getLabel()")
- .isEqualTo(Label.parseAbsolute(expectedLabelString));
-
- assertThat(importForPath.asPathFragment()).named("asPathFragment()")
- .isEqualTo(PathFragment.create(expectedPathString));
-
- thrown.expect(IllegalStateException.class);
- importForPath.getAbsolutePath();
- }
-
- @Test
- public void testValidRelativePathInPackageDir() throws Exception {
- validRelativePathTest("file",
- /*containing*/ "//some/skylark:BUILD",
- /*expected label*/ "//some/skylark:file.bzl",
- /*expected path*/ "file.bzl");
- }
-
- @Test
- public void testValidRelativePathInPackageSubdir() throws Exception {
- validRelativePathTest("file",
- /*containing*/ "//some/path/to:skylark/parent.bzl",
- /*expected label*/ "//some/path/to:skylark/file.bzl",
- /*expected path*/ "file.bzl");
- }
-
private void invalidImportTest(String importString, String expectedMsgPrefix) throws Exception {
thrown.expect(SkylarkImportSyntaxException.class);
thrown.expectMessage(startsWith(expectedMsgPrefix));
@@ -184,6 +131,11 @@ public class SkylarkImportsTest {
}
@Test
+ public void testInvalidPathSyntax() throws Exception {
+ invalidImportTest("some/path/foo.bzl", SkylarkImports.INVALID_PATH_SYNTAX);
+ }
+
+ @Test
public void testInvalidAbsoluteLabelSyntaxWithRepo() throws Exception {
// final '/' is illegal
invalidImportTest("@my_repo//some/skylark/:file.bzl", SkylarkImports.INVALID_LABEL_PREFIX);
@@ -227,16 +179,14 @@ public class SkylarkImportsTest {
@Test
public void testInvalidRelativePathInvalidFilename() throws Exception {
// tab character is invalid
- invalidImportTest("\tfile", SkylarkImports.INVALID_FILENAME_PREFIX);
+ invalidImportTest("\tfile", SkylarkImports.INVALID_PATH_SYNTAX);
}
@Test
public void serialization() throws Exception {
new SerializationTester(
SkylarkImports.create("//some/skylark:file.bzl"),
- SkylarkImports.create("/some/skylark/file"),
- SkylarkImports.create(":subdirectory/containing/file.bzl"),
- SkylarkImports.create("file"))
+ SkylarkImports.create(":subdirectory/containing/file.bzl"))
.runTests();
}
}