blob: 42c1f5fc6c40de64c3e74ae7faf3182951413f4e [file] [log] [blame]
// Copyright (c) 2015, 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.
library dart2js.serialization_analysis_test;
import 'dart:async';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/filenames.dart';
import '../memory_compiler.dart';
import 'helper.dart';
import 'test_data.dart';
main(List<String> args) {
asyncTest(() async {
Arguments arguments = new Arguments.from(args);
SerializedData serializedData =
await serializeDartCore(arguments: arguments);
if (arguments.filename != null) {
Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.filename));
await analyze(serializedData, entryPoint, null);
} else {
Uri entryPoint = Uri.parse('memory:main.dart');
await arguments.forEachTest(TESTS, (int index, Test test) async {
await analyze(serializedData, entryPoint, test);
});
}
});
}
Future analyze(SerializedData serializedData, Uri entryPoint, Test test,
{int index}) async {
String testDescription =
test != null ? test.sourceFiles[entryPoint.path] : '${entryPoint}';
print('------------------------------------------------------------------');
print('analyze ${index != null ? '$index:' :''}${testDescription}');
print('------------------------------------------------------------------');
DiagnosticCollector diagnosticCollector = new DiagnosticCollector();
await runCompiler(
entryPoint: entryPoint,
resolutionInputs: serializedData.toUris(),
memorySourceFiles: serializedData.toMemorySourceFiles(
test != null ? test.sourceFiles : null),
options: [Flags.analyzeOnly],
diagnosticHandler: diagnosticCollector);
if (test != null) {
Expect.equals(test.expectedErrorCount, diagnosticCollector.errors.length,
"Unexpected error count.");
Expect.equals(
test.expectedWarningCount,
diagnosticCollector.warnings.length,
"Unexpected warning count.");
Expect.equals(test.expectedHintCount, diagnosticCollector.hints.length,
"Unexpected hint count.");
Expect.equals(test.expectedInfoCount, diagnosticCollector.infos.length,
"Unexpected info count.");
}
}