Unverified Commit cd57af14 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Tests that module/plugin/package templates can be migrated to null-safety (#74090)

parent a0be9802
......@@ -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 = await _createProject(tempDir);
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=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)));
/// 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,
_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,
_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,
_flutterBin,
'analyze',
], workingDirectory: fileSystem.path.join(tempDir.path, 'foo'));
if (analyzeResult.exitCode != 0) {
fail('flutter analyze had errors: ${analyzeResult.stdout}${analyzeResult.stderr}');
}
} finally {
tempDir?.deleteSync(recursive: true);
}
});
}
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');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment