Files
sdk/pkg/dev_compiler/test/codegen_test.dart
T
Sigmund Cherem 763e61f4d3 Compile library-by-library. This is a step closer to our incremental compile.
As part of this change I made codegen synchronous. Technically is not necessary,
but I think it reduces complexity a lot. For example, keeping it async would
have required more changes to the testing infrastructure. Let me know if you
want to keep that change separate though.

With this change, I'm removing one more use of element.node, which is necessary
to achileve our goal. There is only one more use of this API, for which John has
a CL out.

BUG=
R=jmesserly@google.com

Review URL: https://chromereviews.googleplex.com/145167013
2015-01-27 09:49:26 -08:00

78 lines
2.6 KiB
Dart

/// Tests JavaScript code generation.
/// Runs Dart Dev Compiler on all input in the `codengen` directory and checks
/// that the JavaScript output is what we expected.
library ddc.test.codegen_test;
import 'dart:io';
import 'package:ddc/devc.dart';
import 'package:ddc/src/checker/dart_sdk.dart' show dartSdkDirectory;
import 'package:ddc/src/checker/resolver.dart' show TypeResolver;
import 'package:logging/logging.dart' show Level;
import 'package:path/path.dart' as path;
import 'package:unittest/unittest.dart';
main(arguments) {
if (arguments == null) arguments = [];
var script = Platform.script.path;
var filePattern = new RegExp(arguments.length > 0 ? arguments[0] : '.');
var compilerMessages = new StringBuffer();
var loggerSub;
setUp(() {
compilerMessages.clear();
loggerSub = setupLogger(Level.CONFIG, compilerMessages.writeln);
});
tearDown(() {
if (loggerSub != null) {
loggerSub.cancel();
loggerSub = null;
}
});
var testDir = path.absolute(path.dirname(script));
var inputDir = path.join(testDir, 'codegen');
var actualDir = path.join(inputDir, 'actual');
var paths = new Directory(inputDir)
.listSync()
.where((f) => f is File)
.map((f) => f.path)
.where((p) => p.endsWith('.dart') && filePattern.hasMatch(p));
var sdkResolver =
new TypeResolver(TypeResolver.sdkResolverFromDir(dartSdkDirectory));
// Validate that old output is gone before running.
// TODO(jmesserly): it'd be nice to do all cleanup here, including removing
// pub's 'packages' symlinks which mess up the diff. That way this test
// can be self contained instead of depending on a shell script.
if (new Directory(actualDir).existsSync()) {
throw 'Old compiler output should be cleaned up first. Use ./test/test.sh';
}
for (var filePath in paths) {
var filename = path.basenameWithoutExtension(filePath);
test('ddc $filename.dart', () {
compilerMessages.writeln('// Messages from compiling $filename.dart');
var result = compile(filePath, sdkResolver,
outputDir: actualDir, useColors: false);
var success = !result.failure;
// Write compiler messages to disk.
new File(path.join(actualDir, '$filename.txt'))
.writeAsStringSync(compilerMessages.toString());
var outputDir = new Directory(path.join(actualDir, filename));
expect(outputDir.existsSync(), success,
reason: '${outputDir.path} was created iff compilation succeeds');
// TODO(jmesserly): ideally we'd diff the output here. For now it
// happens in the containing shell script.
});
}
}