Fix tests on the Windows platform (flutter/engine#34350)

Addresses https://github.com/flutter/flutter/issues/36301
This commit is contained in:
Márk Tolmács 2022-07-11 20:01:05 +02:00 committed by GitHub
parent 0136679fb8
commit c85e3529b1
8 changed files with 100 additions and 67 deletions

View File

@ -19,7 +19,7 @@ Future<void> main(List<String> args) async {
final String buildDir = args[0];
final String frontendServer = args[1];
final String sdkRoot = args[2];
final String basePath = path.canonicalize(path.join(path.dirname(Platform.script.path), '..'));
final String basePath = path.canonicalize(path.join(path.dirname(Platform.script.toFilePath()), '..'));
final String fixtures = path.join(basePath, 'test', 'fixtures');
final String mainDart = path.join(fixtures, 'lib', 'main.dart');
final String packageConfig = path.join(fixtures, '.dart_tool', 'package_config.json');

View File

@ -41,7 +41,8 @@ int main(int argc, const char* argv[]) {
}
std::fstream output;
output.open(argv[2], std::fstream::out | std::fstream::trunc);
output.open(argv[2],
std::fstream::out | std::fstream::trunc | std::fstream::binary);
if (!output.is_open()) {
output.close();
std::cerr << "failed to open output file" << std::endl;

View File

@ -27,6 +27,10 @@
#include "third_party/dart/runtime/include/bin/dart_io_api.h"
#include "third_party/dart/runtime/include/dart_api.h"
#if defined(FML_OS_WIN)
#include <combaseapi.h>
#endif // defined(FML_OS_WIN)
#if defined(FML_OS_POSIX)
#include <signal.h>
#endif // defined(FML_OS_POSIX)
@ -414,6 +418,10 @@ int main(int argc, char* argv[]) {
return true;
};
#if defined(FML_OS_WIN)
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
#endif // defined(FML_OS_WIN)
return flutter::RunTester(settings,
command_line.HasOption(flutter::FlagForSwitch(
flutter::Switch::RunForever)),

View File

@ -112,3 +112,24 @@ Matcher startsWith(String s) => (dynamic d) {
Expect.fail('Expected "$h" to start with "$s"');
}
};
/// Gives a matcher that asserts that the value being matched is a [String] that
/// ends with `s`.
Matcher endsWith(String s) => (dynamic d) {
expect(d, isInstanceOf<String>());
final String h = d as String;
if (!h.endsWith(s)) {
Expect.fail('Expected "$h" to end with "$s"');
}
};
/// Gives a matcher that asserts that the value being matched is a [String] that
/// regexp matches with `pattern`.
Matcher hasMatch(String pattern) => (dynamic d) {
expect(d, isInstanceOf<String>());
final String h = d as String;
final RegExp regExp = RegExp(pattern);
if (!regExp.hasMatch(h)) {
Expect.fail('Expected "$h" to match with "$pattern"');
}
};

View File

@ -1049,8 +1049,6 @@ def main():
)
if 'dart' in types:
assert not IsWindows(
), "Dart tests can't be run on windows. https://github.com/flutter/flutter/issues/36301."
dart_filter = args.dart_filter.split(',') if args.dart_filter else None
tasks = list(GatherDartSmokeTest(build_dir, args.verbose_dart_snapshot))
tasks += list(GatherLitetestTests(build_dir))

View File

@ -8,6 +8,7 @@ import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:apicheck/apicheck.dart';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
main(List<String> arguments) {
if (arguments.length < 1) {
@ -38,27 +39,28 @@ main(List<String> arguments) {
checkApiConsistency(String flutterRoot) {
test('AccessibilityFeatures enums match', () {
// Dart values: _kFooBarIndex = 1 << N
List<String> uiFields = getDartClassFields(
sourcePath:'$flutterRoot/lib/ui/window.dart',
className:'AccessibilityFeatures',
final List<String> uiFields = getDartClassFields(
sourcePath: path.join(flutterRoot, 'lib', 'ui', 'window.dart'),
className: 'AccessibilityFeatures',
);
List<String> webuiFields = getDartClassFields(
sourcePath:'$flutterRoot/lib/ui/window.dart',
className:'AccessibilityFeatures',
final List<String> webuiFields = getDartClassFields(
sourcePath: path.join(flutterRoot, 'lib', 'ui', 'window.dart'),
className: 'AccessibilityFeatures',
);
// C values: kFlutterAccessibilityFeatureFooBar = 1 << N,
List<String> embedderEnumValues = getCppEnumValues(
sourcePath: '$flutterRoot/shell/platform/embedder/embedder.h',
final List<String> embedderEnumValues = getCppEnumValues(
sourcePath: path.join(flutterRoot, 'shell', 'platform', 'embedder', 'embedder.h'),
enumName: 'FlutterAccessibilityFeature',
);
// C++ values: kFooBar = 1 << N,
List<String> internalEnumValues = getCppEnumClassValues(
sourcePath: '$flutterRoot/lib/ui/window/platform_configuration.h',
final List<String> internalEnumValues = getCppEnumClassValues(
sourcePath: path.join(flutterRoot, 'lib','ui', 'window', 'platform_configuration.h'),
enumName: 'AccessibilityFeatureFlag',
);
// Java values: FOO_BAR(1 << N).
List<String> javaEnumValues = getJavaEnumValues(
sourcePath: '$flutterRoot/shell/platform/android/io/flutter/view/AccessibilityBridge.java',
final List<String> javaEnumValues = getJavaEnumValues(
sourcePath: path.join(flutterRoot, 'shell', 'platform', 'android', 'io',
'flutter', 'view', 'AccessibilityBridge.java'),
enumName: 'AccessibilityFeature',
).map(allCapsToCamelCase).toList();
@ -70,27 +72,28 @@ checkApiConsistency(String flutterRoot) {
test('SemanticsAction enums match', () {
// Dart values: _kFooBarIndex = 1 << N.
List<String> uiFields = getDartClassFields(
sourcePath:'$flutterRoot/lib/ui/semantics.dart',
className:'SemanticsAction',
final List<String> uiFields = getDartClassFields(
sourcePath: path.join(flutterRoot, 'lib', 'ui', 'semantics.dart'),
className: 'SemanticsAction',
);
List<String> webuiFields = getDartClassFields(
sourcePath:'$flutterRoot/lib/ui/semantics.dart',
className:'SemanticsAction',
final List<String> webuiFields = getDartClassFields(
sourcePath: path.join(flutterRoot, 'lib', 'ui', 'semantics.dart'),
className: 'SemanticsAction',
);
// C values: kFlutterSemanticsActionFooBar = 1 << N.
List<String> embedderEnumValues = getCppEnumValues(
sourcePath: '$flutterRoot/shell/platform/embedder/embedder.h',
final List<String> embedderEnumValues = getCppEnumValues(
sourcePath: path.join(flutterRoot, 'shell', 'platform', 'embedder', 'embedder.h'),
enumName: 'FlutterSemanticsAction',
);
// C++ values: kFooBar = 1 << N.
List<String> internalEnumValues = getCppEnumClassValues(
sourcePath: '$flutterRoot/lib/ui/semantics/semantics_node.h',
final List<String> internalEnumValues = getCppEnumClassValues(
sourcePath: path.join(flutterRoot, 'lib', 'ui', 'semantics', 'semantics_node.h'),
enumName: 'SemanticsAction',
);
// Java values: FOO_BAR(1 << N).
List<String> javaEnumValues = getJavaEnumValues(
sourcePath: '$flutterRoot/shell/platform/android/io/flutter/view/AccessibilityBridge.java',
final List<String> javaEnumValues = getJavaEnumValues(
sourcePath: path.join(flutterRoot, 'shell', 'platform', 'android', 'io',
'flutter', 'view', 'AccessibilityBridge.java'),
enumName: 'Action',
).map(allCapsToCamelCase).toList();
@ -102,27 +105,28 @@ checkApiConsistency(String flutterRoot) {
test('SemanticsFlag enums match', () {
// Dart values: _kFooBarIndex = 1 << N.
List<String> uiFields = getDartClassFields(
sourcePath:'$flutterRoot/lib/ui/semantics.dart',
className:'SemanticsFlag',
final List<String> uiFields = getDartClassFields(
sourcePath: path.join(flutterRoot, 'lib', 'ui', 'semantics.dart'),
className: 'SemanticsFlag',
);
List<String> webuiFields = getDartClassFields(
sourcePath:'$flutterRoot/lib/ui/semantics.dart',
className:'SemanticsFlag',
final List<String> webuiFields = getDartClassFields(
sourcePath: path.join(flutterRoot, 'lib', 'ui', 'semantics.dart'),
className: 'SemanticsFlag',
);
// C values: kFlutterSemanticsFlagFooBar = 1 << N.
List<String> embedderEnumValues = getCppEnumValues(
sourcePath: '$flutterRoot/shell/platform/embedder/embedder.h',
final List<String> embedderEnumValues = getCppEnumValues(
sourcePath: path.join(flutterRoot, 'shell', 'platform', 'embedder', 'embedder.h'),
enumName: 'FlutterSemanticsFlag',
);
// C++ values: kFooBar = 1 << N.
List<String> internalEnumValues = getCppEnumClassValues(
sourcePath: '$flutterRoot/lib/ui/semantics/semantics_node.h',
final List<String> internalEnumValues = getCppEnumClassValues(
sourcePath: path.join(flutterRoot, 'lib', 'ui', 'semantics', 'semantics_node.h'),
enumName: 'SemanticsFlags',
);
// Java values: FOO_BAR(1 << N).
List<String> javaEnumValues = getJavaEnumValues(
sourcePath: '$flutterRoot/shell/platform/android/io/flutter/view/AccessibilityBridge.java',
final List<String> javaEnumValues = getJavaEnumValues(
sourcePath: path.join(flutterRoot, 'shell', 'platform', 'android', 'io',
'flutter', 'view', 'AccessibilityBridge.java'),
enumName: 'Flag',
).map(allCapsToCamelCase).toList();

View File

@ -98,8 +98,8 @@ Future<int> main(List<String> args) async {
expect(clangTidy.options.help, isFalse);
expect(result, equals(1));
expect(errBuffer.toString(), contains(
"ERROR: Build commands path /does/not/exist doesn't exist.",
expect(errBuffer.toString().split('\n')[0], hasMatch(
r"ERROR: Build commands path .*/does/not/exist doesn't exist.",
));
});
@ -121,8 +121,10 @@ Future<int> main(List<String> args) async {
expect(clangTidy.options.help, isFalse);
expect(result, equals(1));
expect(errBuffer.toString(), contains(
"ERROR: Build commands path /does/not/exist/out/ios_debug_unopt/compile_commands.json doesn't exist.",
expect(errBuffer.toString().split('\n')[0], hasMatch(
r'ERROR: Build commands path .*/does/not/exist'
r'[/\\]out[/\\]ios_debug_unopt[/\\]compile_commands.json'
r" doesn't exist.",
));
});
@ -187,7 +189,7 @@ Future<int> main(List<String> args) async {
);
// This file needs to exist, and be UTF8 line-parsable.
final String filePath = io.Platform.script.path;
final String filePath = io.Platform.script.toFilePath();
final List<dynamic> buildCommandsData = <Map<String, dynamic>>[
<String, dynamic>{
'directory': '/unused',
@ -204,24 +206,20 @@ Future<int> main(List<String> args) async {
final Command command = commands.first;
expect(command.tidyPath, contains('clang/bin/clang-tidy'));
final WorkerJob jobNoFix = command.createLintJob(null, false);
expect(jobNoFix.command, <String>[
'../../buildtools/mac-x64/clang/bin/clang-tidy',
filePath,
'--',
'',
filePath,
]);
expect(jobNoFix.command[0], endsWith('../../buildtools/mac-x64/clang/bin/clang-tidy'));
expect(jobNoFix.command[1], endsWith(filePath.replaceAll('/', io.Platform.pathSeparator)));
expect(jobNoFix.command[2], '--');
expect(jobNoFix.command[3], '');
expect(jobNoFix.command[4], endsWith(filePath));
final WorkerJob jobWithFix = command.createLintJob(null, true);
expect(jobWithFix.command, <String>[
'../../buildtools/mac-x64/clang/bin/clang-tidy',
filePath,
'--fix',
'--format-style=file',
'--',
'',
filePath,
]);
expect(jobWithFix.command[0], endsWith('../../buildtools/mac-x64/clang/bin/clang-tidy'));
expect(jobWithFix.command[1], endsWith(filePath.replaceAll('/', io.Platform.pathSeparator)));
expect(jobWithFix.command[2], '--fix');
expect(jobWithFix.command[3], '--format-style=file');
expect(jobWithFix.command[4], '--');
expect(jobWithFix.command[5], '');
expect(jobWithFix.command[6], endsWith(filePath));
});
test('Command getLintAction flags third_party files', () async {

View File

@ -34,7 +34,7 @@ void expectInstances(dynamic value, dynamic expected) {
}
final String basePath =
path.canonicalize(path.join(path.dirname(Platform.script.path), '..'));
path.canonicalize(path.join(path.dirname(Platform.script.toFilePath()), '..'));
final String fixtures = path.join(basePath, 'test', 'fixtures');
final String box = path.join(fixtures, 'lib', 'box.dart');
final String consts = path.join(fixtures, 'lib', 'consts.dart');
@ -119,6 +119,9 @@ void _checkNonConsts() {
classLibraryUri: 'package:const_finder_fixtures/target.dart',
className: 'Target',
);
final String fixturesUrl = Platform.isWindows
? '/$fixtures'.replaceAll(Platform.pathSeparator, '/')
: fixtures;
expectInstances(
finder.findInstances(),
@ -134,27 +137,27 @@ void _checkNonConsts() {
],
'nonConstantLocations': <dynamic>[
<String, dynamic>{
'file': 'file://$fixtures/lib/consts_and_non.dart',
'file': 'file://$fixturesUrl/lib/consts_and_non.dart',
'line': 14,
'column': 26,
},
<String, dynamic>{
'file': 'file://$fixtures/lib/consts_and_non.dart',
'file': 'file://$fixturesUrl/lib/consts_and_non.dart',
'line': 16,
'column': 26,
},
<String, dynamic>{
'file': 'file://$fixtures/lib/consts_and_non.dart',
'file': 'file://$fixturesUrl/lib/consts_and_non.dart',
'line': 16,
'column': 41,
},
<String, dynamic>{
'file': 'file://$fixtures/lib/consts_and_non.dart',
'file': 'file://$fixturesUrl/lib/consts_and_non.dart',
'line': 17,
'column': 26,
},
<String, dynamic>{
'file': 'file://$fixtures/pkg/package.dart',
'file': 'file://$fixturesUrl/pkg/package.dart',
'line': 14,
'column': 25,
}