From c985237b0c8bccd82f42c57993aa455c3b045edb Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Sat, 22 May 2021 11:09:38 -0700 Subject: [PATCH] Use package:litetest for flutter_frontend_server (flutter/engine#26341) --- .../flutter_frontend_server/pubspec.yaml | 18 ++- .../test/to_string_test.dart | 135 ++++++++---------- .../flutter_frontend_server/test/utils.dart | 39 ----- 3 files changed, 75 insertions(+), 117 deletions(-) delete mode 100644 engine/src/flutter/flutter_frontend_server/test/utils.dart diff --git a/engine/src/flutter/flutter_frontend_server/pubspec.yaml b/engine/src/flutter/flutter_frontend_server/pubspec.yaml index 330b3c6e3d5..be53c239da8 100644 --- a/engine/src/flutter/flutter_frontend_server/pubspec.yaml +++ b/engine/src/flutter/flutter_frontend_server/pubspec.yaml @@ -1,3 +1,7 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + name: flutter_frontend_server publish_to: none version: 0.1.1-dev @@ -6,8 +10,9 @@ homepage: https://flutter.dev author: Flutter Authors # Do not add any dependencies that require more than what is provided in -# //third_party/dart/pkg or //third_party/dart/third_party/pkg. -# In particular, package:test is not usable here. +# //third_party/pkg, //third_party/dart/pkg or +# //third_party/dart/third_party/pkg. In particular, package:test is not usable +# here. # If you do add packages here, make sure you can run `pub get --offline`, and # check the .packages and .package_config to make sure all the paths are @@ -35,6 +40,9 @@ dependencies: usage: any vm: any +dev_dependencies: + litetest: any + dependency_overrides: _fe_analyzer_shared: path: ../../third_party/dart/pkg/_fe_analyzer_shared @@ -44,6 +52,8 @@ dependency_overrides: path: ../../third_party/dart/third_party/pkg/args async: path: ../../third_party/dart/third_party/pkg/async + async_helper: + path: ../../third_party/dart/pkg/async_helper bazel_worker: path: ../../third_party/dart/third_party/pkg/bazel_worker build_integration: @@ -60,6 +70,8 @@ dependency_overrides: path: ../../third_party/dart/third_party/pkg/crypto dev_compiler: path: ../../third_party/dart/pkg/dev_compiler + expect: + path: ../../third_party/dart/pkg/expect fixnum: path: ../../third_party/dart/third_party/pkg/fixnum front_end: @@ -68,6 +80,8 @@ dependency_overrides: path: ../../third_party/dart/pkg/frontend_server kernel: path: ../../third_party/dart/pkg/kernel + litetest: + path: ../testing/litetest logging: path: ../../third_party/dart/third_party/pkg/logging matcher: 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 ad7e6fc2322..b42f86fcd07 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 @@ -4,10 +4,9 @@ import 'dart:io'; +import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; -import 'utils.dart'; - Future main(List args) async { if (args.length != 2) { stderr.writeln('The first argument must be the path to the frontend server dill.'); @@ -15,84 +14,68 @@ Future main(List args) async { exit(-1); } - group('Integration tests', () { - final String dart = Platform.resolvedExecutable; - final String frontendServer = args[0]; - final String sdkRoot = args[1]; - final String basePath = path.canonicalize(path.join(path.dirname(Platform.script.path), '..')); - 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 = Platform.resolvedExecutable; + final String frontendServer = args[0]; + final String sdkRoot = args[1]; + final String basePath = path.canonicalize(path.join(path.dirname(Platform.script.path), '..')); + 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'); - void _checkProcessResult(ProcessResult result) { - if (result.exitCode != 0) { - stdout.writeln(result.stdout); - stderr.writeln(result.stderr); - } - expect(result.exitCode == 0, 'Expected result.exitCode to be 0'); + void _checkProcessResult(ProcessResult result) { + if (result.exitCode != 0) { + stdout.writeln(result.stdout); + stderr.writeln(result.stderr); + } + expect(result.exitCode, 0); + } + + test('Without flag', () { + _checkProcessResult(Process.runSync(dart, [ + frontendServer, + '--sdk-root=$sdkRoot', + '--target=flutter', + '--packages=$packageConfig', + '--output-dill=$regularDill', + mainDart, + ])); + final ProcessResult runResult = Process.runSync(dart, [regularDill]); + _checkProcessResult(runResult); + String paintString = '"Paint.toString":"Paint(Color(0xffffffff))"'; + if (const bool.fromEnvironment('dart.vm.product', defaultValue: false)) { + paintString = '"Paint.toString":"Instance of \'Paint\'"'; } - test('Without flag', () { - _checkProcessResult(Process.runSync(dart, [ - frontendServer, - '--sdk-root=$sdkRoot', - '--target=flutter', - '--packages=$packageConfig', - '--output-dill=$regularDill', - mainDart, - ])); - final ProcessResult runResult = Process.runSync(dart, [regularDill]); - _checkProcessResult(runResult); - String paintString = '"Paint.toString":"Paint(Color(0xffffffff))"'; - if (const bool.fromEnvironment('dart.vm.product', defaultValue: false)) { - 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"}'; - final String actualStdout = runResult.stdout.trim() as String; - expect( - actualStdout == expectedStdout, - 'Expected "$expectedStdout" but got "$actualStdout"', - ); - }); - - test('With flag', () { - _checkProcessResult(Process.runSync(dart, [ - 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', - mainDart, - ])); - final ProcessResult runResult = 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.trim() as String; - expect( - actualStdout == expectedStdout, - 'Expected "$expectedStdout" but got "$actualStdout"', - ); - }); + final String expectedStdout = '{$paintString,' + '"Brightness.toString":"Brightness.dark",' + '"Foo.toString":"I am a Foo",' + '"Keep.toString":"I am a Keep"}'; + final String actualStdout = runResult.stdout.trim() as String; + expect(actualStdout, equals(expectedStdout)); }); - if (TestFailure.testFailures == 0) { - print('All tests passed!'); - exit(0); - } else { - print('${TestFailure.testFailures} test expectations failed'); - exit(1); - } + test('With flag', () { + _checkProcessResult(Process.runSync(dart, [ + 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', + mainDart, + ])); + final ProcessResult runResult = 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.trim() as String; + expect(actualStdout, equals(expectedStdout)); + }); } diff --git a/engine/src/flutter/flutter_frontend_server/test/utils.dart b/engine/src/flutter/flutter_frontend_server/test/utils.dart deleted file mode 100644 index cb5fc743b44..00000000000 --- a/engine/src/flutter/flutter_frontend_server/test/utils.dart +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:io'; - -class TestFailure implements Exception { - TestFailure(this.message) { - testFailures++; - } - - static int testFailures = 0; - - final String message; - - @override - String toString() => 'TestFailure("$message")'; -} - -void expect(bool b, String message) { - if (!b) { - throw TestFailure(message); - } -} - -void test(String name, void Function() fn) { - stdout.write('Running $name: '); - try { - fn(); - stdout.writeln('Passed'); - } on TestFailure catch (e, st) { - stdout.writeln('Failed\n$e\n$st'); - } -} - -void group(String name, void Function() fn) { - print('Running group $name'); - fn(); -}