Add more package:test (removing usages of package:litetest) (flutter/engine#54882)

... also removed a few TODOs, deleted a proof of concept directory.

Work towards https://github.com/flutter/flutter/issues/133569.
This commit is contained in:
Matan Lurey
2024-09-04 15:42:55 -07:00
committed by GitHub
parent 50158f1c62
commit d068ccc47d
23 changed files with 157 additions and 180 deletions

View File

@@ -87,7 +87,6 @@ workspace:
- testing/benchmark
- testing/dart
- testing/litetest
- testing/pkg_test_demo
- testing/scenario_app
- testing/skia_gold_client
- testing/smoke_test_failure
@@ -263,6 +262,8 @@ dependency_overrides:
path: ./third_party/dart/third_party/pkg/shelf/pkgs/shelf_static
shelf_web_socket:
path: ./third_party/dart/third_party/pkg/shelf/pkgs/shelf_web_socket
sky_engine:
path: ./sky/packages/sky_engine
smith:
path: ./third_party/dart/pkg/smith
source_map_stack_trace:

View File

@@ -1,32 +0,0 @@
# Demo of `package:test` with `DEPS`-vendored packages
Historically, `flutter/engine` used a homegrown test framework,
[`package:litetest`](../litetest/) to avoid depending on the unwieldy set of
dependencies that `package:test` brings in. However, `package:test` is now
vendored in `DEPS` (used by the Dart SDK).'
This demo shows that:
- It's possible to use `package:test` with entirely local dependencies.
- The functionality of `package:test` (such as filtering, IDE integration, etc.)
is available.
See <https://github.com/flutter/flutter/issues/133569> for details.
## Usage
Navigate to this directory:
```sh
cd testing/pkg_test_demo
```
And run the tests using `dart test`[^1]:
```sh
dart test
```
[^1]:
In practice, you'll want to use the `dart` binary that is vendored in the
pre-built SDK.

View File

@@ -1,16 +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.
name: pkg_test_demo
publish_to: none
# Required for workspace support.
environment:
sdk: ^3.5.0-294.0.dev
# This package is managed as part of the engine workspace.
resolution: workspace
dev_dependencies:
test: any

View File

@@ -1,17 +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 'package:test/test.dart';
void main() {
test('String.split() splits the string on the delimiter', () {
const String string = 'foo,bar,baz';
expect(string.split(','), equals(<String>['foo', 'bar', 'baz']));
});
test('String.trim() removes surrounding whitespace', () {
const String string = ' foo ';
expect(string.trim(), equals('foo'));
});
}

View File

@@ -124,7 +124,9 @@ def run_cmd( # pylint: disable=too-many-arguments
allowed_failure = True
if not allowed_failure:
raise RuntimeError('Command "%s" exited with code %s.' % (command_string, process.returncode))
raise RuntimeError(
'Command "%s" (in %s) exited with code %s.' % (command_string, cwd, process.returncode)
)
for forbidden_string in forbidden_output:
if forbidden_string in output:
@@ -133,7 +135,10 @@ def run_cmd( # pylint: disable=too-many-arguments
)
print_divider('<')
logger.info('Command run successfully in %.2f seconds: %s', end_time - start_time, command_string)
logger.info(
'Command run successfully in %.2f seconds: %s (in %s)', end_time - start_time, command_string,
cwd
)
def is_mac():
@@ -919,8 +924,7 @@ def gather_dart_package_tests(build_dir, package_path, extra_opts):
#
# 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
# TODO(https://github.com/flutter/flutter/issues/154263): Restore `--disable-dart-dev`.
opts = ['test']
opts = ['test', '--reporter=expanded']
yield EngineExecutableTask(
build_dir, os.path.join('dart-sdk', 'bin', 'dart'), None, flags=opts, cwd=package_path
)
@@ -976,7 +980,6 @@ def build_dart_host_test_list(build_dir):
],
),
(os.path.join('flutter', 'testing', 'litetest'), []),
(os.path.join('flutter', 'testing', 'pkg_test_demo'), []),
(os.path.join('flutter', 'testing', 'skia_gold_client'), []),
(os.path.join('flutter', 'testing', 'scenario_app'), []),
(

View File

@@ -24,9 +24,4 @@ dependencies:
sky_engine: any
dev_dependencies:
litetest: any
# TODO(matanlurey): Figure out how sky_engine fits into the pub workspace model.
dependency_overrides:
sky_engine:
path: ../../sky/packages/sky_engine
test: any

View File

@@ -1,4 +1,4 @@
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
import '../bin/utils/adb_logcat_filtering.dart';
import 'src/fake_adb_logcat.dart';

View File

@@ -189,10 +189,6 @@ interface class SkiaGoldClient {
/// The path to the local [Directory] where the `goldctl` tool is hosted.
String get _goldctl {
assert(
isAvailable(environment: _environment),
'Trying to use `goldctl` in an environment where it is not available',
);
final String? result = _environment[_kGoldctlKey];
if (result == null || result.isEmpty) {
throw StateError('The environment variable $_kGoldctlKey is not set.');

View File

@@ -22,5 +22,5 @@ dependencies:
process: any
dev_dependencies:
litetest: any
process_fakes: any
test: any

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:litetest/litetest.dart';
import 'package:skia_gold_client/src/release_version.dart';
import 'package:test/test.dart';
void main() {
test('should accept a major and minor version', () {

View File

@@ -8,11 +8,11 @@ import 'dart:io' as io;
import 'dart:typed_data';
import 'package:engine_repo_tools/engine_repo_tools.dart';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as p;
import 'package:process_fakes/process_fakes.dart';
import 'package:skia_gold_client/skia_gold_client.dart';
import 'package:skia_gold_client/src/release_version.dart';
import 'package:test/test.dart';
void main() {
/// A mock commit hash that is used to simulate a successful git call.

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('test smoke test -- this test SHOULD FAIL', () {

View File

@@ -13,4 +13,4 @@ environment:
resolution: workspace
dependencies:
litetest: any
test: any

View File

@@ -10,7 +10,7 @@ import 'package:path/path.dart' as path;
import 'lint_target.dart';
final Engine _engineRoot = Engine.findWithin(path.dirname(path.fromUri(io.Platform.script)));
final Engine _engineRoot = Engine.findWithin();
/// Adds warnings as errors for only specific runs. This is helpful if migrating one platform at a time.
String? _platformSpecificWarningsAsErrors(ArgResults options) {

View File

@@ -22,9 +22,6 @@ dependencies:
process_runner: any
dev_dependencies:
async_helper: any
expect: any
litetest: any
process_fakes: any
smith: any
test: any
yaml: any

View File

@@ -10,12 +10,11 @@ import 'package:clang_tidy/src/command.dart';
import 'package:clang_tidy/src/lint_target.dart';
import 'package:clang_tidy/src/options.dart';
import 'package:engine_repo_tools/engine_repo_tools.dart';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
import 'package:process/process.dart';
import 'package:process_fakes/process_fakes.dart';
import 'package:process_runner/process_runner.dart';
import 'package:test/test.dart';
/// A test fixture for the `clang-tidy` tool.
final class Fixture {
@@ -94,8 +93,7 @@ Use -header-filter=.* to display errors from all non-system headers. Use -system
1 warning treated as error''';
void _withTempFile(String prefix, void Function(String path) func) {
final String filePath =
path.join(io.Directory.systemTemp.path, '$prefix-temp-file');
final String filePath = path.join(io.Directory.systemTemp.path, '$prefix-temp-file');
final io.File file = io.File(filePath);
file.createSync();
try {
@@ -105,16 +103,27 @@ void _withTempFile(String prefix, void Function(String path) func) {
}
}
Future<int> main(List<String> args) async {
final String? buildCommands =
args.firstOrNull ??
Engine.findWithin().latestOutput()?.compileCommandsJson.path;
final _engineRoot = Engine.findWithin();
if (buildCommands == null || args.length > 1) {
io.stderr.writeln(
'Usage: clang_tidy_test.dart [path/to/compile_commands.json]',
);
return 1;
void main() {
// This test requires a compile_commands.json file to exist.
//
// We can provide exactly which build to use, i.e.:
// COMPILE_COMMANDS_PATH=/path/to/compile_commands.json dart test
//
// Or, we can fall back to the latest build output if one isn't provided.
final String buildCommands;
if (io.Platform.environment['COMPILE_COMMANDS_PATH'] case final String compileCommandsPath) {
buildCommands = compileCommandsPath;
} else {
final String? inferredPath = _engineRoot.latestOutput()?.compileCommandsJson.path;
io.stderr.writeln('No COMPILE_COMMANDS_PATH found in environment.');
if (inferredPath != null) {
io.stderr.writeln('Inferring the last build output: $inferredPath');
buildCommands = inferredPath;
} else {
fail('No outputs or build commands found.');
}
}
test('--help gives help, and uses host_debug by default outside of an engine root', () async {
@@ -253,7 +262,7 @@ Future<int> main(List<String> args) async {
final int result = await fixture.tool.run();
expect(result, equals(1));
expect(fixture.errBuffer.toString().split('\n')[0], hasMatch(
expect(fixture.errBuffer.toString().split('\n')[0], matches(
r"ERROR: Build commands path .*/does/not/exist doesn't exist.",
));
});
@@ -270,7 +279,7 @@ Future<int> main(List<String> args) async {
final int result = await fixture.tool.run();
expect(result, equals(1));
expect(fixture.errBuffer.toString().split('\n')[0], hasMatch(
expect(fixture.errBuffer.toString().split('\n')[0], matches(
r'ERROR: Build commands path .*/does/not/exist'
r'[/\\]out[/\\]ios_debug_unopt[/\\]compile_commands.json'
r" doesn't exist.",
@@ -475,7 +484,13 @@ Future<int> main(List<String> args) async {
);
// This file needs to exist, and be UTF8 line-parsable.
final String filePath = io.Platform.script.toFilePath();
final String filePath = path.join(
_engineRoot.flutterDir.path,
'tools',
'clang_tidy',
'test',
'clang_tidy_test.dart',
);
final List<dynamic> buildCommandsData = <Map<String, dynamic>>[
<String, dynamic>{
'directory': '/unused',
@@ -657,6 +672,4 @@ Future<int> main(List<String> args) async {
expect(result, 0);
});
return 0;
}

View File

@@ -5,14 +5,14 @@
import 'dart:io';
import 'package:engine_repo_tools/engine_repo_tools.dart';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:yaml/yaml.dart' as yaml;
/// Tests that `HeaderFilterRegex` works as expected in `.clang_tidy`.
void main() {
// Find the root of the repo.
final Engine engine = Engine.findWithin(path.dirname(Platform.script.path));
final Engine engine = Engine.findWithin();
// Find the `.clang_tidy` file and "parse" it (it's YAML).
final yaml.YamlDocument dotClangTidy = yaml.loadYamlDocument(
@@ -62,11 +62,11 @@ void main() {
// Create a fake file in that path, and assert that it matches the regex.
for (final String rootDir in rootDirs) {
final String file = path.join('..', '..', 'flutter', rootDir, 'foo');
if (!regexValue.hasMatch(file)) {
// This is because reason: ... doesn't work in pkg/litetest.
stderr.writeln('Expected "$file" to be caught by HeaderFilterRegex (${regexValue.pattern}).');
}
expect(regexValue.hasMatch(file), isTrue);
expect(
file,
matches(regexValue),
reason: '$rootDir/foo should be allowed by the regex but was not.',
);
}
});
}

View File

@@ -19,4 +19,4 @@ dependencies:
skia_gold_client: any
dev_dependencies:
litetest: any
test: any

View File

@@ -6,8 +6,8 @@ import 'dart:async';
import 'dart:io' as io;
import 'package:golden_tests_harvester/golden_tests_harvester.dart';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
void main() async {
Future<void> withTempDirectory(
@@ -24,13 +24,20 @@ void main() async {
test('should fail on a missing directory', () async {
await withTempDirectory((io.Directory tempDirectory) async {
final StringSink stderr = StringBuffer();
final ArgumentError error = await _expectThrow<ArgumentError>(() async {
await Harvester.create(
expect(
() async {
await Harvester.create(
io.Directory(p.join(tempDirectory.path, 'non_existent')),
stderr,
addImageToSkiaGold: _alwaysThrowsAddImg);
});
expect(error.message, contains('non_existent'));
addImageToSkiaGold: _alwaysThrowsAddImg,
);
},
throwsA(isA<ArgumentError>().having(
(error) => error.message,
'message',
contains('non_existent'),
)),
);
expect(stderr.toString(), isEmpty);
});
});
@@ -39,14 +46,22 @@ void main() async {
() async {
await withTempDirectory((io.Directory tempDirectory) async {
final StringSink stderr = StringBuffer();
final StateError error = await _expectThrow<StateError>(() async {
await Harvester.create(
await expectLater(
() async {
await Harvester.create(
tempDirectory,
stderr,
addImageToSkiaGold: _alwaysThrowsAddImg);
});
expect(error.toString(), contains('digest.json'));
addImageToSkiaGold: _alwaysThrowsAddImg,
);
},
throwsA(
isA<StateError>().having(
(error) => error.toString(),
'toString()',
contains('digest.json'),
),
),
);
expect(stderr.toString(), isEmpty);
});
});
@@ -58,15 +73,22 @@ void main() async {
io.File(p.join(tempDirectory.path, 'digest.json'));
await digestsFile
.writeAsString('{"dimensions": "not a map", "entries": []}');
final FormatException error =
await _expectThrow<FormatException>(() async {
await Harvester.create(
await expectLater(
() async {
await Harvester.create(
tempDirectory,
stderr,
addImageToSkiaGold: _alwaysThrowsAddImg);
});
expect(error.message, contains('dimensions'));
addImageToSkiaGold: _alwaysThrowsAddImg,
);
},
throwsA(
isA<FormatException>().having(
(error) => error.message,
'message',
contains('dimensions'),
),
),
);
expect(stderr.toString(), isEmpty);
});
});
@@ -77,30 +99,37 @@ void main() async {
io.File(p.join(tempDirectory.path, 'digest.json'));
final StringSink stderr = StringBuffer();
await digestsFile.writeAsString('''
{
"dimensions": {},
"entries": [
{
"dimensions": {},
"entries": [
{
"filename": "test_name_1.png",
"width": 100,
"height": 100,
"maxDiffPixelsPercent": 0.01,
"maxColorDelta": 0
}
]
"filename": "test_name_1.png",
"width": 100,
"height": 100,
"maxDiffPixelsPercent": 0.01,
"maxColorDelta": 0
}
]
}
''');
final FailedComparisonException error =
await _expectThrow<FailedComparisonException>(() async {
final Harvester harvester = await Harvester.create(
tempDirectory,
stderr,
addImageToSkiaGold: _alwaysThrowsAddImg);
await harvest(harvester);
});
expect(error.testName, 'test_name_1.png');
expect(stderr.toString(), contains('IntentionalError'));
final Harvester harvester = await Harvester.create(
tempDirectory,
stderr,
addImageToSkiaGold: _alwaysThrowsAddImg,
);
expect(
() => harvest(harvester),
throwsA(
isA<FailedComparisonException>()
.having((e) => e.testName, 'testName', 'test_name_1.png')
.having(
(e) => e.toString(),
'toString()',
contains('Failed comparison: test_name_1.png'),
),
),
);
});
});
@@ -186,30 +215,21 @@ void main() async {
]}
''');
final Harvester harvester = await Harvester.create(tempDirectory, stderr);
final StateError error = await _expectThrow<StateError>(() async {
await harvest(harvester);
});
expect(error.message, contains('GOLDCTL'));
expect(
() => harvest(harvester),
throwsA(
isA<StateError>().having(
(t) => t.message,
'message',
contains('GOLDCTL'),
),
),
);
expect(stderr.toString(), isEmpty);
});
});
}
FutureOr<T> _expectThrow<T extends Object>(
FutureOr<void> Function() callback) async {
try {
await callback();
fail('Expected an exception of type $T');
} on T catch (e) {
return e;
} catch (e) {
fail('Expected an exception of type $T, but got $e');
}
// fail(...) unfortunately does not return Never, but it does always throw.
throw UnsupportedError('Unreachable');
}
final class _IntentionalError extends Error {}
Future<void> _alwaysThrowsAddImg(

View File

@@ -10,3 +10,22 @@ This library is a subset of the functionality provided by Skia's `PathKit`
library. It is primarily intended for use with the `vector_graphics` optimizing
compiler. That library uses this one to optimize certain masking and clipping
operations at compile time.
## Testing
The `path_ops` library uses dynamic libraries (i.e. `libpath_ops.dylib` or the
equivalent on your platform) to link against the C++ code in
[`path_ops.cpp`](path_ops.cpp). When run through
[`run_tests.py`](../../testing/run_tests.py), paths are set automatically to
make finding the dynamic library work.
However, if run directly from the command line or IDE, an environment variable
`DYLD_LIBRARY_PATH` (or equivalent on your platform) must be set to the
directory containing the dynamic library. For example, on macOS:
```sh
export DYLD_LIBRARY_PATH=BUILD_DIR
```
... where `BUILD_DIR` is the output directory for the engine build, such as
`../out/host_debug_unopt_arm64`.

View File

@@ -12,4 +12,4 @@ environment:
resolution: workspace
dev_dependencies:
litetest: any
test: any

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:litetest/litetest.dart';
import 'package:path_ops/path_ops.dart';
import 'package:test/test.dart';
void main() {
test('Path tests', () {

View File

@@ -30,7 +30,6 @@ ALL_PACKAGES = [
os.path.join(ENGINE_DIR, 'testing', 'benchmark'),
os.path.join(ENGINE_DIR, 'testing', 'dart'),
os.path.join(ENGINE_DIR, 'testing', 'litetest'),
os.path.join(ENGINE_DIR, 'testing', 'pkg_test_demo'),
os.path.join(ENGINE_DIR, 'testing', 'scenario_app'),
os.path.join(ENGINE_DIR, 'testing', 'skia_gold_client'),
os.path.join(ENGINE_DIR, 'testing', 'smoke_test_failure'),
@@ -104,7 +103,6 @@ EXCLUDED_DIRS = [
os.path.join(ENGINE_DIR, 'shell', 'platform', 'fuchsia'),
os.path.join(ENGINE_DIR, 'shell', 'vmservice'),
os.path.join(ENGINE_DIR, 'sky', 'packages'),
os.path.join(ENGINE_DIR, 'testing', 'pkg_test_demo'),
os.path.join(ENGINE_DIR, 'third_party'),
os.path.join(ENGINE_DIR, 'web_sdk'),
]