diff --git a/engine/src/flutter/flutter_frontend_server/pubspec.yaml b/engine/src/flutter/flutter_frontend_server/pubspec.yaml index e871ad59ab..3cb88d8a9a 100644 --- a/engine/src/flutter/flutter_frontend_server/pubspec.yaml +++ b/engine/src/flutter/flutter_frontend_server/pubspec.yaml @@ -13,5 +13,6 @@ environment: resolution: workspace dev_dependencies: - litetest: any + engine_repo_tools: any path: any + test: any diff --git a/engine/src/flutter/flutter_frontend_server/test/to_string_test.dart b/engine/src/flutter/flutter_frontend_server/test/to_string_test.dart index 2cd8935949..92a0a2a554 100644 --- a/engine/src/flutter/flutter_frontend_server/test/to_string_test.dart +++ b/engine/src/flutter/flutter_frontend_server/test/to_string_test.dart @@ -2,41 +2,55 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io'; +import 'dart:io' as io; -import 'package:litetest/litetest.dart'; +import 'package:engine_repo_tools/engine_repo_tools.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; -Future main(List args) async { - if (args.length != 3) { - stderr.writeln('The first argument must be the path to the build output.'); - stderr.writeln('The second argument must be the path to the frontend server dill.'); - stderr.writeln('The third argument must be the path to the flutter_patched_sdk'); - exit(-1); +void main() { + final engine = Engine.findWithin(); + final manualBuildDir = io.Platform.environment['ENGINE_BUILD_DIR']; + final buildDir = manualBuildDir ?? engine.latestOutput()?.path.path; + if (buildDir == null) { + fail('No build directory found. Set ENGINE_BUILD_DIR'); } + final frontendServer = path.join( + buildDir, + 'gen', + 'frontend_server_aot.dart.snapshot', + ); + final sdkRoot = path.join( + buildDir, + 'flutter_patched_sdk', + ); - final String dart = Platform.resolvedExecutable; - final String dartaotruntime = path.join(path.dirname(Platform.resolvedExecutable), 'dartaotruntime'); - 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.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'); - final String regularDill = path.join(fixtures, 'toString.dill'); - final String transformedDill = path.join(fixtures, 'toStringTransformed.dill'); + final String dart = io.Platform.resolvedExecutable; + final String dartaotruntime = path.join( + path.dirname(io.Platform.resolvedExecutable), + 'dartaotruntime', + ); - void checkProcessResult(ProcessResult result) { - if (result.exitCode != 0) { - stdout.writeln(result.stdout); - stderr.writeln(result.stderr); - } + final engineDir = engine.flutterDir.path; + final basePath = path.join(engineDir, 'flutter_frontend_server'); + final fixtures = path.join(basePath, 'test', 'fixtures'); + final mainDart = path.join(fixtures, 'lib', 'main.dart'); + final packageConfig = path.join( + fixtures, + '.dart_tool', + 'package_config.json', + ); + final regularDill = path.join(fixtures, 'toString.dill'); + final transformedDill = path.join(fixtures, 'toStringTransformed.dill'); + + void checkProcessResult(io.ProcessResult result) { + printOnFailure(result.stdout.toString()); + printOnFailure(result.stderr.toString()); expect(result.exitCode, 0); } test('Without flag', () { - checkProcessResult(Process.runSync(dartaotruntime, [ + checkProcessResult(io.Process.runSync(dartaotruntime, [ frontendServer, '--sdk-root=$sdkRoot', '--target=flutter', @@ -44,40 +58,42 @@ Future main(List args) async { '--output-dill=$regularDill', mainDart, ])); - final ProcessResult runResult = Process.runSync(dart, [regularDill]); + final runResult = io.Process.runSync(dart, [regularDill]); checkProcessResult(runResult); - String paintString = '"Paint.toString":"Paint(Color(0xffffffff))"'; + var paintString = '"Paint.toString":"Paint(Color(0xffffffff))"'; if (buildDir.contains('release')) { paintString = '"Paint.toString":"Instance of \'Paint\'"'; } final String expectedStdout = '{$paintString,' - '"Brightness.toString":"Brightness.dark",' - '"Foo.toString":"I am a Foo",' - '"Keep.toString":"I am a Keep"}'; + '"Brightness.toString":"Brightness.dark",' + '"Foo.toString":"I am a Foo",' + '"Keep.toString":"I am a Keep"}'; final String actualStdout = (runResult.stdout as String).trim(); expect(actualStdout, equals(expectedStdout)); }); test('With flag', () { - checkProcessResult(Process.runSync(dartaotruntime, [ + checkProcessResult(io.Process.runSync(dartaotruntime, [ frontendServer, '--sdk-root=$sdkRoot', '--target=flutter', '--packages=$packageConfig', '--output-dill=$transformedDill', - '--delete-tostring-package-uri', 'dart:ui', - '--delete-tostring-package-uri', 'package:flutter_frontend_fixtures', + '--delete-tostring-package-uri', + 'dart:ui', + '--delete-tostring-package-uri', + 'package:flutter_frontend_fixtures', mainDart, ])); - final ProcessResult runResult = Process.runSync(dart, [transformedDill]); + final runResult = io.Process.runSync(dart, [transformedDill]); checkProcessResult(runResult); - const String expectedStdout = '{"Paint.toString":"Instance of \'Paint\'",' - '"Brightness.toString":"Brightness.dark",' - '"Foo.toString":"Instance of \'Foo\'",' - '"Keep.toString":"I am a Keep"}'; - final String actualStdout = (runResult.stdout as String).trim(); + const expectedStdout = '{"Paint.toString":"Instance of \'Paint\'",' + '"Brightness.toString":"Brightness.dark",' + '"Foo.toString":"Instance of \'Foo\'",' + '"Keep.toString":"I am a Keep"}'; + final actualStdout = (runResult.stdout as String).trim(); expect(actualStdout, equals(expectedStdout)); }); } diff --git a/engine/src/flutter/testing/run_tests.py b/engine/src/flutter/testing/run_tests.py index 6bc49aaf6f..f70a72c66f 100755 --- a/engine/src/flutter/testing/run_tests.py +++ b/engine/src/flutter/testing/run_tests.py @@ -917,16 +917,23 @@ def gather_dart_smoke_test(build_dir, test_filter): def gather_dart_package_tests(build_dir, package_path, extra_opts): if uses_package_test_runner(package_path): - # Package that use package:test (dart test) do not support command-line arguments. - # - # The usual workaround is to use Platform.environment, but that would require changing - # the test execution a tiny bit. TODO(https://github.com/flutter/flutter/issues/133569). - # - # Until then, assert that no extra_opts are passed and explain the limitation. - assert not extra_opts, '%s uses package:test and cannot use CLI args' % package_path + # Assert that extra_opts is either None, or is an empty list, or is a dictionary. + assert len(extra_opts) == 0 or isinstance( + extra_opts, dict + ), '%s uses package:test and expects a dictionary, but passed a %s' % ( + package_path, type(extra_opts) + ) + extra_env = {} + if isinstance(extra_opts, dict): + extra_env = extra_opts opts = ['test', '--reporter=expanded'] yield EngineExecutableTask( - build_dir, os.path.join('dart-sdk', 'bin', 'dart'), None, flags=opts, cwd=package_path + build_dir, + os.path.join('dart-sdk', 'bin', 'dart'), + None, + flags=opts, + cwd=package_path, + extra_env=extra_env ) else: dart_tests = glob.glob('%s/test/*_test.dart' % package_path) @@ -971,14 +978,7 @@ def uses_package_test_runner(package): def build_dart_host_test_list(build_dir): dart_host_tests = [ (os.path.join('flutter', 'ci'), []), - ( - os.path.join('flutter', 'flutter_frontend_server'), - [ - build_dir, - os.path.join(build_dir, 'gen', 'frontend_server_aot.dart.snapshot'), - os.path.join(build_dir, 'flutter_patched_sdk') - ], - ), + (os.path.join('flutter', 'flutter_frontend_server'), {'ENGINE_BUILD_DIR': build_dir}), (os.path.join('flutter', 'testing', 'litetest'), []), (os.path.join('flutter', 'testing', 'skia_gold_client'), []), (os.path.join('flutter', 'testing', 'scenario_app'), []),