Files
sdk/pkg/dev_compiler/test/codegen_test.dart
T
Sigmund Cherem 02a4650a24 Refactor: move code around a bit
- bin/
    devc.dart

- lib/
    devc.dart

    src/
       info.dart # static info we compute, used by checker & backends
       checker/  # implementation details for the checker
          checker.dart  # checking algorithm
          rules.dart    # type checking rules
          resolver.dart # same as today, type resolution via analyzer
       emitter/
          ...
- test/
     checker/    # unit tests for the checker internals
     codegen/    # left as is - maybe should rename to emitter?
     samples/    # stand alone samples that we run in the end_to_end tests.
     ...

R=vsm@google.com

Review URL: https://chromereviews.googleplex.com/128957013
2014-12-11 15:13:54 -08:00

80 lines
2.7 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, useColors: false);
});
tearDown(() {
if (loggerSub != null) {
loggerSub.cancel();
loggerSub = null;
}
});
var testDir = path.absolute(path.dirname(script));
var inputDir = path.join(testDir, 'codegen');
var expectDir = path.join(inputDir, 'expect');
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');
return compile(filePath, sdkResolver, outputDir: actualDir,
useColors: false).then((success) {
// 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.
});
});
}
}