Skip to content

Commit c021746

Browse files
bwilkersonCommit Queue
authored andcommitted
Automate checking for solo tests
Change-Id: Iba0134f4b31b64d3bf3eb622c57d0e40121494f4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286944 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 63e6041 commit c021746

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pkg/analyzer_utilities/lib/verify_tests.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class VerifyTests {
6666
void _buildTestsIn(
6767
AnalysisSession session, String testDirPath, Folder directory) {
6868
var testFileNames = <String>[];
69+
var testFilePaths = <String>[];
6970
File? testAllFile;
7071
var children = directory.getChildren();
7172
children
@@ -83,6 +84,7 @@ class VerifyTests {
8384
testAllFile = child;
8485
} else if (name.endsWith('_test.dart') && !isExpensive(child)) {
8586
testFileNames.add(name);
87+
testFilePaths.add(child.path);
8688
}
8789
}
8890
}
@@ -126,6 +128,7 @@ class VerifyTests {
126128
if (missingFiles.isNotEmpty) {
127129
fail('Tests missing from "test_all.dart": ${missingFiles.join(', ')}');
128130
}
131+
129132
var extraImports = <String>[];
130133
for (var importedFile in importedFiles) {
131134
if (!testFileNames.contains(importedFile) &&
@@ -136,6 +139,30 @@ class VerifyTests {
136139
if (extraImports.isNotEmpty) {
137140
fail('Extra tests in "test_all.dart": ${extraImports.join(', ')}');
138141
}
142+
143+
for (var testFilePath in testFilePaths) {
144+
var result = session.getParsedUnit(testFilePath);
145+
if (result is! ParsedUnitResult) {
146+
fail('Could not parse $testFilePath');
147+
}
148+
for (var declaration in result.unit.declarations) {
149+
if (declaration is ClassDeclaration) {
150+
for (var member in declaration.members) {
151+
if (member is MethodDeclaration) {
152+
var name = member.name.lexeme;
153+
if (name.startsWith('solo_test_')) {
154+
fail("Solo test: $name in '$testFilePath'");
155+
}
156+
for (var annotation in member.metadata) {
157+
if (annotation.name.name == 'soloTest') {
158+
fail("Solo test: $name in '$testFilePath'");
159+
}
160+
}
161+
}
162+
}
163+
}
164+
}
165+
}
139166
});
140167
}
141168
}

0 commit comments

Comments
 (0)