Use package:litetest for flutter_frontend_server (flutter/engine#26341)

This commit is contained in:
Zachary Anderson 2021-05-22 11:09:38 -07:00 committed by GitHub
parent 263c0a9cf9
commit c985237b0c
3 changed files with 75 additions and 117 deletions

View File

@ -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 <flutter-dev@googlegroups.com>
# 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:

View File

@ -4,10 +4,9 @@
import 'dart:io';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
import 'utils.dart';
Future<void> main(List<String> 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<void> main(List<String> 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, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
'--packages=$packageConfig',
'--output-dill=$regularDill',
mainDart,
]));
final ProcessResult runResult = Process.runSync(dart, <String>[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, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
'--packages=$packageConfig',
'--output-dill=$regularDill',
mainDart,
]));
final ProcessResult runResult = Process.runSync(dart, <String>[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, <String>[
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, <String>[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, <String>[
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, <String>[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));
});
}

View File

@ -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();
}