blob: 9669536db0c8afe497c6662bada95e60b2e06938 [file] [log] [blame]
// Copyright (c) 2018, 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:async';
import 'dart:io';
import 'package:front_end/src/api_unstable/vm.dart'
import 'package:kernel/ast.dart';
import 'package:kernel/text/ast_to_text.dart' show Printer;
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
import 'package:kernel/target/targets.dart';
import 'package:test/test.dart';
import 'package:vm/target/vm.dart' show VmTarget;
const bool kDumpActualResult = const bool.fromEnvironment('dump.actual.result');
class TestingVmTarget extends VmTarget {
TestingVmTarget(TargetFlags flags) : super(flags);
bool enableSuperMixins = false;
Future<Component> compileTestCaseToKernelProgram(Uri sourceUri,
{Target target, bool enableSuperMixins: false}) async {
final platformKernel =
target ??= new TestingVmTarget(new TargetFlags())
..enableSuperMixins = enableSuperMixins;
final options = new CompilerOptions() = target
..linkedDependencies = <Uri>[platformKernel]
..onDiagnostic = (DiagnosticMessage message) {
fail("Compilation error: ${message.plainTextFormatted.join('\n')}");
final Component component = await kernelForProgram(sourceUri, options);
// Make sure the library name is the same and does not depend on the order
// of test cases. = '#lib';
return component;
String kernelLibraryToString(Library library) {
final StringBuffer buffer = new StringBuffer();
new Printer(buffer, showExternal: false, showMetadata: true)
return buffer
class DevNullSink<T> extends Sink<T> {
void add(T data) {}
void close() {}
void ensureKernelCanBeSerializedToBinary(Component component) {
new BinaryPrinter(new DevNullSink<List<int>>()).writeComponentFile(component);
void compareResultWithExpectationsFile(Uri source, String actual) {
final expectFile = new File(source.toFilePath() + '.expect');
final expected = expectFile.existsSync() ? expectFile.readAsStringSync() : '';
if (actual != expected) {
if (kDumpActualResult) {
new File(source.toFilePath() + '.actual').writeAsStringSync(actual);
expect(actual, equals(expected), reason: "Test case: $source");