Skip to content

Commit a3c7d37

Browse files
fix: failing test on Windows (#1407)
Co-authored-by: Erick <[email protected]>
1 parent f15d6a8 commit a3c7d37

File tree

7 files changed

+77
-40
lines changed

7 files changed

+77
-40
lines changed

test/fixtures/lcov_fixtures.dart

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
const lcov100 = '''
2-
SF:/bloc/packages/bloc/lib/src/bloc.dart
1+
import 'package:path/path.dart' as p;
2+
3+
final lcov100 =
4+
'''
5+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'bloc.dart')}
36
DA:21,2
47
DA:22,1
58
DA:26,3
@@ -43,7 +46,7 @@ DA:250,1
4346
LF:40
4447
LH:40
4548
end_of_record
46-
SF:/bloc/packages/bloc/lib/src/bloc_observer.dart
49+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'bloc_observer.dart')}
4750
DA:14,1
4851
DA:20,1
4952
DA:27,1
@@ -53,7 +56,7 @@ DA:51,1
5356
LF:6
5457
LH:6
5558
end_of_record
56-
SF:/bloc/packages/bloc/lib/src/change.dart
59+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'change.dart')}
5760
DA:10,1
5861
DA:18,1
5962
DA:21,1
@@ -67,7 +70,7 @@ DA:31,3
6770
LF:10
6871
LH:10
6972
end_of_record
70-
SF:/bloc/packages/bloc/lib/src/cubit.dart
73+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'cubit.dart')}
7174
DA:16,1
7275
DA:27,1
7376
DA:29,3
@@ -103,7 +106,7 @@ DA:179,2
103106
LF:32
104107
LH:32
105108
end_of_record
106-
SF:/bloc/packages/bloc/lib/src/transition.dart
109+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'transition.dart')}
107110
DA:14,1
108111
DA:18,1
109112
DA:23,1
@@ -121,8 +124,9 @@ LH:12
121124
end_of_record
122125
''';
123126

124-
const lcov95 = '''
125-
SF:/bloc/packages/bloc/lib/src/bloc.dart
127+
final lcov95 =
128+
'''
129+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'bloc.dart')}
126130
DA:21,2
127131
DA:22,1
128132
DA:26,3
@@ -166,7 +170,7 @@ DA:250,1
166170
LF:40
167171
LH:40
168172
end_of_record
169-
SF:/bloc/packages/bloc/lib/src/bloc_observer.dart
173+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'bloc_observer.dart')}
170174
DA:14,1
171175
DA:20,0
172176
DA:27,0
@@ -176,7 +180,7 @@ DA:51,0
176180
LF:6
177181
LH:1
178182
end_of_record
179-
SF:/bloc/packages/bloc/lib/src/change.dart
183+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'change.dart')}
180184
DA:10,1
181185
DA:18,1
182186
DA:21,1
@@ -190,7 +194,7 @@ DA:31,3
190194
LF:10
191195
LH:10
192196
end_of_record
193-
SF:/bloc/packages/bloc/lib/src/cubit.dart
197+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'cubit.dart')}
194198
DA:16,1
195199
DA:27,1
196200
DA:29,3
@@ -226,7 +230,7 @@ DA:179,2
226230
LF:32
227231
LH:32
228232
end_of_record
229-
SF:/bloc/packages/bloc/lib/src/transition.dart
233+
SF:${p.join('bloc', 'packages', 'bloc', 'lib', 'src', 'transition.dart')}
230234
DA:14,1
231235
DA:18,1
232236
DA:23,1

test/src/cli/test_runner_cli_test.dart

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:stack_trace/stack_trace.dart' as stack_trace;
1111
import 'package:test/test.dart';
1212
import 'package:very_good_cli/src/cli/cli.dart';
1313
import 'package:very_good_test_runner/very_good_test_runner.dart';
14+
1415
import '../../fixtures/fixtures.dart';
1516

1617
class _MockMasonGenerator extends Mock implements MasonGenerator {}
@@ -338,6 +339,14 @@ void main() {
338339
'\x1B[2K\r00:12 +7 -1: Some tests failed.\n',
339340
]),
340341
);
342+
343+
final testPath = p.join(
344+
'test',
345+
'counter',
346+
'cubit',
347+
'counter_cubit_test.dart',
348+
);
349+
341350
expect(
342351
stderrLogs,
343352
equals(
@@ -349,7 +358,7 @@ void main() {
349358
'test/counter/cubit/counter_cubit_test.dart 16:7 main.<fn>.<fn>\n',
350359
'\x1B[2K\rCounterCubit initial state is 0 ${tempDirectory.path}/test/counter/cubit/counter_cubit_test.dart (FAILED)',
351360
'\x1B[2K\rFailing Tests:\n'
352-
'\x1B[2K\r - test/counter/cubit/counter_cubit_test.dart \n'
361+
'\x1B[2K\r - $testPath \n'
353362
'\x1B[2K\r \t- [FAILED] CounterCubit initial state is 0\n',
354363
],
355364
),
@@ -424,7 +433,8 @@ void main() {
424433
'The test description was: renders CounterPage',
425434
'\x1B[2K\rApp renders CounterPage ${tempDirectory.path}/test/app/view/app_test.dart (FAILED)',
426435
'\x1B[2K\rFailing Tests:\n'
427-
'\x1B[2K\r - test/app/view/app_test.dart \n'
436+
'\x1B[2K\r - '
437+
'${p.join('test', 'app', 'view', 'app_test.dart')} \n'
428438
'\x1B[2K\r \t- [ERROR] App renders CounterPage\n',
429439
]),
430440
);
@@ -528,9 +538,10 @@ void main() {
528538
stderrLogs,
529539
equals([
530540
'\x1B[2K\rerror',
531-
'\x1B[2K\rtest/example_test.dart 4 main\n',
541+
'\x1B[2K\r${p.join('test', 'example_test.dart')} 4 main\n',
532542
'\x1B[2K\rFailing Tests:\n'
533-
'\x1B[2K\r - test/app/view/app_test.dart \n'
543+
'\x1B[2K\r - '
544+
'${p.join('test', 'app', 'view', 'app_test.dart')} \n'
534545
'''\x1B[2K\r \t- [FAILED] CounterCubit emits [1] when increment is called\n''',
535546
]),
536547
);
@@ -879,7 +890,7 @@ void main() {
879890
collectCoverage: true,
880891
minCoverage: 100,
881892
excludeFromCoverage:
882-
'/bloc/packages/bloc/lib/src/bloc_observer.dart',
893+
'bloc/packages/bloc/lib/src/bloc_observer.dart',
883894
stdout: stdoutLogs.add,
884895
stderr: stderrLogs.add,
885896
overrideTestRunner: testRunner(
@@ -1144,7 +1155,11 @@ void main() {
11441155
suite: TestSuite(
11451156
id: 4,
11461157
platform: 'vm',
1147-
path: '${tempDirectory.path}/test/.test_optimizer.dart',
1158+
path: p.join(
1159+
tempDirectory.path,
1160+
'test',
1161+
'.test_optimizer.dart',
1162+
),
11481163
),
11491164
time: 0,
11501165
),
@@ -1204,9 +1219,10 @@ void main() {
12041219
stderrLogs,
12051220
equals([
12061221
'\x1B[2K\rerror',
1207-
'\x1B[2K\rtest/example_test.dart 4 main\n',
1222+
'\x1B[2K\r${p.join('test', 'example_test.dart')} 4 main\n',
12081223
'\x1B[2K\rFailing Tests:\n'
1209-
'\x1B[2K\r - test/app/view/app_test.dart \n'
1224+
'\x1B[2K\r - '
1225+
'${p.join('test', 'app', 'view', 'app_test.dart')} \n'
12101226
'''\x1B[2K\r \t- [FAILED] CounterCubit emits [1] when increment is called\n''',
12111227
]),
12121228
);
@@ -1222,8 +1238,8 @@ void main() {
12221238
final updatedVars = <String, dynamic>{
12231239
'package-root': tempDirectory.path,
12241240
'notOptimizedTests': [
1225-
'app/view/app_test.dart',
1226-
'app/cubit/cubit_test.dart',
1241+
p.join('app', 'view', 'app_test.dart'),
1242+
p.join('app', 'cubit', 'cubit_test.dart'),
12271243
],
12281244
};
12291245
File(p.join(tempDirectory.path, 'pubspec.yaml')).createSync();
@@ -1272,8 +1288,8 @@ void main() {
12721288
testRunnerArgs,
12731289
equals([
12741290
p.join('test', '.test_optimizer.dart'),
1275-
'test/app/view/app_test.dart',
1276-
'test/app/cubit/cubit_test.dart',
1291+
p.join('test', 'app', 'view', 'app_test.dart'),
1292+
p.join('test', 'app', 'cubit', 'cubit_test.dart'),
12771293
]),
12781294
);
12791295
},

test/src/command_runner_test.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ void main() {
199199
});
200200

201201
test('shows message when version changed', () async {
202-
commandRunner.environmentOverride = {'HOME': '/users/test'};
202+
commandRunner.environmentOverride = {
203+
'HOME': '/users/test',
204+
'LOCALAPPDATA': '/users/test',
205+
};
203206

204207
await IOOverrides.runZoned(
205208
() async {
@@ -241,10 +244,12 @@ void main() {
241244
});
242245

243246
test('cache inside XDG directory', () async {
244-
commandRunner.environmentOverride = {
245-
'HOME': '/users/test',
246-
'XDG_CONFIG_HOME': '/users/test/.xdg',
247-
};
247+
commandRunner
248+
..environmentOverride = {
249+
'HOME': '/users/test',
250+
'XDG_CONFIG_HOME': '/users/test/.xdg',
251+
}
252+
..isWindowsOverride = false;
248253

249254
final xdgCache = _MockDirectory();
250255
when(() => xdgCache.path).thenReturn('/users/test/.xdg');

test/src/commands/dart/commands/dart_test_test.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ void main() {
137137
'when no pubspec.yaml exists',
138138
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
139139
final tempDirectory = Directory.systemTemp.createTempSync();
140-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
140+
addTearDown(() {
141+
Directory.current = cwd;
142+
tempDirectory.deleteSync(recursive: true);
143+
});
141144

142145
Directory.current = tempDirectory.path;
143146
final result = await commandRunner.run(['dart', 'test']);
@@ -152,7 +155,10 @@ void main() {
152155
'completes normally when no pubspec.yaml exists (recursive)',
153156
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
154157
final tempDirectory = Directory.systemTemp.createTempSync();
155-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
158+
addTearDown(() {
159+
Directory.current = cwd;
160+
tempDirectory.deleteSync(recursive: true);
161+
});
156162

157163
Directory.current = tempDirectory.path;
158164

test/src/commands/packages/commands/check/commands/licenses_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ and limitations under the License.''');
535535
'nothing',
536536
);
537537
when(() => veryGoodTestRunnerConfigPackage.root).thenReturn(
538-
Uri.parse(packagePath),
538+
Uri.file(packagePath),
539539
);
540540

