diff options
author | 2016-12-29 21:41:33 +0000 | |
---|---|---|
committer | 2017-01-03 15:02:44 +0000 | |
commit | c31f351a191d6927a6483384826297e5549cf426 (patch) | |
tree | 1b65b2caf884254917d6c0059f88f3e1dfce9d44 /src/test/java | |
parent | ccb78ec8a0ba777ad9f121de95e553791fa9c617 (diff) |
Cleanup in error messages, try to improve consistency.
--
PiperOrigin-RevId: 143204724
MOS_MIGRATED_REVID=143204724
Diffstat (limited to 'src/test/java')
9 files changed, 124 insertions, 135 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java b/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java index 6feb959a10..972b2fecaf 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java @@ -36,11 +36,6 @@ import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.testutil.TestUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -51,6 +46,9 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** * Unit tests for {@code PackageFactory}. @@ -690,9 +688,9 @@ public class PackageFactoryTest extends PackageFactoryTestBase { events.setFailFast(false); assertGlobFails( "glob(1, exclude=2)", - "Method glob(include: sequence of strings, *, exclude: sequence of strings, " + "method glob(include: sequence of strings, *, exclude: sequence of strings, " + "exclude_directories: int) is not applicable for arguments (int, int, int): " - + "'include' is int, but should be sequence"); + + "'include' is 'int', but should be 'sequence'"); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java index dbe7efa497..0872174ea0 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java @@ -1366,7 +1366,7 @@ public class SkylarkAspectsTest extends AnalysisTestCase { } catch (TargetParsingException | ViewCreationFailedException expected) { // expected. } - assertContainsEvent("Aspect //test:aspect.bzl%my_aspect added more than once"); + assertContainsEvent("aspect //test:aspect.bzl%my_aspect added more than once"); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java index cb9436734c..3013450710 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java @@ -294,16 +294,16 @@ public class SkylarkIntegrationTest extends BuildViewTestCase { "str", "\t\tstr.index(1)" + System.lineSeparator() - + "Method string.index(sub: string, start: int, end: int or NoneType) is not " - + "applicable for arguments (int, int, NoneType): 'sub' is int, " - + "but should be string"); + + "method string.index(sub: string, start: int, end: int or NoneType) is not " + + "applicable for arguments (int, int, NoneType): 'sub' is 'int', " + + "but should be 'string'"); } @Test public void testStackTraceMissingMethod() throws Exception { runStackTraceTest( "None", - "\t\tNone.index(1)" + System.lineSeparator() + "Type NoneType has no function index(int)"); + "\t\tNone.index(1)" + System.lineSeparator() + "type 'NoneType' has no method index(int)"); } protected void runStackTraceTest(String object, String errorMessage) throws Exception { diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java index 69783f215f..682d9877a4 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java @@ -245,11 +245,13 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase { @Test public void testAttrWithWrongProvidersList() throws Exception { - checkErrorContains("Illegal argument: element in 'providers' is of unexpected type." + checkErrorContains( + "element in 'providers' is of unexpected type." + " Should be list of string, but got list with an element of type int.", "attr.label_list(allow_files = True, providers = [['a', 1], ['c']])"); - checkErrorContains("Illegal argument: element in 'providers' is of unexpected type." + checkErrorContains( + "element in 'providers' is of unexpected type." + " Should be list of string, but got string.", "attr.label_list(allow_files = True, providers = [['a', 'b'], 'c'])"); } @@ -270,12 +272,11 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase { @Test public void testLabelListWithAspectsError() throws Exception { checkErrorContains( - "Illegal argument: expected type Aspect for 'aspects' element but got type int instead", + "expected type 'Aspect' for 'aspects' element but got type 'int' instead", "def _impl(target, ctx):", " pass", "my_aspect = aspect(implementation = _impl)", - "attr.label_list(aspects = [my_aspect, 123])" - ); + "attr.label_list(aspects = [my_aspect, 123])"); } @Test @@ -392,9 +393,9 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase { @Test public void testAttrDefaultValueBadType() throws Exception { checkErrorContains( - "Method attr.string(*, default: string, mandatory: bool, values: sequence of strings) " - + "is not applicable for arguments (int, bool, list): 'default' is int, " - + "but should be string", + "method attr.string(*, default: string, mandatory: bool, values: sequence of strings) " + + "is not applicable for arguments (int, bool, list): 'default' is 'int', " + + "but should be 'string'", "attr.string(default = 1)"); } @@ -469,9 +470,9 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase { @Test public void testLateBoundAttrWorksWithOnlyLabel() throws Exception { checkEvalError( - "Method attr.string(*, default: string, mandatory: bool, values: sequence of strings) " - + "is not applicable for arguments (function, bool, list): 'default' is function, " - + "but should be string", + "method attr.string(*, default: string, mandatory: bool, values: sequence of strings) " + + "is not applicable for arguments (function, bool, list): 'default' is 'function', " + + "but should be 'string'", "def attr_value(cfg): return 'a'", "attr.string(default=attr_value)"); } @@ -558,8 +559,7 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase { public void testRuleBadTypeInAdd() throws Exception { registerDummyUserDefinedFunction(); checkErrorContains( - "Illegal argument: " - + "expected <String, Descriptor> type for 'attrs' but got <string, string> instead", + "expected <String, Descriptor> type for 'attrs' but got <string, string> instead", "rule(impl, attrs = {'a1': 'some text'})"); } @@ -908,8 +908,8 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase { @Test public void testGetattrNoAttr() throws Exception { - checkErrorContains("Object of type 'struct' has no attribute \"b\"", - "s = struct(a='val')", "getattr(s, 'b')"); + checkErrorContains( + "object of type 'struct' has no attribute \"b\"", "s = struct(a='val')", "getattr(s, 'b')"); } @Test 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 e22b1f16a8..3749437df2 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 @@ -368,7 +368,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { public void testCreateSpawnActionBadGenericArg() throws Exception { checkErrorContains( createRuleContext("//foo:foo"), - "Illegal argument: expected type File for 'outputs' element but got type string instead", + "expected type 'File' for 'outputs' element but got type 'string' instead", "l = ['a', 'b']", "ruleContext.action(", " outputs = l,", @@ -597,8 +597,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { SkylarkRuleContext ruleContext = createRuleContext("//foo:foo"); checkErrorContains( ruleContext, - "Method ctx.file_action(output: File, content: string, executable: bool) is not " - + "applicable for arguments (File, int, bool): 'content' is int, but should be string", + "method ctx.file_action(output: File, content: string, executable: bool) is not applicable " + + "for arguments (File, int, bool): 'content' is 'int', but should be 'string'", "ruleContext.file_action(", " output = ruleContext.files.srcs[0],", " content = 1,", @@ -668,7 +668,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { @Test public void testRunfilesBadListGenericType() throws Exception { checkErrorContains( - "Illegal argument: expected type File for 'files' element but got type string instead", + "expected type 'File' for 'files' element but got type 'string' instead", "ruleContext.runfiles(files = ['some string'])"); } @@ -683,18 +683,16 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { @Test public void testRunfilesBadMapGenericType() throws Exception { checkErrorContains( - "Illegal argument: expected type string for 'symlinks' key " + "but got type int instead", + "expected type 'string' for 'symlinks' key " + "but got type 'int' instead", "ruleContext.runfiles(symlinks = {123: ruleContext.files.srcs[0]})"); checkErrorContains( - "Illegal argument: expected type File for 'symlinks' value " + "but got type int instead", + "expected type 'File' for 'symlinks' value " + "but got type 'int' instead", "ruleContext.runfiles(symlinks = {'some string': 123})"); checkErrorContains( - "Illegal argument: expected type string for 'root_symlinks' key " - + "but got type int instead", + "expected type 'string' for 'root_symlinks' key " + "but got type 'int' instead", "ruleContext.runfiles(root_symlinks = {123: ruleContext.files.srcs[0]})"); checkErrorContains( - "Illegal argument: expected type File for 'root_symlinks' value " - + "but got type int instead", + "expected type 'File' for 'root_symlinks' value " + "but got type 'int' instead", "ruleContext.runfiles(root_symlinks = {'some string': 123})"); } diff --git a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java index 3a571b7e06..464e81cae4 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java @@ -324,14 +324,14 @@ public class FunctionTest extends EvaluationTestCase { @Test public void testKwargsBadKey() throws Exception { - checkEvalError("Keywords must be strings, not int", - "def func(a, b): return a + b", - "func('a', **{3: 1})"); + checkEvalError( + "keywords must be strings, not int", "def func(a, b): return a + b", "func('a', **{3: 1})"); } @Test public void testKwargsIsNotDict() throws Exception { - checkEvalError("Argument after ** must be a dictionary, not int", + checkEvalError( + "argument after ** must be a dictionary, not int", "def func(a, b): return a + b", "func('a', **42)"); } diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java index 5fc8aae5d5..cde97c12cd 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java @@ -44,7 +44,7 @@ public class MethodLibraryTest extends EvaluationTestCase { public void testMinWithInvalidArgs() throws Exception { new SkylarkTest() .testIfExactError("type 'int' is not iterable", "min(1)") - .testIfExactError("Expected at least one argument", "min([])"); + .testIfExactError("expected at least one argument", "min([])"); } @Test @@ -100,7 +100,7 @@ public class MethodLibraryTest extends EvaluationTestCase { public void testMaxWithInvalidArgs() throws Exception { new BothModesTest() .testIfExactError("type 'int' is not iterable", "max(1)") - .testIfExactError("Expected at least one argument", "max([])"); + .testIfExactError("expected at least one argument", "max([])"); } @Test @@ -402,8 +402,8 @@ public class MethodLibraryTest extends EvaluationTestCase { // only one built-in function. new BothModesTest() .testIfExactError( - "Method string.index(sub: string, start: int, end: int or NoneType) is not applicable " - + "for arguments (int, int, NoneType): 'sub' is int, but should be string", + "method string.index(sub: string, start: int, end: int or NoneType) is not applicable " + + "for arguments (int, int, NoneType): 'sub' is 'int', but should be 'string'", "'test'.index(1)"); } @@ -427,9 +427,9 @@ public class MethodLibraryTest extends EvaluationTestCase { + LINE_SEPARATOR + "\t\t'test'.index(x)" + LINE_SEPARATOR - + "Method string.index(sub: string, start: int, end: int or NoneType) " + + "method string.index(sub: string, start: int, end: int or NoneType) " + "is not applicable " - + "for arguments (int, int, NoneType): 'sub' is int, but should be string", + + "for arguments (int, int, NoneType): 'sub' is 'int', but should be 'string'", "def foo():", " bar(1)", "def bar(x):", @@ -442,13 +442,13 @@ public class MethodLibraryTest extends EvaluationTestCase { public void testBuiltinFunctionErrorMessage() throws Exception { new BothModesTest() .testIfErrorContains( - "Method depset.union(new_elements: Iterable) is not applicable for arguments (string): " - + "'new_elements' is string, but should be Iterable", + "method depset.union(new_elements: Iterable) is not applicable for arguments (string): " + + "'new_elements' is 'string', but should be 'Iterable'", "depset([]).union('a')") .testIfErrorContains( - "Method string.startswith(sub: string, start: int, end: int or NoneType) is not " - + "applicable for arguments (int, int, NoneType): 'sub' is int, " - + "but should be string", + "method string.startswith(sub: string, start: int, end: int or NoneType) is not " + + "applicable for arguments (int, int, NoneType): 'sub' is 'int', " + + "but should be 'string'", "'test'.startswith(1)") .testIfErrorContains( "expected value of type 'list(object)' for parameter args in dict(), " @@ -469,7 +469,7 @@ public class MethodLibraryTest extends EvaluationTestCase { public void testGetAttrMissingField() throws Exception { new SkylarkTest() .testIfExactError( - "Object of type 'string' has no attribute \"not_there\"", + "object of type 'string' has no attribute \"not_there\"", "getattr('a string', 'not_there')") .testStatement("getattr('a string', 'not_there', 'use this')", "use this") .testStatement("getattr('a string', 'not there', None)", Runtime.NONE); @@ -478,7 +478,7 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testGetAttrWithMethods() throws Exception { String msg = - "Object of type 'string' has no attribute \"count\", however, " + "object of type 'string' has no attribute \"count\", however, " + "a method of that name exists"; new SkylarkTest() .testIfExactError(msg, "getattr('a string', 'count')") @@ -1032,8 +1032,8 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testListSlice_WrongType() throws Exception { new BothModesTest() - .testIfExactError("Slice start must be an integer, not 'a'", "'123'['a'::]") - .testIfExactError("Slice end must be an integer, not 'b'", "'123'[:'b':]"); + .testIfExactError("slice start must be an integer, not 'a'", "'123'['a'::]") + .testIfExactError("slice end must be an integer, not 'b'", "'123'[:'b':]"); } @Test @@ -1078,7 +1078,7 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testListSliceStep_InvalidStep() throws Exception { - String msg = "Slice step cannot be zero"; + String msg = "slice step cannot be zero"; new BothModesTest() .testIfExactError(msg, "[1, 2, 3][::0]") .testIfExactError(msg, "[1, 2, 3][1::0]") @@ -1102,7 +1102,7 @@ public class MethodLibraryTest extends EvaluationTestCase { .testEval("(1, 2, 3, 4, 5)[3:1:-1]", "(4, 3)") .testEval("(1, 2, 3, 4, 5)[::-2]", "(5, 3, 1)") .testEval("(1, 2, 3, 4, 5)[::-10]", "(5,)") - .testIfExactError("Slice step cannot be zero", "(1, 2, 3)[1::0]"); + .testIfExactError("slice step cannot be zero", "(1, 2, 3)[1::0]"); } @Test @@ -1141,16 +1141,14 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testDictionaryKeyNotFound() throws Exception { new BothModesTest() - .testIfErrorContains("Key \"0\" not found in dictionary", "{}['0']") - .testIfErrorContains("Key 0 not found in dictionary", "{'0': 1, 2: 3, 4: 5}[0]"); + .testIfErrorContains("key \"0\" not found in dictionary", "{}['0']") + .testIfErrorContains("key 0 not found in dictionary", "{'0': 1, 2: 3, 4: 5}[0]"); } @Test public void testListAccessBadIndex() throws Exception { new BothModesTest() - .testIfErrorContains( - "Indices must be integers, not string", - "[[1], [2]]['a']"); + .testIfErrorContains("indices must be integers, not string", "[[1], [2]]['a']"); } @Test @@ -1181,9 +1179,9 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testStringIndexingOutOfRange() throws Exception { new BothModesTest() - .testIfErrorContains("Index out of range", "'abcdef'[10]") - .testIfErrorContains("Index out of range", "'abcdef'[-11]") - .testIfErrorContains("Index out of range", "'abcdef'[42]"); + .testIfErrorContains("index out of range", "'abcdef'[10]") + .testIfErrorContains("index out of range", "'abcdef'[-11]") + .testIfErrorContains("index out of range", "'abcdef'[42]"); } @Test @@ -1200,8 +1198,8 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testStringSlice_WrongType() throws Exception { new BothModesTest() - .testIfExactError("Slice start must be an integer, not 'a'", "'123'['a'::]") - .testIfExactError("Slice end must be an integer, not 'b'", "'123'[:'b':]"); + .testIfExactError("slice start must be an integer, not 'a'", "'123'['a'::]") + .testIfExactError("slice end must be an integer, not 'b'", "'123'[:'b':]"); } @Test @@ -1246,7 +1244,7 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testStringSliceStep_InvalidStep() throws Exception { - String msg = "Slice step cannot be zero"; + String msg = "slice step cannot be zero"; new BothModesTest() .testIfExactError(msg, "'123'[::0]") .testIfExactError(msg, "'123'[1::0]") @@ -1300,13 +1298,11 @@ public class MethodLibraryTest extends EvaluationTestCase { "expected value of type 'list(object)' for parameter args in dict(), " + "but got \"a\" (string)", "dict('a')") - .testIfErrorContains( - "Cannot convert dictionary update sequence element #0 to a sequence", "dict(['a'])") - .testIfErrorContains( - "Cannot convert dictionary update sequence element #0 to a sequence", "dict([('a')])") + .testIfErrorContains("cannot convert item #0 to a sequence", "dict(['a'])") + .testIfErrorContains("cannot convert item #0 to a sequence", "dict([('a')])") .testIfErrorContains("too many (3) positional arguments", "dict((3,4), (3,2), (1,2))") .testIfErrorContains( - "Sequence #0 has length 3, but exactly two elements are required", + "item #0 has length 3, but exactly two elements are required", "dict([('a', 'b', 'c')])"); } @@ -1443,8 +1439,8 @@ public class MethodLibraryTest extends EvaluationTestCase { new BothModesTest() .testIfErrorContains("insufficient arguments received by union", "depset(['a']).union()") .testIfErrorContains( - "Method depset.union(new_elements: Iterable) is not applicable for arguments (string): " - + "'new_elements' is string, but should be Iterable", + "method depset.union(new_elements: Iterable) is not applicable for arguments (string): " + + "'new_elements' is 'string', but should be 'Iterable'", "depset(['a']).union('b')"); } @@ -1472,8 +1468,8 @@ public class MethodLibraryTest extends EvaluationTestCase { .testStatement("[2, 4, 6].index(4)", 1) .testStatement("[2, 4, 6].index(4)", 1) .testStatement("[0, 1, [1]].index([1])", 2) - .testIfErrorContains("Item \"a\" not found in list", "[1, 2].index('a')") - .testIfErrorContains("Item 0 not found in list", "[].index(0)"); + .testIfErrorContains("item \"a\" not found in list", "[1, 2].index('a')") + .testIfErrorContains("item 0 not found in list", "[].index(0)"); } @Test @@ -1493,15 +1489,15 @@ public class MethodLibraryTest extends EvaluationTestCase { public void testListIndexOutOfRange() throws Exception { new BothModesTest() .testIfErrorContains( - "Index out of range (index is 3, but sequence has 3 elements)", "[0, 1, 2][3]") + "index out of range (index is 3, but sequence has 3 elements)", "[0, 1, 2][3]") .testIfErrorContains( - "Index out of range (index is -4, but sequence has 3 elements)", "[0, 1, 2][-4]") + "index out of range (index is -4, but sequence has 3 elements)", "[0, 1, 2][-4]") .testIfErrorContains( - "Index out of range (index is -2, but sequence has 1 elements)", "[0][-2]") + "index out of range (index is -2, but sequence has 1 elements)", "[0][-2]") .testIfErrorContains( - "Index out of range (index is 1, but sequence has 1 elements)", "[0][1]") + "index out of range (index is 1, but sequence has 1 elements)", "[0][1]") .testIfErrorContains( - "Index out of range (index is 1, but sequence has 0 elements)", "[][1]"); + "index out of range (index is 1, but sequence has 0 elements)", "[][1]"); } @Test @@ -1511,8 +1507,8 @@ public class MethodLibraryTest extends EvaluationTestCase { .testStatement("hash('skylark')", "skylark".hashCode()) .testStatement("hash('google')", "google".hashCode()) .testIfErrorContains( - "Method hash(value: string) is not applicable for arguments (NoneType): " - + "'value' is NoneType, but should be string", + "method hash(value: string) is not applicable for arguments (NoneType): " + + "'value' is 'NoneType', but should be 'string'", "hash(None)"); } @@ -1550,8 +1546,8 @@ public class MethodLibraryTest extends EvaluationTestCase { public void testEnumerateBadArg() throws Exception { new BothModesTest() .testIfErrorContains( - "Method enumerate(list: sequence) is not applicable for arguments (string): " - + "'list' is string, but should be sequence", + "method enumerate(list: sequence) is not applicable for arguments (string): " + + "'list' is 'string', but should be 'sequence'", "enumerate('a')"); } @@ -1568,7 +1564,7 @@ public class MethodLibraryTest extends EvaluationTestCase { .testLookup("FOO", MutableList.of(env, "f", "c", "d", "a", "b", "e")) .setUp("FOO.insert(10, 'g')") .testLookup("FOO", MutableList.of(env, "f", "c", "d", "a", "b", "e", "g")) - .testIfErrorContains("Type tuple has no function insert(int)", "(1, 2).insert(3)"); + .testIfErrorContains("type 'tuple' has no method insert(int)", "(1, 2).insert(3)"); } @Test @@ -1576,7 +1572,7 @@ public class MethodLibraryTest extends EvaluationTestCase { new BuildTest() .setUp("FOO = ['a', 'b']", "FOO.append('c')") .testLookup("FOO", MutableList.of(env, "a", "b", "c")) - .testIfErrorContains("Type tuple has no function append(int)", "(1, 2).append(3)"); + .testIfErrorContains("type 'tuple' has no method append(int)", "(1, 2).append(3)"); } @Test @@ -1584,10 +1580,10 @@ public class MethodLibraryTest extends EvaluationTestCase { new BuildTest() .setUp("FOO = ['a', 'b']", "FOO.extend(['c', 'd'])", "FOO.extend(('e', 'f'))") .testLookup("FOO", MutableList.of(env, "a", "b", "c", "d", "e", "f")) - .testIfErrorContains("Type tuple has no function extend(list)", "(1, 2).extend([3, 4])") + .testIfErrorContains("type 'tuple' has no method extend(list)", "(1, 2).extend([3, 4])") .testIfErrorContains( - "Method list.extend(items: sequence) is not applicable for arguments " - + "(int): 'items' is int, but should be sequence", + "method list.extend(items: sequence) is not applicable for arguments " + + "(int): 'items' is 'int', but should be 'sequence'", "[1, 2].extend(3)"); } @@ -1602,10 +1598,10 @@ public class MethodLibraryTest extends EvaluationTestCase { .testLookup("foo", MutableList.of(env, "b")) .setUp("foo.remove('b')") .testLookup("foo", MutableList.of(env)) - .testIfErrorContains("Item 3 not found in list", "[1, 2].remove(3)"); + .testIfErrorContains("item 3 not found in list", "[1, 2].remove(3)"); new BothModesTest() - .testIfErrorContains("Type tuple has no function remove(int)", "(1, 2).remove(3)"); + .testIfErrorContains("type 'tuple' has no method remove(int)", "(1, 2).remove(3)"); } @Test @@ -1624,9 +1620,9 @@ public class MethodLibraryTest extends EvaluationTestCase { .testLookup("ret", 3); new BothModesTest() .testIfErrorContains( - "Index out of range (index is 3, but sequence has 2 elements)", "[1, 2].pop(3)"); + "index out of range (index is 3, but sequence has 2 elements)", "[1, 2].pop(3)"); - new BothModesTest().testIfErrorContains("Type tuple has no function pop()", "(1, 2).pop()"); + new BothModesTest().testIfErrorContains("type 'tuple' has no method pop()", "(1, 2).pop()"); } @Test @@ -1661,8 +1657,8 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testIndexOnFunction() throws Exception { new BothModesTest() - .testIfErrorContains("Type function has no operator [](int)", "len[1]") - .testIfErrorContains("Type function has no operator [:](int, int, int)", "len[1:4]"); + .testIfErrorContains("type 'function' has no operator [](int)", "len[1]") + .testIfErrorContains("type 'function' has no operator [:](int, int, int)", "len[1:4]"); } @Test 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 7a48b204ba..f6493ba70f 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 @@ -691,28 +691,28 @@ public class SkylarkEvaluationTest extends EvaluationTest { public void testJavaCallsNotSkylarkCallable() throws Exception { new SkylarkTest() .update("mock", new Mock()) - .testIfExactError("Type Mock has no function value()", "mock.value()"); + .testIfExactError("type 'Mock' has no method value()", "mock.value()"); } @Test public void testNoOperatorIndex() throws Exception { new SkylarkTest() .update("mock", new Mock()) - .testIfExactError("Type Mock has no operator [](int)", "mock[2]"); + .testIfExactError("type 'Mock' has no operator [](int)", "mock[2]"); } @Test public void testJavaCallsNoMethod() throws Exception { new SkylarkTest() .update("mock", new Mock()) - .testIfExactError("Type Mock has no function bad()", "mock.bad()"); + .testIfExactError("type 'Mock' has no method bad()", "mock.bad()"); } @Test public void testJavaCallsNoMethodErrorMsg() throws Exception { new SkylarkTest() .testIfExactError( - "Type int has no function bad(string, string, string)", "s = 3.bad('a', 'b', 'c')"); + "type 'int' has no method bad(string, string, string)", "s = 3.bad('a', 'b', 'c')"); } @Test @@ -720,7 +720,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { new SkylarkTest() .update("mock", new MockMultipleMethodClass()) .testIfExactError( - "Type MockMultipleMethodClass has multiple matches for function method(string)", + "type 'MockMultipleMethodClass' has multiple matches for function method(string)", "s = mock.method('string')"); } @@ -729,7 +729,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { new SkylarkTest() .update("mock", new Mock()) .testIfExactError( - "Type Mock has no function isEmpty(string str)", "mock.isEmpty(str='abc')"); + "type 'Mock' has no method isEmpty(string str)", "mock.isEmpty(str='abc')"); } @@ -743,14 +743,14 @@ public class SkylarkEvaluationTest extends EvaluationTest { .update("mock", new Mock()) .setUp("") .testIfExactError( - "Parameter 'named' has no default value (in function with_params(int, bool) of Mock).", + "parameter 'named' has no default value, in method with_params(int, bool) of 'Mock'", "mock.with_params(1, True)"); new SkylarkTest() .update("mock", new Mock()) .setUp("") .testIfExactError( - "Parameter 'named' has no default value (in function with_params(int, bool, bool) " - + "of Mock).", + "parameter 'named' has no default value, in method with_params(int, bool, bool) " + + "of 'Mock'", "mock.with_params(1, True, True)"); new SkylarkTest() .update("mock", new Mock()) @@ -768,21 +768,21 @@ public class SkylarkEvaluationTest extends EvaluationTest { .update("mock", new Mock()) .setUp("") .testIfExactError( - "Too many arguments (in function with_params(int, bool, bool named, " - + "bool posOrNamed, int n) of Mock).", + "too many arguments, in method with_params(int, bool, bool named, " + + "bool posOrNamed, int n) of 'Mock'", "mock.with_params(1, True, named=True, posOrNamed=True, n=2)"); new SkylarkTest() .update("mock", new Mock()) .setUp("") .testIfExactError( - "Parameter 'nonNoneable' cannot be None (in function with_params(int, bool, bool, " - + "bool named, bool optionalNamed, NoneType nonNoneable) of Mock).", + "parameter 'nonNoneable' cannot be None, in method with_params(int, bool, bool, " + + "bool named, bool optionalNamed, NoneType nonNoneable) of 'Mock'", "mock.with_params(1, True, True, named=True, optionalNamed=False, nonNoneable=None)"); } @Test public void testNoJavaCallsWithoutSkylark() throws Exception { - new SkylarkTest().testIfExactError("Type int has no function to_string()", "s = 3.to_string()"); + new SkylarkTest().testIfExactError("type 'int' has no method to_string()", "s = 3.to_string()"); } @Test @@ -790,7 +790,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { new SkylarkTest() .update("mock", new MockSubClass()) .testIfExactError( - "Type Mock has no function is_empty_class_not_annotated(string)", + "type 'Mock' has no method is_empty_class_not_annotated(string)", "b = mock.is_empty_class_not_annotated('a')"); } @@ -822,7 +822,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { public void testStructAccessOfMethod() throws Exception { new SkylarkTest() .update("mock", new Mock()) - .testIfExactError("Object of type 'Mock' has no field \"function\"", "v = mock.function"); + .testIfExactError("object of type 'Mock' has no field \"function\"", "v = mock.function"); } @Test @@ -830,17 +830,16 @@ public class SkylarkEvaluationTest extends EvaluationTest { new SkylarkTest() .update("mock", new Mock()) .testIfExactError( - "Method 'return_bad' returns an object of invalid type Bad", - "mock.return_bad()"); + "method 'return_bad' returns an object of invalid type Bad", "mock.return_bad()"); } @Test public void testJavaFunctionReturnsNullFails() throws Exception { new SkylarkTest() .update("mock", new Mock()) - .testIfExactError( - "Method invocation returned None," - + " please contact Skylark developers: nullfunc_failing(\"abc\", 1)", + .testIfErrorContains( + "method invocation returned None," + + " please file a bug report: nullfunc_failing(\"abc\", 1)", "mock.nullfunc_failing('abc', 1)"); } @@ -872,7 +871,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { public void testClassObjectCannotAccessNestedSet() throws Exception { new SkylarkTest() .update("mock", new MockClassObject()) - .testIfExactError("Type is not allowed in Skylark: NestedSet", "v = mock.nset"); + .testIfErrorContains("internal error: type 'NestedSet' is not allowed", "v = mock.nset"); } @Test @@ -908,8 +907,9 @@ public class SkylarkEvaluationTest extends EvaluationTest { @Test public void testStaticDirectJavaCallMethodIsNonStatic() throws Exception { - new SkylarkTest().update("Mock", Mock.class).testIfExactError("Method 'is_empty' is not static", - "val = Mock.is_empty('a')"); + new SkylarkTest() + .update("Mock", Mock.class) + .testIfExactError("method 'is_empty' is not static", "val = Mock.is_empty('a')"); } @Test @@ -925,8 +925,8 @@ public class SkylarkEvaluationTest extends EvaluationTest { @Test public void testDotExpressionOnNonStructObject() throws Exception { - new SkylarkTest().testIfExactError("Object of type 'string' has no field \"field\"", - "x = 'a'.field"); + new SkylarkTest() + .testIfExactError("object of type 'string' has no field \"field\"", "x = 'a'.field"); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java index d6fa9fdab8..8a17607aa8 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java @@ -43,12 +43,11 @@ public class SkylarkListTest extends EvaluationTestCase { @Test public void testIndexOutOfBounds() throws Exception { - checkEvalError("Index out of range (index is 3, but sequence has 3 elements)", - "['a', 'b', 'c'][3]"); - checkEvalError("Index out of range (index is 10, but sequence has 3 elements)", - "['a', 'b', 'c'][10]"); - checkEvalError("Index out of range (index is 0, but sequence has 0 elements)", - "[][0]"); + checkEvalError( + "index out of range (index is 3, but sequence has 3 elements)", "['a', 'b', 'c'][3]"); + checkEvalError( + "index out of range (index is 10, but sequence has 3 elements)", "['a', 'b', 'c'][10]"); + checkEvalError("index out of range (index is 0, but sequence has 0 elements)", "[][0]"); } @Test @@ -58,10 +57,8 @@ public class SkylarkListTest extends EvaluationTestCase { assertThat(eval("l[-1]")).isEqualTo("c"); assertThat(eval("l[-2]")).isEqualTo("b"); assertThat(eval("l[-3]")).isEqualTo("a"); - checkEvalError("Index out of range (index is -4, but sequence has 3 elements)", - "l[-4]"); - checkEvalError("Index out of range (index is -1, but sequence has 0 elements)", - "[][-1]"); + checkEvalError("index out of range (index is -4, but sequence has 3 elements)", "l[-4]"); + checkEvalError("index out of range (index is -1, but sequence has 0 elements)", "[][-1]"); } @SuppressWarnings("unchecked") @@ -141,7 +138,7 @@ public class SkylarkListTest extends EvaluationTestCase { assertThat(listEval("l[-10:5:-1]")).isEmpty(); assertThat(listEval("l[1:-8:-1]")).containsExactly("b", "a").inOrder(); - checkEvalError("Slice step cannot be zero", "l[2:5:0]"); + checkEvalError("slice step cannot be zero", "l[2:5:0]"); } @Test |