4
4
5
5
import 'dart:async' ;
6
6
7
+ import 'package:file/memory.dart' ;
8
+ import 'package:flutter_tools/src/base/platform.dart' ;
7
9
import 'package:flutter_tools/src/cache.dart' ;
8
10
import 'package:flutter_tools/src/debug_adapters/flutter_adapter_args.dart' ;
9
- import 'package:flutter_tools/src/globals.dart' as globals;
11
+ import 'package:flutter_tools/src/globals.dart' as globals show platform ;
10
12
import 'package:test/fake.dart' ;
11
13
import 'package:test/test.dart' ;
12
14
import 'package:vm_service/vm_service.dart' ;
13
15
14
16
import 'mocks.dart' ;
15
17
16
18
void main () {
19
+ // Use the real platform as a base so that Windows bots test paths.
20
+ final FakePlatform platform = FakePlatform .fromPlatform (globals.platform);
21
+ final FileSystemStyle fsStyle = platform.isWindows ? FileSystemStyle .windows : FileSystemStyle .posix;
22
+
17
23
group ('flutter adapter' , () {
18
- final String expectedFlutterExecutable = globals. platform.isWindows
24
+ final String expectedFlutterExecutable = platform.isWindows
19
25
? r'C:\fake\flutter\bin\flutter.bat'
20
26
: '/fake/flutter/bin/flutter' ;
21
27
22
28
setUpAll (() {
23
- Cache .flutterRoot = globals. platform.isWindows
29
+ Cache .flutterRoot = platform.isWindows
24
30
? r'C:\fake\flutter'
25
31
: '/fake/flutter' ;
26
32
});
27
33
28
-
29
- group ('launchRequest' , () {
30
- test ('runs "flutter run" with --machine' , () async {
31
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
34
+ group ('launchRequest' , () {
35
+ test ('runs "flutter run" with --machine' , () async {
36
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
37
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
38
+ platform: platform,
39
+ );
32
40
final Completer <void > responseCompleter = Completer <void >();
33
41
34
42
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
@@ -43,8 +51,33 @@ void main() {
43
51
expect (adapter.processArgs, containsAllInOrder (< String > ['run' , '--machine' ]));
44
52
});
45
53
54
+ test ('includes env variables' , () async {
55
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
56
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
57
+ platform: platform,
58
+ );
59
+ final Completer <void > responseCompleter = Completer <void >();
60
+
61
+ final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
62
+ cwd: '/project' ,
63
+ program: 'foo.dart' ,
64
+ env: < String , String > {
65
+ 'MY_TEST_ENV' : 'MY_TEST_VALUE' ,
66
+ },
67
+ );
68
+
69
+ await adapter.configurationDoneRequest (MockRequest (), null , () {});
70
+ await adapter.launchRequest (MockRequest (), args, responseCompleter.complete);
71
+ await responseCompleter.future;
72
+
73
+ expect (adapter.env! ['MY_TEST_ENV' ], 'MY_TEST_VALUE' );
74
+ });
75
+
46
76
test ('does not record the VMs PID for terminating' , () async {
47
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
77
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
78
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
79
+ platform: platform,
80
+ );
48
81
final Completer <void > responseCompleter = Completer <void >();
49
82
50
83
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
@@ -65,10 +98,12 @@ void main() {
65
98
});
66
99
});
67
100
68
-
69
- group ('attachRequest' , () {
70
- test ('runs "flutter attach" with --machine' , () async {
71
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
101
+ group ('attachRequest' , () {
102
+ test ('runs "flutter attach" with --machine' , () async {
103
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
104
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
105
+ platform: platform,
106
+ );
72
107
final Completer <void > responseCompleter = Completer <void >();
73
108
74
109
final FlutterAttachRequestArguments args = FlutterAttachRequestArguments (
@@ -83,7 +118,10 @@ void main() {
83
118
});
84
119
85
120
test ('does not record the VMs PID for terminating' , () async {
86
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
121
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
122
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
123
+ platform: platform,
124
+ );
87
125
final Completer <void > responseCompleter = Completer <void >();
88
126
89
127
final FlutterAttachRequestArguments args = FlutterAttachRequestArguments (
@@ -105,7 +143,10 @@ void main() {
105
143
106
144
group ('--start-paused' , () {
107
145
test ('is passed for debug mode' , () async {
108
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
146
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
147
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
148
+ platform: platform,
149
+ );
109
150
final Completer <void > responseCompleter = Completer <void >();
110
151
111
152
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
@@ -121,7 +162,10 @@ void main() {
121
162
});
122
163
123
164
test ('is not passed for noDebug mode' , () async {
124
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
165
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
166
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
167
+ platform: platform,
168
+ );
125
169
final Completer <void > responseCompleter = Completer <void >();
126
170
127
171
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
@@ -138,7 +182,10 @@ void main() {
138
182
});
139
183
140
184
test ('is not passed if toolArgs contains --profile' , () async {
141
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
185
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
186
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
187
+ platform: platform,
188
+ );
142
189
final Completer <void > responseCompleter = Completer <void >();
143
190
144
191
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
@@ -155,7 +202,10 @@ void main() {
155
202
});
156
203
157
204
test ('is not passed if toolArgs contains --release' , () async {
158
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
205
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
206
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
207
+ platform: platform,
208
+ );
159
209
final Completer <void > responseCompleter = Completer <void >();
160
210
161
211
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
@@ -173,7 +223,10 @@ void main() {
173
223
});
174
224
175
225
test ('includes toolArgs' , () async {
176
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
226
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
227
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
228
+ platform: platform,
229
+ );
177
230
final Completer <void > responseCompleter = Completer <void >();
178
231
179
232
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
@@ -193,7 +246,10 @@ void main() {
193
246
194
247
group ('includes customTool' , () {
195
248
test ('with no args replaced' , () async {
196
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
249
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
250
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
251
+ platform: platform,
252
+ );
197
253
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
198
254
cwd: '/project' ,
199
255
program: 'foo.dart' ,
@@ -212,7 +268,10 @@ void main() {
212
268
});
213
269
214
270
test ('with all args replaced' , () async {
215
- final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (fileSystem: globals.fs, platform: globals.platform);
271
+ final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter (
272
+ fileSystem: MemoryFileSystem .test (style: fsStyle),
273
+ platform: platform,
274
+ );
216
275
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments (
217
276
cwd: '/project' ,
218
277
program: 'foo.dart' ,
0 commit comments