mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
[dart2js_info] Update tests to allow using dart test
command
Makes local development a lot easier Change-Id: I85c6911db313cc9842359b149405aedeb8243be7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280407 Auto-Submit: Kevin Moore <kevmoo@google.com> Reviewed-by: Mark Zhou <markzipan@google.com> Commit-Queue: Mark Zhou <markzipan@google.com>
This commit is contained in:
parent
aa7a150bcd
commit
7d9dab0e7a
|
@ -3,13 +3,14 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io' show File, Platform;
|
||||
import 'dart:typed_data' show BytesBuilder;
|
||||
|
||||
import 'package:dart2js_info/binary_serialization.dart' as binary;
|
||||
import 'package:dart2js_info/json_info_codec.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'test_shared.dart';
|
||||
|
||||
class ByteSink implements Sink<List<int>> {
|
||||
BytesBuilder builder = BytesBuilder();
|
||||
|
||||
|
@ -21,12 +22,9 @@ class ByteSink implements Sink<List<int>> {
|
|||
|
||||
void main() {
|
||||
group('json to proto conversion with deferred files', () {
|
||||
test('hello_world_deferred', () {
|
||||
var uri = Platform.script
|
||||
.resolve('hello_world_deferred/hello_world_deferred.js.info.json');
|
||||
var helloWorld = File.fromUri(uri);
|
||||
var contents = helloWorld.readAsStringSync();
|
||||
var json = jsonDecode(contents);
|
||||
test('hello_world_deferred', () async {
|
||||
var helloWorld = await helloWorldDeferredDumpInfo();
|
||||
var json = jsonDecode(helloWorld);
|
||||
// Clear toJsonDuration for consistency.
|
||||
json['program']['toJsonDuration'] = 0;
|
||||
var info = AllInfoJsonCodec().decode(json);
|
||||
|
|
|
@ -3,19 +3,18 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart2js_info/json_info_codec.dart';
|
||||
import 'package:dart2js_info/proto_info_codec.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'test_shared.dart';
|
||||
|
||||
void main() {
|
||||
group('json to proto conversion with deferred files', () {
|
||||
test('hello_world_deferred', () {
|
||||
var uri = Platform.script
|
||||
.resolve('hello_world_deferred/hello_world_deferred.js.info.json');
|
||||
final helloWorld = File.fromUri(uri);
|
||||
final json = jsonDecode(helloWorld.readAsStringSync());
|
||||
test('hello_world_deferred', () async {
|
||||
final helloWorld = await helloWorldDeferredDumpInfo();
|
||||
final json = jsonDecode(helloWorld);
|
||||
final decoded = AllInfoJsonCodec().decode(json);
|
||||
final proto = AllInfoProtoCodec().encode(decoded);
|
||||
|
||||
|
|
|
@ -3,19 +3,23 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart2js_info/info.dart';
|
||||
import 'package:dart2js_info/json_info_codec.dart';
|
||||
import 'package:dart2js_info/proto_info_codec.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'test_shared.dart';
|
||||
|
||||
void main() {
|
||||
late String content;
|
||||
setUpAll(() async {
|
||||
content = await helloWorldDumpInfo();
|
||||
});
|
||||
|
||||
group('json to proto conversion', () {
|
||||
test('hello_world', () {
|
||||
var uri = Platform.script.resolve('hello_world/hello_world.js.info.json');
|
||||
final helloWorld = File.fromUri(uri);
|
||||
final json = jsonDecode(helloWorld.readAsStringSync());
|
||||
final json = jsonDecode(content);
|
||||
final decoded = AllInfoJsonCodec().decode(json);
|
||||
final proto = AllInfoProtoCodec().encode(decoded);
|
||||
|
||||
|
@ -32,9 +36,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('has proper id format', () {
|
||||
var uri = Platform.script.resolve('hello_world/hello_world.js.info.json');
|
||||
final helloWorld = File.fromUri(uri);
|
||||
final json = jsonDecode(helloWorld.readAsStringSync());
|
||||
final json = jsonDecode(content);
|
||||
final decoded = AllInfoJsonCodec().decode(json);
|
||||
final proto = AllInfoProtoCodec().encode(decoded);
|
||||
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart2js_info/json_info_codec.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'test_shared.dart';
|
||||
|
||||
void main() {
|
||||
group('parse', () {
|
||||
test('hello_world', () {
|
||||
var uri = Platform.script.resolve('hello_world/hello_world.js.info.json');
|
||||
var helloWorld = File.fromUri(uri);
|
||||
var json = jsonDecode(helloWorld.readAsStringSync());
|
||||
test('hello_world', () async {
|
||||
var content = await helloWorldDumpInfo();
|
||||
var json = jsonDecode(content);
|
||||
var decoded = AllInfoJsonCodec().decode(json);
|
||||
|
||||
final program = decoded.program;
|
||||
|
|
|
@ -11,24 +11,28 @@
|
|||
// --dump-info=binary
|
||||
// --packages=$PATH_TO_SDK/.dart_tool/package_config.json
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart2js_info/binary_serialization.dart';
|
||||
import 'package:dart2js_info/info.dart';
|
||||
import 'package:dart2js_info/src/runtime_coverage_utils.dart';
|
||||
import 'package:dart2js_info/src/util.dart';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'test_shared.dart';
|
||||
|
||||
void main() {
|
||||
group('runtime coverage', () {
|
||||
group('class filter (angular info)', () {
|
||||
final infoBinaryFile =
|
||||
File.fromUri(Platform.script.resolve('classes/classes.js.info.data'));
|
||||
final allInfo = decode(infoBinaryFile.readAsBytesSync());
|
||||
final classFilters =
|
||||
File.fromUri(Platform.script.resolve('classes/class_filter.txt'))
|
||||
.readAsLinesSync();
|
||||
final runtimeClassInfos = <String, RuntimeClassInfo>{};
|
||||
late final List<String> classFilters;
|
||||
late final AllInfo allInfo;
|
||||
|
||||
setUpAll(() async {
|
||||
final infoBinaryFile =
|
||||
await resolveTestFile('classes/classes.js.info.data');
|
||||
allInfo = decode(infoBinaryFile.readAsBytesSync());
|
||||
classFilters = (await resolveTestFile('classes/class_filter.txt'))
|
||||
.readAsLinesSync();
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
runtimeClassInfos.clear();
|
||||
|
|
21
pkg/dart2js_info/test/test_shared.dart
Normal file
21
pkg/dart2js_info/test/test_shared.dart
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. 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';
|
||||
import 'dart:isolate';
|
||||
|
||||
Future<String> helloWorldDumpInfo() async =>
|
||||
resolveTestFileContent('hello_world/hello_world.js.info.json');
|
||||
|
||||
Future<String> helloWorldDeferredDumpInfo() async => resolveTestFileContent(
|
||||
'hello_world_deferred/hello_world_deferred.js.info.json');
|
||||
|
||||
Future<String> resolveTestFileContent(String filePath) async =>
|
||||
(await resolveTestFile(filePath)).readAsStringSync();
|
||||
|
||||
Future<File> resolveTestFile(String filePath) async {
|
||||
final mainLibraryUri = await Isolate.resolvePackageUri(
|
||||
Uri.parse('package:dart2js_info/info.dart'));
|
||||
return File.fromUri(mainLibraryUri!.resolve('../test/$filePath'));
|
||||
}
|
Loading…
Reference in a new issue