Expand what BlazeWorkspacePackage.isInTestDirectory() allows.
Change-Id: I091c83e136c82c326d74660ebd2ffc186d3f8484 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505480 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
eda0e21e25
commit
0220df06a8
@@ -636,9 +636,74 @@ class BlazeWorkspacePackage extends WorkspacePackageImpl {
|
||||
bool isInTestDirectory(File file) {
|
||||
// If the package itself is a "testing" package, then [file] counts as being
|
||||
// "in a test directory."
|
||||
return root.shortName == 'testing' ||
|
||||
root.path.contains('/testing/') ||
|
||||
super.isInTestDirectory(file);
|
||||
var pathContext = workspace.provider.pathContext;
|
||||
var relativeRoot = pathContext.relative(root.path, from: workspace.root);
|
||||
var relativeRootSegments = pathContext.split(relativeRoot);
|
||||
if (root.shortName == 'testing' ||
|
||||
relativeRootSegments.contains('testing') ||
|
||||
relativeRootSegments.contains('integration_test') ||
|
||||
relativeRootSegments.contains('test_driver') ||
|
||||
relativeRootSegments.contains('test')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var libFolder = root.getChildAssumingFolder('lib');
|
||||
var libSrcFolder = libFolder.getChildAssumingFolder('src');
|
||||
var libSrcTestingFolder = libSrcFolder.getChildAssumingFolder('testing');
|
||||
if (libSrcTestingFolder.contains(file.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var libTestDriverFolder = libFolder.getChildAssumingFolder('test_driver');
|
||||
if (libTestDriverFolder.contains(file.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (var binPath in workspace.binPaths) {
|
||||
var binFolder = workspace.provider.getFolder(binPath);
|
||||
var genPackageRoot = binFolder.getChildAssumingFolder(relativeRoot);
|
||||
if (isInTestDirectoryUnder(genPackageRoot, file)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var genLibSrcTestingFolder = genPackageRoot
|
||||
.getChildAssumingFolder('lib')
|
||||
.getChildAssumingFolder('src')
|
||||
.getChildAssumingFolder('testing');
|
||||
if (genLibSrcTestingFolder.contains(file.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var genLibTestDriverFolder = genPackageRoot
|
||||
.getChildAssumingFolder('lib')
|
||||
.getChildAssumingFolder('test_driver');
|
||||
if (genLibTestDriverFolder.contains(file.path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
var genfilesFolder = workspace.provider.getFolder(workspace.genfiles);
|
||||
var genPackageRoot = genfilesFolder.getChildAssumingFolder(relativeRoot);
|
||||
if (isInTestDirectoryUnder(genPackageRoot, file)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var genLibSrcTestingFolder = genPackageRoot
|
||||
.getChildAssumingFolder('lib')
|
||||
.getChildAssumingFolder('src')
|
||||
.getChildAssumingFolder('testing');
|
||||
if (genLibSrcTestingFolder.contains(file.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var genLibTestDriverFolder = genPackageRoot
|
||||
.getChildAssumingFolder('lib')
|
||||
.getChildAssumingFolder('test_driver');
|
||||
if (genLibTestDriverFolder.contains(file.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.isInTestDirectory(file);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -793,6 +793,119 @@ class BlazeWorkspacePackageTest with ResourceProviderMixin {
|
||||
package.isInTestDirectory(getFile('/ws/some/code/test/a.dart')),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
// lib/src/testing is considered in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/some/code/lib/src/testing/a.dart'),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
// lib/src/test is NOT considered in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(getFile('/ws/some/code/lib/src/test/a.dart')),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
// lib/testing is NOT considered in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(getFile('/ws/some/code/lib/testing/a.dart')),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
// Generated lib/src/testing under blaze-bin is in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/blaze-bin/some/code/lib/src/testing/a.dart'),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
// Generated lib/src/testing under blaze-genfiles is in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/blaze-genfiles/some/code/lib/src/testing/a.dart'),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
// Generated lib/src/test under blaze-bin is NOT in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/blaze-bin/some/code/lib/src/test/a.dart'),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
// lib/test_driver is considered in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/some/code/lib/test_driver/a.dart'),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
// Generated lib/test_driver under blaze-bin is in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/blaze-bin/some/code/lib/test_driver/a.dart'),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
// Generated lib/test_driver under blaze-genfiles is in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/blaze-genfiles/some/code/lib/test_driver/a.dart'),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
// Generated test/a_test.0.dart under blaze-bin is in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/blaze-bin/some/code/test/a_test.0.dart'),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
// Generated test/a_test.0.dart under blaze-genfiles is in a test directory
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/blaze-genfiles/some/code/test/a_test.0.dart'),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
}
|
||||
|
||||
void test_isInTestDirectory_packageIntegrationTest() {
|
||||
_setUpPackageWithPath('/ws/some/integration_test/code');
|
||||
|
||||
expect(
|
||||
package.isInTestDirectory(
|
||||
getFile('/ws/some/integration_test/code/lib/a.dart'),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
}
|
||||
|
||||
void test_isInTestDirectory_packageSubFolderTest() {
|
||||
_setUpPackageWithPath('/ws/some/code/test/foo');
|
||||
|
||||
expect(
|
||||
package.isInTestDirectory(getFile('/ws/some/code/test/foo/lib/a.dart')),
|
||||
isTrue,
|
||||
);
|
||||
}
|
||||
|
||||
void test_isInTestDirectory_packageTesting() {
|
||||
_setUpPackageWithPath('/ws/some/testing/code');
|
||||
|
||||
expect(
|
||||
package.isInTestDirectory(getFile('/ws/some/testing/code/lib/a.dart')),
|
||||
isTrue,
|
||||
);
|
||||
}
|
||||
|
||||
void test_packagesAvailableTo() {
|
||||
@@ -839,6 +952,23 @@ class BlazeWorkspacePackageTest with ResourceProviderMixin {
|
||||
)!;
|
||||
}
|
||||
|
||||
void _setUpPackageWithPath(String packagePath) {
|
||||
_addResources([
|
||||
'/ws/${file_paths.blazeWorkspaceMarker}',
|
||||
'/ws/blaze-genfiles/',
|
||||
'$packagePath/BUILD',
|
||||
'$packagePath/lib/code.dart',
|
||||
]);
|
||||
|
||||
workspace = BlazeWorkspace.find(
|
||||
resourceProvider,
|
||||
convertPath(packagePath),
|
||||
)!;
|
||||
package = workspace.findPackageFor(
|
||||
convertPath('$packagePath/lib/code.dart'),
|
||||
)!;
|
||||
}
|
||||
|
||||
Source _testSource(String path) {
|
||||
return FileSource(newFile(path, ''));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user