Tests that module/plugin/package templates can be migrated to null-safety (#74090)
This commit is contained in:
committed by
GitHub
parent
a0be98020e
commit
cd57af1458
@@ -8,6 +8,5 @@ void main() {
|
||||
expect(calculator.addOne(2), 3);
|
||||
expect(calculator.addOne(-7), -6);
|
||||
expect(calculator.addOne(0), 1);
|
||||
expect(() => calculator.addOne(null), throwsNoSuchMethodError);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,43 +8,95 @@ import 'package:flutter_tools/src/base/io.dart';
|
||||
import '../src/common.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
/// Verifies that `dart migrate` will run successfully on the default `flutter create`
|
||||
/// template.
|
||||
void main() {
|
||||
/// Verifies that `dart migrate` will run successfully on the default `flutter create`
|
||||
/// template.
|
||||
testWithoutContext('dart migrate succeeds on flutter create template', () async {
|
||||
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'flutter.bat' : 'flutter');
|
||||
final String dartBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'dart.bat' : 'dart');
|
||||
|
||||
Directory tempDir;
|
||||
try {
|
||||
tempDir = createResolvedTempDirectorySync('dart_migrate_test.');
|
||||
final ProcessResult createResult = await processManager.run(<String>[
|
||||
flutterBin,
|
||||
'create',
|
||||
'foo',
|
||||
], workingDirectory: tempDir.path);
|
||||
if (createResult.exitCode != 0) {
|
||||
fail('flutter create did not work: ${createResult.stdout}${createResult.stderr}');
|
||||
}
|
||||
tempDir = await _createProject(tempDir);
|
||||
await _migrate(tempDir);
|
||||
await _analyze(tempDir);
|
||||
} finally {
|
||||
tempDir?.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
final ProcessResult migrateResult = await processManager.run(<String>[
|
||||
dartBin,
|
||||
'migrate',
|
||||
'--apply-changes',
|
||||
], workingDirectory: fileSystem.path.join(tempDir.path, 'foo'));
|
||||
if (migrateResult.exitCode != 0) {
|
||||
fail('dart migrate did not work: ${migrateResult.stdout}${migrateResult.stderr}');
|
||||
}
|
||||
/// Verifies that `dart migrate` will run successfully on the module template
|
||||
/// used by `flutter create --template=module`.
|
||||
testWithoutContext('dart migrate succeeds on module template', () async {
|
||||
Directory tempDir;
|
||||
try {
|
||||
tempDir = await _createProject(tempDir, <String>['--template=module']);
|
||||
await _migrate(tempDir);
|
||||
await _analyze(tempDir);
|
||||
} finally {
|
||||
tempDir?.deleteSync(recursive: true);
|
||||
}
|
||||
}, timeout: const Timeout(Duration(minutes: 1)));
|
||||
|
||||
final ProcessResult analyzeResult = await processManager.run(<String>[
|
||||
flutterBin,
|
||||
'analyze',
|
||||
], workingDirectory: fileSystem.path.join(tempDir.path, 'foo'));
|
||||
if (analyzeResult.exitCode != 0) {
|
||||
fail('flutter analyze had errors: ${analyzeResult.stdout}${analyzeResult.stderr}');
|
||||
}
|
||||
/// Verifies that `dart migrate` will run successfully on the module template
|
||||
/// used by `flutter create --template=plugin`.
|
||||
testWithoutContext('dart migrate succeeds on plugin template', () async {
|
||||
Directory tempDir;
|
||||
try {
|
||||
tempDir = await _createProject(tempDir, <String>['--template=plugin']);
|
||||
await _migrate(tempDir);
|
||||
await _analyze(tempDir);
|
||||
} finally {
|
||||
tempDir?.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
/// Verifies that `dart migrate` will run successfully on the module template
|
||||
/// used by `flutter create --template=package`.
|
||||
testWithoutContext('dart migrate succeeds on package template', () async {
|
||||
Directory tempDir;
|
||||
try {
|
||||
tempDir = await _createProject(tempDir, <String>['--template=package']);
|
||||
await _migrate(tempDir);
|
||||
await _analyze(tempDir);
|
||||
} finally {
|
||||
tempDir?.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<Directory> _createProject(Directory tempDir, [List<String> extraAgs]) async {
|
||||
tempDir = createResolvedTempDirectorySync('dart_migrate_test.');
|
||||
final ProcessResult createResult = await processManager.run(<String>[
|
||||
_flutterBin,
|
||||
'create',
|
||||
if (extraAgs != null)
|
||||
...extraAgs,
|
||||
'foo',
|
||||
], workingDirectory: tempDir.path);
|
||||
if (createResult.exitCode != 0) {
|
||||
fail('flutter create did not work: ${createResult.stdout}${createResult.stderr}');
|
||||
}
|
||||
return tempDir;
|
||||
}
|
||||
|
||||
Future<void> _migrate(Directory tempDir) async {
|
||||
final ProcessResult migrateResult = await processManager.run(<String>[
|
||||
_dartBin,
|
||||
'migrate',
|
||||
'--apply-changes',
|
||||
], workingDirectory: fileSystem.path.join(tempDir.path, 'foo'));
|
||||
if (migrateResult.exitCode != 0) {
|
||||
fail('dart migrate did not work: ${migrateResult.stdout}${migrateResult.stderr}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _analyze(Directory tempDir) async {
|
||||
final ProcessResult analyzeResult = await processManager.run(<String>[
|
||||
_flutterBin,
|
||||
'analyze',
|
||||
], workingDirectory: fileSystem.path.join(tempDir.path, 'foo'));
|
||||
if (analyzeResult.exitCode != 0) {
|
||||
fail('flutter analyze had errors: ${analyzeResult.stdout}${analyzeResult.stderr}');
|
||||
}
|
||||
}
|
||||
|
||||
String get _flutterBin => fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'flutter.bat' : 'flutter');
|
||||
String get _dartBin => fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'dart.bat' : 'dart');
|
||||
|
||||
Reference in New Issue
Block a user