Skip to content

Commit da57016

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer_testing: Move three mock packages
This moves the sources for the mock fixnum, test_reflective_loader, and vector_math packages to be loaded via multi-line Dart strings. Change-Id: I95800ebc417afd4a6b1a5103ffd9e69329022cf3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461526 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent de77c6b commit da57016

File tree

12 files changed

+122
-59
lines changed

12 files changed

+122
-59
lines changed

pkg/analyzer_testing/lib/mock_packages/mock_packages.dart

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
import 'package:analyzer/file_system/file_system.dart';
66
import 'package:analyzer/file_system/physical_file_system.dart';
77
import 'package:analyzer_testing/package_root.dart' as package_root;
8+
import 'package:analyzer_testing/src/mock_packages/fixnum/fixnum.dart'
9+
as mock_fixnum;
10+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
11+
import 'package:analyzer_testing/src/mock_packages/test_reflective_loader/test_reflective_loader.dart'
12+
as test_reflective_loader;
13+
import 'package:analyzer_testing/src/mock_packages/vector_math/vector_math.dart'
14+
as mock_vector_math;
815
import 'package:analyzer_testing/utilities/extensions/resource_provider.dart';
916
import 'package:path/path.dart' as path;
1017

@@ -97,7 +104,7 @@ mixin MockPackagesMixin {
97104
}
98105

99106
Folder addFixnum() {
100-
var packageFolder = _addFiles('fixnum');
107+
var packageFolder = _addFiles2('fixnum', mock_fixnum.units);
101108
return packageFolder.getChildAssumingFolder('lib');
102109
}
103110

@@ -144,7 +151,10 @@ mixin MockPackagesMixin {
144151
}
145152

146153
Folder addTestReflectiveLoader() {
147-
var packageFolder = _addFiles('test_reflective_loader');
154+
var packageFolder = _addFiles2(
155+
'test_reflective_loader',
156+
test_reflective_loader.units,
157+
);
148158
return packageFolder.getChildAssumingFolder('lib');
149159
}
150160

@@ -154,11 +164,15 @@ mixin MockPackagesMixin {
154164
}
155165

156166
Folder addVectorMath() {
157-
var packageFolder = _addFiles('vector_math');
167+
var packageFolder = _addFiles2('vector_math', mock_vector_math.units);
158168
return packageFolder.getChildAssumingFolder('lib');
159169
}
160170

161171
/// Adds files of the given [packageName] to the [resourceProvider].
172+
///
173+
/// This method adds files from the sources found in
174+
/// [package_root.packageRoot]. The mock sources are being moved to
175+
/// `lib/src/mock_sources/`, accessible via [_addFiles2].
162176
Folder _addFiles(String packageName) {
163177
Map<String, String> cachedFiles;
164178
try {
@@ -187,4 +201,21 @@ mixin MockPackagesMixin {
187201
);
188202
return packagesFolder.getChildAssumingFolder(packageName);
189203
}
204+
205+
/// Adds files of the given [packageName] to the [resourceProvider].
206+
Folder _addFiles2(String packageName, List<MockLibraryUnit> units) {
207+
var absolutePackagePath = resourceProvider.convertPath(
208+
'$packagesRootPath/$packageName/$packageName',
209+
);
210+
for (var unit in units) {
211+
var absoluteUnitPath = resourceProvider.convertPath(
212+
'$absolutePackagePath/${unit.path}',
213+
);
214+
resourceProvider
215+
.getFile(absoluteUnitPath)
216+
.writeAsStringSync(unit.content);
217+
}
218+
219+
return resourceProvider.getFolder(absolutePackagePath);
220+
}
190221
}

pkg/analyzer_testing/lib/mock_packages/package_content/fixnum/lib/fixnum.dart

Lines changed: 0 additions & 5 deletions
This file was deleted.

pkg/analyzer_testing/lib/mock_packages/package_content/fixnum/pubspec.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

pkg/analyzer_testing/lib/mock_packages/package_content/test_reflective_loader/lib/test_reflective_loader.dart

Lines changed: 0 additions & 17 deletions
This file was deleted.

pkg/analyzer_testing/lib/mock_packages/package_content/test_reflective_loader/pubspec.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

pkg/analyzer_testing/lib/mock_packages/package_content/vector_math/lib/matrix4.dart

Lines changed: 0 additions & 9 deletions
This file was deleted.

pkg/analyzer_testing/lib/mock_packages/package_content/vector_math/lib/vector_math_64.dart

Lines changed: 0 additions & 22 deletions
This file was deleted.

pkg/analyzer_testing/lib/mock_packages/package_content/vector_math/pubspec.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
/// The set of units that make up the mock 'fixnum' package.
8+
final List<MockLibraryUnit> units = [_fixnumLibrary];
9+
10+
final _fixnumLibrary = MockLibraryUnit('lib/fixnum.dart', r'''
11+
library fixnum;
12+
13+
class Int32 {}
14+
15+
class Int64 {}
16+
''');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
class MockLibraryUnit {
6+
/// The relative path of this compilation unit, relative to the package root.
7+
///
8+
/// Typically, this will start with 'lib/'.
9+
final String path;
10+
11+
/// The source content of the compilation unit.
12+
final String content;
13+
14+
MockLibraryUnit(this.path, this.content);
15+
}

0 commit comments

Comments
 (0)