@@ -11,13 +11,16 @@ import 'package:analysis_server/protocol/protocol_constants.dart';
11
11
import 'package:analysis_server/protocol/protocol_generated.dart' ;
12
12
import 'package:analysis_server/src/services/pub/pub_command.dart' ;
13
13
import 'package:analyzer/file_system/physical_file_system.dart' ;
14
+ import 'package:analyzer/src/util/file_paths.dart' as file_paths;
14
15
import 'package:analyzer_plugin/protocol/protocol_common.dart' ;
15
16
import 'package:meta/meta.dart' ;
16
17
import 'package:path/path.dart' as path;
17
18
import 'package:test/test.dart' ;
18
19
20
+ import '../../analysis_server_base.dart' show AnalysisOptionsFileConfig;
19
21
import '../../src/utilities/mock_packages.dart' ;
20
22
import '../../support/configuration_files.dart' ;
23
+ import '../../test_macros.dart' as macros;
21
24
import 'integration_test_methods.dart' ;
22
25
import 'protocol_matchers.dart' ;
23
26
@@ -86,7 +89,7 @@ typedef NotificationProcessor = void Function(
86
89
87
90
/// Base class for analysis server integration tests.
88
91
abstract class AbstractAnalysisServerIntegrationTest extends IntegrationTest
89
- with MockPackagesMixin , ConfigurationFilesMixin {
92
+ with MockPackagesMixin , ConfigurationFilesMixin , macros. TestMacros {
90
93
/// Amount of time to give the server to respond to a shutdown request before
91
94
/// forcibly terminating it.
92
95
static const Duration SHUTDOWN_TIMEOUT = Duration (seconds: 60 );
@@ -151,6 +154,24 @@ abstract class AbstractAnalysisServerIntegrationTest extends IntegrationTest
151
154
@override
152
155
String get testPackageRootPath => sourceDirectory.path;
153
156
157
+ /// Adds support for macros to the `package_config.json` file and creates a
158
+ /// `macros.dart` file that defines the given [macros] . The macros should not
159
+ /// include imports, the imports for macros will be added automatically.
160
+ void addMacros (List <String > macros) {
161
+ writeTestPackageConfig (
162
+ macro : true ,
163
+ );
164
+ writeFile (
165
+ '$testPackageRootPath /lib/macros.dart' ,
166
+ [
167
+ '''
168
+ // There is no public API exposed yet, the in-progress API lives here.
169
+ import 'package:_fe_analyzer_shared/src/macros/api.dart';
170
+ ''' ,
171
+ ...macros
172
+ ].join ('\n ' ));
173
+ }
174
+
154
175
/// Print out any messages exchanged with the server. If some messages have
155
176
/// already been exchanged with the server, they are printed out immediately.
156
177
void debugStdio () {
@@ -193,6 +214,12 @@ abstract class AbstractAnalysisServerIntegrationTest extends IntegrationTest
193
214
..createSync ();
194
215
writeTestPackageConfig ();
195
216
217
+ writeTestPackageAnalysisOptionsFile (
218
+ AnalysisOptionsFileConfig (
219
+ experiments: ['macros' ],
220
+ ),
221
+ );
222
+
196
223
onAnalysisErrors.listen ((AnalysisErrorsParams params) {
197
224
currentAnalysisErrors[params.file] = params.errors;
198
225
});
@@ -302,6 +329,12 @@ abstract class AbstractAnalysisServerIntegrationTest extends IntegrationTest
302
329
file.writeAsStringSync (contents);
303
330
return file.resolveSymbolicLinksSync ();
304
331
}
332
+
333
+ void writeTestPackageAnalysisOptionsFile (AnalysisOptionsFileConfig config) {
334
+ String filePath =
335
+ path.join (testPackageRootPath, file_paths.analysisOptionsYaml);
336
+ writeFile (filePath, config.toContent ());
337
+ }
305
338
}
306
339
307
340
/// Wrapper class for Matcher which doesn't create the underlying Matcher object
0 commit comments