diff options
author | 2016-12-29 21:41:33 +0000 | |
---|---|---|
committer | 2017-01-03 15:02:44 +0000 | |
commit | c31f351a191d6927a6483384826297e5549cf426 (patch) | |
tree | 1b65b2caf884254917d6c0059f88f3e1dfce9d44 | |
parent | ccb78ec8a0ba777ad9f121de95e553791fa9c617 (diff) |
Cleanup in error messages, try to improve consistency.
--
PiperOrigin-RevId: 143204724
MOS_MIGRATED_REVID=143204724
20 files changed, 216 insertions, 212 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java index 48375c92e6..bc2a96db11 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java @@ -1004,8 +1004,8 @@ public final class Attribute implements Comparable<Attribute> { SkylarkRuleAspect skylarkRuleAspect = new SkylarkRuleAspect(skylarkAspect); RuleAspect<?> oldAspect = this.aspects.put(skylarkAspect.getName(), skylarkRuleAspect); if (oldAspect != null) { - throw new EvalException(location, - String.format("Aspect %s added more than once", skylarkAspect.getName())); + throw new EvalException( + location, String.format("aspect %s added more than once", skylarkAspect.getName())); } return this; } @@ -1455,7 +1455,7 @@ public final class Attribute implements Comparable<Attribute> { throw new EvalException( location, String.format( - "Expected '%s', but got '%s'", type, EvalUtils.getDataTypeName(result, true))); + "expected '%s', but got '%s'", type, EvalUtils.getDataTypeName(result, true))); } } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java index b050b2ec48..7614df5dc0 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java @@ -159,7 +159,7 @@ public class BuiltinFunction extends BaseFunction { if (e instanceof EvalException) { throw ((EvalException) e).ensureLocation(loc); } else if (e instanceof IllegalArgumentException) { - throw new EvalException(loc, "Illegal argument in call to " + getName(), e); + throw new EvalException(loc, "illegal argument in call to " + getName(), e); } // TODO(bazel-team): replace with Throwables.throwIfInstanceOf once Guava 20 is released. Throwables.propagateIfInstanceOf(e, InterruptedException.class); @@ -179,9 +179,12 @@ public class BuiltinFunction extends BaseFunction { throw new EvalException( loc, String.format( - "Method %s is not applicable for arguments %s: '%s' is %s, but should be %s", - getShortSignature(true), printTypeString(args, args.length - extraArgsCount), - paramName, EvalUtils.getDataTypeName(args[i]), + "method %s is not applicable for arguments %s: " + + "'%s' is '%s', but should be '%s'", + getShortSignature(true), + printTypeString(args, args.length - extraArgsCount), + paramName, + EvalUtils.getDataTypeName(args[i]), EvalUtils.getDataTypeNameFromClass(types[i]))); } } @@ -351,7 +354,7 @@ public class BuiltinFunction extends BaseFunction { @Override public Object call(Object[] args, @Nullable FuncallExpression ast, @Nullable Environment env) throws EvalException { - throw new EvalException(null, "Tried to invoke a Factory for function " + this); + throw new EvalException(null, "tried to invoke a Factory for function " + this); } /** Instantiate the Factory diff --git a/src/main/java/com/google/devtools/build/lib/syntax/DotExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/DotExpression.java index a0ce8fe7bf..5d94498ea7 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/DotExpression.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/DotExpression.java @@ -74,7 +74,7 @@ public final class DotExpression extends Expression { throw new EvalException( loc, Printer.format( - "Object of type '%s' has no field %r", EvalUtils.getDataTypeName(objValue), name)); + "object of type '%s' has no field %r", EvalUtils.getDataTypeName(objValue), name)); } return result; } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java index 370692336b..bb859c90c6 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java @@ -270,9 +270,12 @@ public final class EvalUtils { public static Object checkNotNull(Expression expr, Object obj) throws EvalException { if (obj == null) { - throw new EvalException(expr.getLocation(), - "Unexpected null value, please send a bug report. " - + "This was generated by '" + expr + "'"); + throw new EvalException( + expr.getLocation(), + "unexpected null value, please send a bug report. " + + "This was generated by expression '" + + expr + + "'"); } return obj; } @@ -410,8 +413,9 @@ public final class EvalUtils { actualIndex += length; } if (actualIndex < 0 || actualIndex >= length) { - throw new EvalException(loc, "Index out of range (index is " - + index + ", but sequence has " + length + " elements)"); + throw new EvalException( + loc, + "index out of range (index is " + index + ", but sequence has " + length + " elements)"); } return actualIndex; } @@ -422,8 +426,8 @@ public final class EvalUtils { public static int getSequenceIndex(Object index, int length, Location loc) throws EvalException { if (!(index instanceof Integer)) { - throw new EvalException(loc, "Indices must be integers, not " - + EvalUtils.getDataTypeName(index)); + throw new EvalException( + loc, "indices must be integers, not " + EvalUtils.getDataTypeName(index)); } return getSequenceIndex(((Integer) index).intValue(), length, loc); } @@ -491,11 +495,11 @@ public final class EvalUtils { } else if (stepObj instanceof Integer) { step = ((Integer) stepObj).intValue(); } else { - throw new EvalException(loc, - String.format("Slice step must be an integer, not '%s'", stepObj)); + throw new EvalException( + loc, String.format("slice step must be an integer, not '%s'", stepObj)); } if (step == 0) { - throw new EvalException(loc, "Slice step cannot be zero"); + throw new EvalException(loc, "slice step cannot be zero"); } if (startObj == Runtime.NONE) { @@ -503,8 +507,8 @@ public final class EvalUtils { } else if (startObj instanceof Integer) { start = ((Integer) startObj).intValue(); } else { - throw new EvalException(loc, - String.format("Slice start must be an integer, not '%s'", startObj)); + throw new EvalException( + loc, String.format("slice start must be an integer, not '%s'", startObj)); } if (endObj == Runtime.NONE) { // If step is negative, can't use -1 for end since that would be converted @@ -513,8 +517,7 @@ public final class EvalUtils { } else if (endObj instanceof Integer) { end = ((Integer) endObj).intValue(); } else { - throw new EvalException(loc, - String.format("Slice end must be an integer, not '%s'", endObj)); + throw new EvalException(loc, String.format("slice end must be an integer, not '%s'", endObj)); } return getSliceIndices(start, end, step, length); diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java index 7ca5793cc9..b7c2d59ccd 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java @@ -265,10 +265,6 @@ public final class FuncallExpression extends Expression { return numPositionalArgs; } - private String functionName() { - return "function " + func.getName(); - } - @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -291,7 +287,7 @@ public final class FuncallExpression extends Expression { try { return methodCache.get(objClass).get(methodName); } catch (ExecutionException e) { - throw new EvalException(loc, "Method invocation failed: " + e); + throw new EvalException(loc, "method invocation failed: " + e); } } @@ -308,7 +304,7 @@ public final class FuncallExpression extends Expression { try { Method method = methodDescriptor.getMethod(); if (obj == null && !Modifier.isStatic(method.getModifiers())) { - throw new EvalException(loc, "Method '" + methodName + "' is not static"); + throw new EvalException(loc, "method '" + methodName + "' is not static"); } // This happens when the interface is public but the implementation classes // have reduced visibility. @@ -321,16 +317,20 @@ public final class FuncallExpression extends Expression { if (methodDescriptor.getAnnotation().allowReturnNones()) { return Runtime.NONE; } else { - throw new EvalException(loc, - "Method invocation returned None, please contact Skylark developers: " + methodName - + Printer.listString(ImmutableList.copyOf(args), "(", ", ", ")", null)); + throw new EvalException( + loc, + "method invocation returned None, please file a bug report: " + + methodName + + Printer.listString(ImmutableList.copyOf(args), "(", ", ", ")", null)); } } // TODO(bazel-team): get rid of this, by having everyone use the Skylark data structures result = SkylarkType.convertToSkylark(result, method, env); if (result != null && !EvalUtils.isSkylarkAcceptable(result.getClass())) { - throw new EvalException(loc, Printer.format( - "Method '%s' returns an object of invalid type %r", methodName, result.getClass())); + throw new EvalException( + loc, + Printer.format( + "method '%s' returns an object of invalid type %r", methodName, result.getClass())); } return result; } catch (IllegalAccessException e) { @@ -344,7 +344,7 @@ public final class FuncallExpression extends Expression { throw new EvalExceptionWithJavaCause(loc, e.getCause()); } else { // This is unlikely to happen - throw new EvalException(loc, "Method invocation failed: " + e); + throw new EvalException(loc, "method invocation failed: " + e); } } } @@ -374,7 +374,7 @@ public final class FuncallExpression extends Expression { throw new EvalException( getLocation(), String.format( - "Type %s has multiple matches for %s", + "type '%s' has multiple matches for function %s", EvalUtils.getDataTypeNameFromClass(objClass), formatMethod(args, kwargs))); } } @@ -386,13 +386,13 @@ public final class FuncallExpression extends Expression { if (argumentListConversionResult == null || argumentListConversionResult.getError() == null) { errorMessage = String.format( - "Type %s has no %s", + "type '%s' has no method %s", EvalUtils.getDataTypeNameFromClass(objClass), formatMethod(args, kwargs)); } else { errorMessage = String.format( - "%s (in %s of %s).", + "%s, in method %s of '%s'", argumentListConversionResult.getError(), formatMethod(args, kwargs), EvalUtils.getDataTypeNameFromClass(objClass)); @@ -429,7 +429,7 @@ public final class FuncallExpression extends Expression { } if (mandatoryPositionals > args.size() || args.size() > mandatoryPositionals + callable.parameters().length) { - return ArgumentListConversionResult.fromError("Too many arguments"); + return ArgumentListConversionResult.fromError("too many arguments"); } // First process the legacy positional parameters. int i = 0; @@ -482,25 +482,25 @@ public final class FuncallExpression extends Expression { // Use default value if (param.defaultValue().isEmpty()) { return ArgumentListConversionResult.fromError( - String.format("Parameter '%s' has no default value", param.name())); + String.format("parameter '%s' has no default value", param.name())); } value = SkylarkSignatureProcessor.getDefaultValue(param, null); } builder.add(value); if (!param.noneable() && value instanceof NoneType) { return ArgumentListConversionResult.fromError( - String.format("Parameter '%s' cannot be None", param.name())); + String.format("parameter '%s' cannot be None", param.name())); } } if (i < args.size() || !keys.isEmpty()) { - return ArgumentListConversionResult.fromError("Too many arguments"); + return ArgumentListConversionResult.fromError("too many arguments"); } return ArgumentListConversionResult.fromArgumentList(builder.build()); } private String formatMethod(List<Object> args, Map<String, Object> kwargs) { StringBuilder sb = new StringBuilder(); - sb.append(functionName()).append("("); + sb.append(func.getName()).append("("); boolean first = true; for (Object obj : args) { if (!first) { @@ -577,12 +577,12 @@ public final class FuncallExpression extends Expression { if (!(items instanceof Map<?, ?>)) { throw new EvalException( location, - "Argument after ** must be a dictionary, not " + EvalUtils.getDataTypeName(items)); + "argument after ** must be a dictionary, not " + EvalUtils.getDataTypeName(items)); } for (Map.Entry<?, ?> entry : ((Map<?, ?>) items).entrySet()) { if (!(entry.getKey() instanceof String)) { throw new EvalException( - location, "Keywords must be strings, not " + EvalUtils.getDataTypeName(entry.getKey())); + location, "keywords must be strings, not " + EvalUtils.getDataTypeName(entry.getKey())); } addKeywordArg(kwargs, (String) entry.getKey(), entry.getValue(), duplicates); } @@ -717,7 +717,7 @@ public final class FuncallExpression extends Expression { try { return callFunction(javaMethod.first.getMethod().invoke(obj), env); } catch (IllegalAccessException e) { - throw new EvalException(getLocation(), "Method invocation failed: " + e); + throw new EvalException(getLocation(), "method invocation failed: " + e); } catch (InvocationTargetException e) { if (e.getCause() instanceof FuncallException) { throw new EvalException(getLocation(), e.getCause().getMessage()); @@ -725,7 +725,7 @@ public final class FuncallExpression extends Expression { throw new EvalExceptionWithJavaCause(getLocation(), e.getCause()); } else { // This is unlikely to happen - throw new EvalException(getLocation(), "Method invocation failed: " + e); + throw new EvalException(getLocation(), "method invocation failed: " + e); } } } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/IndexExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/IndexExpression.java index 575a7d2de1..fd2a59b07d 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/IndexExpression.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/IndexExpression.java @@ -58,9 +58,8 @@ public final class IndexExpression extends Expression { throw new EvalException( loc, Printer.format( - "Type %s has no operator [](%s)", - EvalUtils.getDataTypeName(objValue), - EvalUtils.getDataTypeName(keyValue))); + "type '%s' has no operator [](%s)", + EvalUtils.getDataTypeName(objValue), EvalUtils.getDataTypeName(keyValue))); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java index b4e2a21301..415d4273ca 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java @@ -1001,7 +1001,7 @@ public class MethodLibrary { try { return maxOrdering.max(getIterable(args, loc)); } catch (NoSuchElementException ex) { - throw new EvalException(loc, "Expected at least one argument"); + throw new EvalException(loc, "expected at least one argument"); } } @@ -1207,7 +1207,7 @@ public class MethodLibrary { } i++; } - throw new EvalException(loc, Printer.format("Item %r not found in list", x)); + throw new EvalException(loc, Printer.format("item %r not found in list", x)); } }; @@ -1235,7 +1235,7 @@ public class MethodLibrary { return Runtime.NONE; } } - throw new EvalException(loc, Printer.format("Item %r not found in list", x)); + throw new EvalException(loc, Printer.format("item %r not found in list", x)); } }; @@ -1749,15 +1749,13 @@ public class MethodLibrary { throw new EvalException( location, String.format( - "Sequence #%d has length %d, but exactly two elements are required", + "item #%d has length %d, but exactly two elements are required", pos, numElements)); } return tuple; } catch (ConversionException e) { throw new EvalException( - loc, - String.format( - "Cannot convert dictionary update sequence element #%d to a sequence", pos)); + loc, String.format("cannot convert item #%d to a sequence", pos)); } } }; @@ -1945,7 +1943,7 @@ public class MethodLibrary { throw new EvalException( loc, Printer.format( - "Object of type '%s' has no attribute %r%s", + "object of type '%s' has no attribute %r%s", EvalUtils.getDataTypeName(obj), name, isRealMethod ? ", however, a method of that name exists" : "")); diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ReturnStatement.java b/src/main/java/com/google/devtools/build/lib/syntax/ReturnStatement.java index d3dac8198c..72c301ff8b 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/ReturnStatement.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/ReturnStatement.java @@ -33,8 +33,11 @@ public class ReturnStatement extends Statement { Object value; public ReturnException(Location location, Object value) { - super(location, "Return statements must be inside a function", - /*dueToIncompleteAST=*/ false, /*fillInJavaStackTrace=*/ false); + super( + location, + "return statements must be inside a function", + /*dueToIncompleteAST=*/ false, /*fillInJavaStackTrace=*/ + false); this.value = value; } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java index af75d436d1..ad0a97dfe7 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java @@ -189,8 +189,10 @@ public final class SkylarkDict<K, V> if (obj instanceof SkylarkDict) { return ((SkylarkDict<?, ?>) obj).getContents(keyType, valueType, description); } - throw new EvalException(null, - Printer.format("Illegal argument: %s is not of expected type dict or NoneType", + throw new EvalException( + null, + Printer.format( + "%s is not of expected type dict or NoneType", description == null ? Printer.repr(obj) : String.format("'%s'", description))); } @@ -218,7 +220,7 @@ public final class SkylarkDict<K, V> @Override public final Object getIndex(Object key, Location loc) throws EvalException { if (!this.containsKey(key)) { - throw new EvalException(loc, Printer.format("Key %r not found in dictionary", key)); + throw new EvalException(loc, Printer.format("key %r not found in dictionary", key)); } return this.get(key); } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java index 87fa01203b..09f2467e70 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java @@ -601,9 +601,8 @@ public abstract class SkylarkType implements Serializable { */ static void checkTypeAllowedInSkylark(Object object, Location loc) throws EvalException { if (!isTypeAllowedInSkylark(object)) { - throw new EvalException(loc, - "Type is not allowed in Skylark: " - + object.getClass().getSimpleName()); + throw new EvalException( + loc, "internal error: type '" + object.getClass().getSimpleName() + "' is not allowed"); } } @@ -660,19 +659,25 @@ public abstract class SkylarkType implements Serializable { return ImmutableMap.of(); } if (!(obj instanceof Map<?, ?>)) { - throw new EvalException(null, String.format( - "Illegal argument: expected a dictionary for %s but got %s instead", - what, EvalUtils.getDataTypeName(obj))); + throw new EvalException( + null, + String.format( + "expected a dictionary for '%s' but got '%s' instead", + what, EvalUtils.getDataTypeName(obj))); } for (Map.Entry<?, ?> input : ((Map<?, ?>) obj).entrySet()) { if (!keyType.isAssignableFrom(input.getKey().getClass()) || !valueType.isAssignableFrom(input.getValue().getClass())) { - throw new EvalException(null, String.format( - "Illegal argument: expected <%s, %s> type for '%s' but got <%s, %s> instead", - keyType.getSimpleName(), valueType.getSimpleName(), what, - EvalUtils.getDataTypeName(input.getKey()), - EvalUtils.getDataTypeName(input.getValue()))); + throw new EvalException( + null, + String.format( + "expected <%s, %s> type for '%s' but got <%s, %s> instead", + keyType.getSimpleName(), + valueType.getSimpleName(), + what, + EvalUtils.getDataTypeName(input.getKey()), + EvalUtils.getDataTypeName(input.getValue()))); } } @@ -735,8 +740,10 @@ public abstract class SkylarkType implements Serializable { public static void checkType(Object object, Class<?> type, @Nullable Object description) throws EvalException { if (!type.isInstance(object)) { - throw new EvalException(null, - Printer.format("Illegal argument: expected type %r %sbut got type %s instead", + throw new EvalException( + null, + Printer.format( + "expected type '%r' %sbut got type '%s' instead", type, description == null ? "" : String.format("for %s ", description), EvalUtils.getDataTypeName(object))); diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SliceExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/SliceExpression.java index f7c36e5a7a..14988f0f7a 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SliceExpression.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SliceExpression.java @@ -89,7 +89,7 @@ public final class SliceExpression extends Expression { throw new EvalException( loc, Printer.format( - "Type %s has no operator [:](%s, %s, %s)", + "type '%s' has no operator [:](%s, %s, %s)", EvalUtils.getDataTypeName(objValue), EvalUtils.getDataTypeName(startValue), EvalUtils.getDataTypeName(endValue), 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 |