Skip to content

Commit f4a09ee

Browse files
keertipCommit Queue
authored andcommitted
Add tests for nested contexts with single options file.
BUG: #56552 Change-Id: Ic0588c4f5eaea2aead0546d148f848802b15499b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388642 Commit-Queue: Keerti Parthasarathy <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 26f2ff4 commit f4a09ee

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

pkg/analyzer/test/src/dart/analysis/analysis_context_collection_test.dart

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,78 @@ workspaces
280280
''');
281281
}
282282

283+
test_multiplePackageConfigWorkspace_singleAnalysisOptions_exclude() async {
284+
configuration.withOptionFilesForContext = true;
285+
286+
var workspaceRootPath = '/home';
287+
var testPackageRootPath = '$workspaceRootPath/test';
288+
var testPackageLibPath = '$testPackageRootPath/lib';
289+
290+
newPubspecYamlFile(testPackageRootPath, r'''
291+
name: test
292+
''');
293+
294+
newSinglePackageConfigJsonFile(
295+
packagePath: testPackageRootPath,
296+
name: 'test',
297+
);
298+
299+
newFile('$testPackageLibPath/a.dart', '');
300+
newFile('$testPackageLibPath/b.g.dart', '');
301+
newAnalysisOptionsYamlFile(testPackageRootPath, r'''
302+
analyzer:
303+
exclude:
304+
- "**/*.g.dart"
305+
''');
306+
307+
var nestedPath = '$testPackageLibPath/nested';
308+
newFile('$nestedPath/lib/c.dart', '');
309+
newFile('$nestedPath/lib/d.g.dart', '');
310+
311+
newSinglePackageConfigJsonFile(
312+
packagePath: nestedPath,
313+
name: 'nested',
314+
);
315+
newPubspecYamlFile(nestedPath, r'''
316+
name: nested
317+
''');
318+
319+
_assertWorkspaceCollectionText(workspaceRootPath, r'''
320+
contexts
321+
/home/test
322+
packagesFile: /home/test/.dart_tool/package_config.json
323+
optionsFile: /home/test/analysis_options.yaml
324+
workspace: workspace_0
325+
analyzedFiles
326+
/home/test/lib/a.dart
327+
uri: package:test/a.dart
328+
analysisOptions_0
329+
workspacePackage_0_0
330+
/home/test/lib/nested
331+
packagesFile: /home/test/lib/nested/.dart_tool/package_config.json
332+
optionsFile: /home/test/analysis_options.yaml
333+
workspace: workspace_1
334+
analyzedFiles
335+
/home/test/lib/nested/lib/c.dart
336+
uri: package:nested/c.dart
337+
analysisOptions_0
338+
workspacePackage_1_0
339+
analysisOptions
340+
analysisOptions_0: /home/test/analysis_options.yaml
341+
workspaces
342+
workspace_0: PackageConfigWorkspace
343+
root: /home/test
344+
pubPackages
345+
workspacePackage_0_0: PubPackage
346+
root: /home/test
347+
workspace_1: PackageConfigWorkspace
348+
root: /home/test/lib/nested
349+
pubPackages
350+
workspacePackage_1_0: PubPackage
351+
root: /home/test/lib/nested
352+
''');
353+
}
354+
283355
test_packageConfigWorkspace_enabledExperiment() async {
284356
configuration.withEnabledFeatures = true;
285357

@@ -1119,6 +1191,9 @@ class _AnalysisContextCollectionPrinter {
11191191
sink.writelnWithIndent(contextRoot.root.posixPath);
11201192
sink.withIndent(() {
11211193
_writeNamedFile('packagesFile', contextRoot.packagesFile);
1194+
if (configuration.withOptionFilesForContext) {
1195+
_writeNamedFile('optionsFile', contextRoot.optionsFile);
1196+
}
11221197
sink.writelnWithIndent(
11231198
'workspace: ${_idOfWorkspace(contextRoot.workspace)}',
11241199
);
@@ -1265,4 +1340,5 @@ class _AnalysisContextCollectionPrinterConfiguration {
12651340
bool withEmptyContextRoots = false;
12661341
bool withEnabledFeatures = false;
12671342
bool withLintRules = false;
1343+
bool withOptionFilesForContext = false;
12681344
}

pkg/analyzer/test/src/dart/analysis/context_locator_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,38 @@ analyzer:
7777
_assertAnalyzedFiles2(root, [optionsFile, fooFile]);
7878
}
7979

80+
void test_locateRoots_excludedByOptions_in_subDirectory() {
81+
var rootPath = convertPath('/home/test (copy)');
82+
var rootFolder = newFolder(rootPath);
83+
var optionsFile = newAnalysisOptionsYamlFile(rootPath, r'''
84+
analyzer:
85+
exclude:
86+
- "**/*.g.dart"
87+
''');
88+
newPackageConfigJsonFile(rootPath, '');
89+
var fooFile = newFile('$rootPath/lib/foo.dart', '');
90+
newFile('$rootPath/lib/bar.g.dart', '');
91+
92+
var pkg1Path = convertPath('$rootPath/lib/pkg1');
93+
var pkg1Folder = newFolder(pkg1Path);
94+
newPackageConfigJsonFile(pkg1Path, '');
95+
newFile('$pkg1Path/lib/src/bar.g.dart', '');
96+
var fooFile2 = newFile('$pkg1Path/lib/foo.dart', '');
97+
var roots = contextLocator.locateRoots(
98+
includedPaths: [rootFolder.path],
99+
);
100+
expect(roots, hasLength(2));
101+
102+
var root = findRoot(roots, rootFolder);
103+
104+
_assertAnalyzedFiles2(root, [optionsFile, fooFile]);
105+
106+
root = findRoot(roots, pkg1Folder);
107+
expect(root.optionsFile, optionsFile);
108+
109+
_assertAnalyzedFiles2(root, [fooFile2]);
110+
}
111+
80112
void test_locateRoots_link_file_toOutOfRoot() {
81113
Folder rootFolder = newFolder('/home/test');
82114
newFile('/home/test/lib/a.dart', '');

0 commit comments

Comments
 (0)