541541
final targetPath = tempDirectory.path;
@@ -1719,7 +1719,7 @@ and limitations under the License.''');
17191719
'nothing',
17201720
);
17211721
when(() => veryGoodTestRunnerConfigPackage.root).thenReturn(
1722-
Uri.parse(packagePath),
1722+
Uri.file(packagePath),
17231723
);
17241724

17251725
final targetPath = tempDirectory.path;

test/src/commands/packages/commands/get_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ sdk: ^3.9.0
523523
'packages',
524524
'get',
525525
'--recursive',
526-
'${tempDirectory.path}/plugin',
526+
path.join(tempDirectory.path, 'plugin'),
527527
]);
528528

529529
expect(result, equals(ExitCode.success.code));
@@ -541,8 +541,8 @@ sdk: ^3.9.0
541541
verify(() {
542542
logger.progress(
543543
any(
544-
that: contains(
545-
'''Running "flutter pub get" in ./example''',
544+
that: matches(
545+
RegExp(r'Running "flutter pub get" in \.[/\\]example'),
546546
),
547547
),
548548
);
@@ -617,8 +617,8 @@ sdk: ^3.9.0
617617
verify(() {
618618
logger.progress(
619619
any(
620-
that: contains(
621-
'''Running "flutter pub get" in ./my_sub_package''',
620+
that: matches(
621+
RegExp(r'Running "flutter pub get" in \.[/\\]my_sub_package'),
622622
),
623623
),
624624
);

test/src/commands/test/test_test.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ void main() {
139139
'when no pubspec.yaml exists',
140140
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
141141
final tempDirectory = Directory.systemTemp.createTempSync();
142-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
142+
addTearDown(() {
143+
Directory.current = cwd;
144+
tempDirectory.deleteSync(recursive: true);
145+
});
143146

144147
Directory.current = tempDirectory.path;
145148
final result = await commandRunner.run(['test']);
@@ -154,7 +157,10 @@ void main() {
154157
'completes normally when no pubspec.yaml exists (recursive)',
155158
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
156159
final tempDirectory = Directory.systemTemp.createTempSync();
157-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
160+
addTearDown(() {
161+
Directory.current = cwd;
162+
tempDirectory.deleteSync(recursive: true);
163+
});
158164

159165
Directory.current = tempDirectory.path;
160166

0 commit comments

Comments
 (0)