Skip to content

Commit

Permalink
Use package:litetest for flutter_frontend_server (flutter#26341)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanderso authored May 22, 2021
1 parent df1adb3 commit c5195ea
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 115 deletions.
18 changes: 16 additions & 2 deletions flutter_frontend_server/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -6,8 +10,9 @@ homepage: https://flutter.dev
author: Flutter Authors <[email protected]>

# 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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
131 changes: 57 additions & 74 deletions flutter_frontend_server/test/to_string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,78 @@

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.');
stderr.writeln('The second argument must be the path to the flutter_patched_sdk');
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"',
);
});
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));
});

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);
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"',
);
});
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));
});

if (TestFailure.testFailures == 0) {
print('All tests passed!');
exit(0);
} else {
print('${TestFailure.testFailures} test expectations failed');
exit(1);
}
}
39 changes: 0 additions & 39 deletions flutter_frontend_server/test/utils.dart

This file was deleted.

0 comments on commit c5195ea

Please sign in to comment.