Skip to content

Commit

Permalink
[CFE] Increase test coverage 01
Browse files Browse the repository at this point in the history
Increase test coverage --- body_builder.dart was the target.

Process: Replaced all `coverage-ignore-block(suite):` comments with
throws and ran `python3 tools/test.py -n cfe-strong-linux language/`,
copying (and modifying) representative tests from `langauge` that
covered new stuff (i.e. threw in the modified version). Then undid the
throw changes, and redid the coverage marking.
Change-Id: Ie08dc6fcd70cd3722b68c38bf2a152d03aae7885
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378705
Commit-Queue: Jens Johansen <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
  • Loading branch information
jensjoha authored and Commit Queue committed Aug 5, 2024
1 parent 2cf3222 commit 47dc466
Show file tree
Hide file tree
Showing 138 changed files with 3,101 additions and 41 deletions.
29 changes: 1 addition & 28 deletions pkg/front_end/lib/src/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,6 @@ class BodyBuilder extends StackListenerImpl
switchScope.unclaimedForwardDeclarations!
.forEach((String name, JumpTarget declaration) {
if (outerSwitchScope == null) {
// Coverage-ignore-block(suite): Not run.
for (Statement statement in declaration.users) {
statement.parent!.replaceChild(
statement,
Expand All @@ -745,7 +744,6 @@ class BodyBuilder extends StackListenerImpl
buildProblem(message, offset, name.length, context: context)
..parent = variable;
} else {
// Coverage-ignore-block(suite): Not run.
variable.initializer = wrapInLocatedProblem(
variable.initializer!, message.withLocation(uri, offset, name.length),
context: context)
Expand Down Expand Up @@ -1043,7 +1041,6 @@ class BodyBuilder extends StackListenerImpl
if (formal.isInitializingFormal) {
List<Initializer> initializers;
if (_context.isExternalConstructor) {
// Coverage-ignore-block(suite): Not run.
initializers = <Initializer>[
buildInvalidInitializer(
buildProblem(
Expand Down Expand Up @@ -2180,7 +2177,6 @@ class BodyBuilder extends StackListenerImpl
debugEvent("ParenthesizedExpression");
Expression value = popForValue();
if (value is ShadowLargeIntLiteral) {
// Coverage-ignore-block(suite): Not run.
// We need to know that the expression was parenthesized because we will
// treat -n differently from -(n). If the expression occurs in a double
// context, -n is a double literal and -(n) is an application of unary- to
Expand Down Expand Up @@ -2676,7 +2672,6 @@ class BodyBuilder extends StackListenerImpl
token.charOffset,
token.length));
} else {
// Coverage-ignore-block(suite): Not run.
push(buildProblem(fasta.templateInvalidOperator.withArguments(token),
token.charOffset, token.length));
}
Expand Down Expand Up @@ -3630,7 +3625,6 @@ class BodyBuilder extends StackListenerImpl
void pushNewLocalVariable(Expression? initializer, {Token? equalsToken}) {
Object? node = pop();
if (node is ParserRecovery) {
// Coverage-ignore-block(suite): Not run.
push(node);
return;
}
Expand Down Expand Up @@ -3694,7 +3688,6 @@ class BodyBuilder extends StackListenerImpl
debugEvent("NoFieldInitializer");
constantContext = _context.constantContext;
if (constantContext == ConstantContext.inferred) {
// Coverage-ignore-block(suite): Not run.
// Creating a null value to prevent the Dart VM from crashing.
push(forest.createNullLiteral(offsetForToken(token)));
} else {
Expand All @@ -3709,7 +3702,6 @@ class BodyBuilder extends StackListenerImpl
debugEvent("InitializedIdentifier");
Object? node = pop();
if (node is ParserRecovery) {
// Coverage-ignore-block(suite): Not run.
push(node);
return;
}
Expand Down Expand Up @@ -3757,7 +3749,6 @@ class BodyBuilder extends StackListenerImpl
currentLocalVariableModifiers = pop() as int;
List<Expression>? annotations = pop() as List<Expression>?;
if (node is ParserRecovery) {
// Coverage-ignore-block(suite): Not run.
push(node);
return;
}
Expand Down Expand Up @@ -3791,7 +3782,6 @@ class BodyBuilder extends StackListenerImpl
currentLocalVariableModifiers = pop() as int;
List<Expression>? annotations = pop() as List<Expression>?;
if (variables == null) {
// Coverage-ignore-block(suite): Not run.
push(new ParserRecovery(offsetForToken(endToken)));
return;
}
Expand Down Expand Up @@ -3921,7 +3911,6 @@ class BodyBuilder extends StackListenerImpl

void exitLoopOrSwitch(Statement statement) {
if (problemInLoopOrSwitch != null) {
// Coverage-ignore-block(suite): Not run.
push(problemInLoopOrSwitch);
problemInLoopOrSwitch = null;
} else {
Expand Down Expand Up @@ -3964,7 +3953,6 @@ class BodyBuilder extends StackListenerImpl
// Coverage-ignore-block(suite): Not run.
return <VariableDeclaration>[];
} else if (variableOrExpression is ParserRecovery) {
// Coverage-ignore-block(suite): Not run.
return <VariableDeclaration>[];
} else if (variableOrExpression == null) {
return <VariableDeclaration>[];
Expand Down Expand Up @@ -4280,7 +4268,6 @@ class BodyBuilder extends StackListenerImpl
<Statement>[variableOrExpression, ...intermediateVariables!, result]);
}
if (variableOrExpression is ParserRecovery) {
// Coverage-ignore-block(suite): Not run.
problemInLoopOrSwitch ??= buildProblemStatement(
fasta.messageSyntheticToken, variableOrExpression.charOffset,
suppressMessage: true);
Expand Down Expand Up @@ -4350,7 +4337,6 @@ class BodyBuilder extends StackListenerImpl
DartType typeArgument;
if (typeArguments != null) {
if (typeArguments.length > 1) {
// Coverage-ignore-block(suite): Not run.
addProblem(
fasta.messageListLiteralTooManyTypeArguments,
offsetForToken(leftBracket),
Expand Down Expand Up @@ -4556,7 +4542,6 @@ class BodyBuilder extends StackListenerImpl
if (setOrMapEntries != null) {
for (dynamic entry in setOrMapEntries) {
if (entry is MapLiteralEntry) {
// Coverage-ignore-block(suite): Not run.
// TODO(danrubel): report the error on the colon
addProblem(fasta.templateExpectedButGot.withArguments(','),
entry.fileOffset, 1);
Expand Down Expand Up @@ -4849,7 +4834,6 @@ class BodyBuilder extends StackListenerImpl
if (identifierCount == 1) {
Object? part = pop();
if (part is ParserRecovery) {
// Coverage-ignore-block(suite): Not run.
push(new ParserErrorGenerator(
this, hashToken, fasta.messageSyntheticToken));
} else {
Expand Down Expand Up @@ -5255,7 +5239,6 @@ class BodyBuilder extends StackListenerImpl
debugEvent("ThrowExpression");
Expression expression = popForValue();
if (constantContext != ConstantContext.none) {
// Coverage-ignore-block(suite): Not run.
push(buildProblem(
fasta.templateNotConstantExpression.withArguments('Throw'),
throwToken.offset,
Expand Down Expand Up @@ -6222,7 +6205,6 @@ class BodyBuilder extends StackListenerImpl
List<TypeBuilder>? typeArguments = pop() as List<TypeBuilder>?;
if (inMetadata && typeArguments != null) {
if (!libraryFeatures.genericMetadata.isEnabled) {
// Coverage-ignore-block(suite): Not run.
handleRecoverableError(fasta.messageMetadataTypeArguments,
nameLastToken.next!, nameLastToken.next!);
}
Expand Down Expand Up @@ -6396,7 +6378,6 @@ class BodyBuilder extends StackListenerImpl
target = null;
} else if (constructorBuilder.isConstructor) {
if (typeDeclarationBuilder.isAbstract) {
// Coverage-ignore-block(suite): Not run.
return evaluateArgumentsBefore(
arguments,
buildAbstractClassInstantiationError(
Expand Down Expand Up @@ -7631,7 +7612,6 @@ class BodyBuilder extends StackListenerImpl
JumpTarget breakTarget = exitBreakTarget()!;
List<BreakStatementImpl>? continueStatements;
if (continueTarget.hasUsers) {
// Coverage-ignore-block(suite): Not run.
LabeledStatement labeledStatement = forest.createLabeledStatement(body);
continueStatements =
continueTarget.resolveContinues(forest, labeledStatement);
Expand Down Expand Up @@ -7662,7 +7642,6 @@ class BodyBuilder extends StackListenerImpl
typeInferrer.assignedVariables
.storeInfo(forInStatement, assignedVariablesNodeInfo);
if (continueStatements != null) {
// Coverage-ignore-block(suite): Not run.
for (BreakStatementImpl continueStatement in continueStatements) {
continueStatement.targetStatement = forInStatement;
}
Expand Down Expand Up @@ -7755,7 +7734,6 @@ class BodyBuilder extends StackListenerImpl
push(forest.createRethrowStatement(
offsetForToken(rethrowToken), offsetForToken(endToken)));
} else {
// Coverage-ignore-block(suite): Not run.
push(new ExpressionStatement(buildProblem(fasta.messageRethrowNotCatch,
offsetForToken(rethrowToken), lengthForToken(rethrowToken)))
..fileOffset = offsetForToken(rethrowToken));
Expand Down Expand Up @@ -8589,14 +8567,12 @@ class BodyBuilder extends StackListenerImpl
push(problemInLoopOrSwitch = buildProblemStatement(
fasta.messageBreakOutsideOfLoop, breakKeyword.charOffset));
} else if (target == null || !target.isBreakTarget) {
// Coverage-ignore-block(suite): Not run.
Token labelToken = breakKeyword.next!;
push(problemInLoopOrSwitch = buildProblemStatement(
fasta.templateInvalidBreakTarget.withArguments(name!),
labelToken.charOffset,
length: labelToken.length));
} else if (target.functionNestingLevel != functionNestingLevel) {
// Coverage-ignore-block(suite): Not run.
push(buildProblemTargetOutsideLocalFunction(name, breakKeyword));
} else {
Statement statement =
Expand All @@ -8606,7 +8582,6 @@ class BodyBuilder extends StackListenerImpl
}
}

// Coverage-ignore(suite): Not run.
Statement buildProblemTargetOutsideLocalFunction(
String? name, Token keyword) {
Statement problem;
Expand All @@ -8619,6 +8594,7 @@ class BodyBuilder extends StackListenerImpl
template.withArguments(name), offsetForToken(keyword),
length: lengthOfSpan(keyword, keyword.next));
} else {
// Coverage-ignore-block(suite): Not run.
Message message = isBreak
? fasta.messageAnonymousBreakTargetOutsideFunction
: fasta.messageAnonymousContinueTargetOutsideFunction;
Expand Down Expand Up @@ -8661,7 +8637,6 @@ class BodyBuilder extends StackListenerImpl
}
}
if (target == null) {
// Coverage-ignore-block(suite): Not run.
push(problemInLoopOrSwitch = buildProblemStatement(
fasta.messageContinueWithoutLabelInCase, continueKeyword.charOffset,
length: continueKeyword.length));
Expand Down Expand Up @@ -8895,7 +8870,6 @@ class BodyBuilder extends StackListenerImpl
context: context, suppressMessage: suppressMessage));
}

// Coverage-ignore(suite): Not run.
Statement wrapInProblemStatement(Statement statement, Message message) {
// TODO(askesc): Produce explicit error statement wrapping the original.
// See [issue 29717](https://github.com/dart-lang/sdk/issues/29717)
Expand Down Expand Up @@ -9020,7 +8994,6 @@ class BodyBuilder extends StackListenerImpl
DartType fieldType = _context.substituteFieldType(builder.fieldType);
if (!typeEnvironment.isSubtypeOf(
formalType, fieldType, SubtypeCheckMode.withNullabilities)) {
// Coverage-ignore-block(suite): Not run.
libraryBuilder.addProblem(
fasta.templateInitializingFormalTypeMismatch
.withArguments(name, formalType, builder.fieldType),
Expand Down
1 change: 0 additions & 1 deletion pkg/front_end/lib/src/source/source_field_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl
hasBodyBeenBuilt = true;
if (!hasInitializer &&
initializer != null &&
// Coverage-ignore(suite): Not run.
initializer is! NullLiteral &&
// Coverage-ignore(suite): Not run.
!isConst &&
Expand Down
3 changes: 0 additions & 3 deletions pkg/front_end/lib/src/type_inference/inference_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase

int? intValue = node.asInt64();
if (intValue == null) {
// Coverage-ignore-block(suite): Not run.
Expression replacement = helper.buildProblem(
templateIntegerLiteralIsOutOfRange.withArguments(node.literal),
node.fileOffset,
Expand Down Expand Up @@ -2815,7 +2814,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase
inferredConditionTypes);
}
if (otherwise is ControlFlowElement) {
// Coverage-ignore-block(suite): Not run.
checkElement(otherwise, item, typeArgument, inferredSpreadTypes,
inferredConditionTypes);
}
Expand Down Expand Up @@ -9841,7 +9839,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase
}
int? intValue = receiver.asInt64(negated: true);
if (intValue == null) {
// Coverage-ignore-block(suite): Not run.
Expression error = helper.buildProblem(
templateIntegerLiteralIsOutOfRange
.withArguments(receiver.literal),
Expand Down
8 changes: 4 additions & 4 deletions pkg/front_end/test/coverage_suite_expected.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
),
// 100.0%.
"package:front_end/src/kernel/body_builder.dart": (
hitCount: 6831,
hitCount: 6954,
missCount: 0,
),
// 100.0%.
Expand All @@ -490,7 +490,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
),
// 100.0%.
"package:front_end/src/kernel/collections.dart": (
hitCount: 326,
hitCount: 329,
missCount: 0,
),
// 100.0%.
Expand Down Expand Up @@ -836,7 +836,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
),
// 100.0%.
"package:front_end/src/source/source_field_builder.dart": (
hitCount: 1180,
hitCount: 1181,
missCount: 0,
),
// 100.0%.
Expand Down Expand Up @@ -911,7 +911,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
),
// 100.0%.
"package:front_end/src/type_inference/inference_visitor.dart": (
hitCount: 8044,
hitCount: 8081,
missCount: 0,
),
// 100.0%.
Expand Down
8 changes: 8 additions & 0 deletions pkg/front_end/testcases/coverage/bad_literal_symbol.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

void foo() {
print(#Bla); // OK
print(#!); // Error
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/coverage/bad_literal_symbol.dart:7:10: Error: Expected an identifier, but got '!'.
// Try inserting an identifier before '!'.
// print(#!); // Error
// ^
//
import self as self;
import "dart:core" as core;

static method foo() → void {
core::print(#C1);
core::print(invalid-expression "pkg/front_end/testcases/coverage/bad_literal_symbol.dart:7:9: Error: This couldn't be parsed.
print(#!); // Error
^"!);
}

constants {
#C1 = #Bla
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/coverage/bad_literal_symbol.dart:7:10: Error: Expected an identifier, but got '!'.
// Try inserting an identifier before '!'.
// print(#!); // Error
// ^
//
import self as self;
import "dart:core" as core;

static method foo() → void {
core::print(#C1);
core::print(invalid-expression "pkg/front_end/testcases/coverage/bad_literal_symbol.dart:7:9: Error: This couldn't be parsed.
print(#!); // Error
^"!);
}

constants {
#C1 = #Bla
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library;
import self as self;

static method foo() → void
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/coverage/bad_literal_symbol.dart:7:10: Error: Expected an identifier, but got '!'.
// Try inserting an identifier before '!'.
// print(#!); // Error
// ^
//
import self as self;
import "dart:core" as core;

static method foo() → void {
core::print(#C1);
core::print(invalid-expression "pkg/front_end/testcases/coverage/bad_literal_symbol.dart:7:9: Error: This couldn't be parsed.
print(#!); // Error
^"!);
}

constants {
#C1 = #Bla
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void foo() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void foo() {}
7 changes: 7 additions & 0 deletions pkg/front_end/testcases/coverage/const_equals_throw.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Based on tests/language/compile_time_constant/r_test.dart

const x = throw "x"; // Error
Loading

0 comments on commit 47dc466

Please sign in to comment.