55import 'dart:async' ;
66import 'dart:isolate' ;
77
8+ import 'package:analyzer/file_system/file_system.dart' ;
89import 'package:analyzer/src/util/file_paths.dart' as file_paths;
910import 'package:analyzer/src/workspace/blaze.dart' ;
1011import 'package:analyzer/src/workspace/blaze_watcher.dart' ;
@@ -25,22 +26,22 @@ class BlazeWatcherTest with ResourceProviderMixin {
2526 late final BlazeWorkspace workspace;
2627
2728 void test_blazeFileWatcher () {
28- _addResources ([ '/workspace/${file_paths .blazeWorkspaceMarker }' ] );
29+ _addResource ( '/workspace/${file_paths .blazeWorkspaceMarker }' );
2930 var candidates = [
3031 convertPath ('/workspace/blaze-bin/my/module/test1.dart' ),
3132 convertPath ('/workspace/blaze-genfiles/my/module/test1.dart' ),
3233 ];
3334 var watcher = BlazeFilePoller (resourceProvider, candidates);
3435
3536 // First do some tests with the first candidate path.
36- _addResources ([ candidates[0 ]]) ;
37+ var firstCandidate = _addResource ( candidates[0 ]) as File ;
3738
3839 var event = watcher.poll ()! ;
3940
4041 expect (event.type, ChangeType .ADD );
4142 expect (event.path, candidates[0 ]);
4243
43- modifyFile (candidates[ 0 ] , 'const foo = 42;' );
44+ modifyFile2 (firstCandidate , 'const foo = 42;' );
4445
4546 event = watcher.poll ()! ;
4647
@@ -56,7 +57,7 @@ class BlazeWatcherTest with ResourceProviderMixin {
5657
5758 // Now check that if we add the *second* candidate, we'll get the
5859 // notification for it.
59- _addResources ([ candidates[1 ] ]);
60+ _addResource ( candidates[1 ]);
6061
6162 event = watcher.poll ()! ;
6263
@@ -68,7 +69,7 @@ class BlazeWatcherTest with ResourceProviderMixin {
6869 }
6970
7071 void test_blazeFileWatcherIsolate () async {
71- _addResources ([ '/workspace/${file_paths .blazeWorkspaceMarker }' ] );
72+ _addResource ( '/workspace/${file_paths .blazeWorkspaceMarker }' );
7273 var candidates1 = [
7374 convertPath ('/workspace/blaze-bin/my/module/test1.dart' ),
7475 convertPath ('/workspace/blaze-genfiles/my/module/test1.dart' ),
@@ -113,7 +114,7 @@ class BlazeWatcherTest with ResourceProviderMixin {
113114 );
114115
115116 // First do some tests with the first candidate path.
116- _addResources ([ candidates1[0 ] ]);
117+ _addResource ( candidates1[0 ]);
117118
118119 trigger.controller.add ('' );
119120 var events = (await queue.next as BlazeWatcherEvents ).events;
@@ -123,7 +124,7 @@ class BlazeWatcherTest with ResourceProviderMixin {
123124 expect (events[0 ].type, ChangeType .ADD );
124125
125126 // Now let's take a look at the second file.
126- _addResources ([ candidates2[1 ] ]);
127+ _addResource ( candidates2[1 ]);
127128
128129 trigger.controller.add ('' );
129130 events = (await queue.next as BlazeWatcherEvents ).events;
@@ -162,10 +163,8 @@ class BlazeWatcherTest with ResourceProviderMixin {
162163 }
163164
164165 void test_blazeFileWatcherIsolate_multipleWorkspaces () async {
165- _addResources ([
166- '/workspace1/${file_paths .blazeWorkspaceMarker }' ,
167- '/workspace2/${file_paths .blazeWorkspaceMarker }' ,
168- ]);
166+ _addResource ('/workspace1/${file_paths .blazeWorkspaceMarker }' );
167+ _addResource ('/workspace2/${file_paths .blazeWorkspaceMarker }' );
169168 var candidates1 = [
170169 convertPath ('/workspace1/blaze-bin/my/module/test1.dart' ),
171170 convertPath ('/workspace1/blaze-genfiles/my/module/test1.dart' ),
@@ -223,7 +222,7 @@ class BlazeWatcherTest with ResourceProviderMixin {
223222 );
224223
225224 // First do some tests with the first candidate path.
226- _addResources ([ candidates1[0 ] ]);
225+ _addResource ( candidates1[0 ]);
227226
228227 trigger1! .controller.add ('' );
229228 var events = (await queue.next as BlazeWatcherEvents ).events;
@@ -233,7 +232,7 @@ class BlazeWatcherTest with ResourceProviderMixin {
233232 expect (events[0 ].type, ChangeType .ADD );
234233
235234 // Now let's take a look at the second file.
236- _addResources ([ candidates2[1 ] ]);
235+ _addResource ( candidates2[1 ]);
237236
238237 trigger2! .controller.add ('' );
239238 events = (await queue.next as BlazeWatcherEvents ).events;
@@ -272,11 +271,11 @@ class BlazeWatcherTest with ResourceProviderMixin {
272271 }
273272
274273 void test_blazeFileWatcherWithFolder () {
275- _addResources ([ '/workspace/${file_paths .blazeWorkspaceMarker }' ] );
274+ _addResource ( '/workspace/${file_paths .blazeWorkspaceMarker }' );
276275
277276 // The `_addResources`/`_deleteResources` functions recognize a folder by a
278277 // trailing `/`, but everywhere else we need to use normalized paths.
279- void addFolder (path) => _addResources ([ '$path /' ] );
278+ void addFolder (path) => _addResource ( '$path /' );
280279 void deleteFolder (path) => _deleteResources (['$path /' ]);
281280
282281 var candidates = [
@@ -310,14 +309,12 @@ class BlazeWatcherTest with ResourceProviderMixin {
310309 expect (watcher.poll (), isNull);
311310 }
312311
313- /// Create new files and directories from [paths] .
314- void _addResources (List <String > paths) {
315- for (String path in paths) {
316- if (path.endsWith ('/' )) {
317- newFolder (path.substring (0 , path.length - 1 ));
318- } else {
319- newFile (path, '' );
320- }
312+ /// Creates a new file or directory from [resourcePath] .
313+ Resource _addResource (String resourcePath) {
314+ if (resourcePath.endsWith ('/' )) {
315+ return newFolder (resourcePath.substring (0 , resourcePath.length - 1 ));
316+ } else {
317+ return newFile (resourcePath, '' );
321318 }
322319 }
323320
0 commit comments