| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Tests code generation. | 5 /// Tests code generation. |
| 6 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks | 6 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks |
| 7 /// that the output is what we expected. | 7 /// that the output is what we expected. |
| 8 library dev_compiler.test.codegen_test; | 8 library dev_compiler.test.codegen_test; |
| 9 | 9 |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 import 'package:cli_util/cli_util.dart' show getSdkDir; | 11 import 'package:cli_util/cli_util.dart' show getSdkDir; |
| 12 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine, Logger; | 12 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine, Logger; |
| 13 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; | 13 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; |
| 14 import 'package:args/args.dart'; | 14 import 'package:args/args.dart'; |
| 15 import 'package:logging/logging.dart' show Level; | 15 import 'package:logging/logging.dart' show Level; |
| 16 import 'package:path/path.dart' as path; | 16 import 'package:path/path.dart' as path; |
| 17 import 'package:unittest/unittest.dart'; | 17 import 'package:test/test.dart'; |
| 18 | 18 |
| 19 import 'package:dev_compiler/devc.dart'; | 19 import 'package:dev_compiler/devc.dart'; |
| 20 import 'package:dev_compiler/src/options.dart'; | 20 import 'package:dev_compiler/src/options.dart'; |
| 21 import 'package:dev_compiler/src/dependency_graph.dart' | 21 import 'package:dev_compiler/src/dependency_graph.dart' |
| 22 show defaultRuntimeFiles; | 22 show defaultRuntimeFiles; |
| 23 import 'package:dev_compiler/src/utils.dart' | 23 import 'package:dev_compiler/src/utils.dart' |
| 24 show computeHash, computeHashFromFile; | 24 show computeHash, computeHashFromFile; |
| 25 import 'package:html/parser.dart' as html; | 25 import 'package:html/parser.dart' as html; |
| 26 | 26 |
| 27 import 'test_util.dart' show testDirectory; |
| 28 |
| 27 final ArgParser argParser = new ArgParser() | 29 final ArgParser argParser = new ArgParser() |
| 28 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) | 30 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) |
| 29 ..addFlag('dart-gen', | 31 ..addFlag('dart-gen', |
| 30 abbr: 'd', help: 'Generate dart output', defaultsTo: false); | 32 abbr: 'd', help: 'Generate dart output', defaultsTo: false); |
| 31 | 33 |
| 32 main(arguments) { | 34 main(arguments) { |
| 33 if (arguments == null) arguments = []; | 35 if (arguments == null) arguments = []; |
| 34 ArgResults args = argParser.parse(arguments); | 36 ArgResults args = argParser.parse(arguments); |
| 35 var script = Platform.script.path; | |
| 36 var dartGen = args['dart-gen']; | 37 var dartGen = args['dart-gen']; |
| 37 var filePattern = new RegExp(args.rest.length > 0 ? args.rest[0] : '.'); | 38 var filePattern = new RegExp(args.rest.length > 0 ? args.rest[0] : '.'); |
| 38 var compilerMessages = new StringBuffer(); | 39 var compilerMessages = new StringBuffer(); |
| 39 var loggerSub; | 40 var loggerSub; |
| 40 | 41 |
| 41 setUp(() { | 42 setUp(() { |
| 42 compilerMessages.clear(); | 43 compilerMessages.clear(); |
| 43 loggerSub = setupLogger(Level.CONFIG, compilerMessages.writeln); | 44 loggerSub = setupLogger(Level.CONFIG, compilerMessages.writeln); |
| 44 }); | 45 }); |
| 45 | 46 |
| 46 tearDown(() { | 47 tearDown(() { |
| 47 if (loggerSub != null) { | 48 if (loggerSub != null) { |
| 48 loggerSub.cancel(); | 49 loggerSub.cancel(); |
| 49 loggerSub = null; | 50 loggerSub = null; |
| 50 } | 51 } |
| 51 }); | 52 }); |
| 52 | 53 |
| 53 var testDir = path.absolute(path.dirname(script)); | 54 var inputDir = path.join(testDirectory, dartGen ? 'dart_codegen' : 'codegen'); |
| 54 var inputDir = dartGen | |
| 55 ? path.join(testDir, 'dart_codegen') | |
| 56 : path.join(testDir, 'codegen'); | |
| 57 var actualDir = path.join(inputDir, 'actual'); | 55 var actualDir = path.join(inputDir, 'actual'); |
| 58 var paths = new Directory(inputDir) | 56 var paths = new Directory(inputDir) |
| 59 .listSync() | 57 .listSync() |
| 60 .where((f) => f is File) | 58 .where((f) => f is File) |
| 61 .map((f) => f.path) | 59 .map((f) => f.path) |
| 62 .where((p) => p.endsWith('.dart') && filePattern.hasMatch(p)); | 60 .where((p) => p.endsWith('.dart') && filePattern.hasMatch(p)); |
| 63 | 61 |
| 64 compile(String entryPoint, String sdkPath, {bool checkSdk: false, | 62 compile(String entryPoint, String sdkPath, {bool checkSdk: false, |
| 65 bool serverMode: false, bool sourceMaps: false, String subDir}) { | 63 bool serverMode: false, bool sourceMaps: false, String subDir}) { |
| 66 // TODO(jmesserly): add a way to specify flags in the test file, so | 64 // TODO(jmesserly): add a way to specify flags in the test file, so |
| 67 // they're more self-contained. | 65 // they're more self-contained. |
| 68 var runtimeDir = path.join( | 66 var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime'); |
| 69 path.dirname(path.dirname(Platform.script.path)), 'lib', 'runtime'); | |
| 70 var options = new CompilerOptions( | 67 var options = new CompilerOptions( |
| 71 allowConstCasts: !dartGen, | 68 allowConstCasts: !dartGen, |
| 72 outputDir: subDir == null ? actualDir : path.join(actualDir, subDir), | 69 outputDir: subDir == null ? actualDir : path.join(actualDir, subDir), |
| 73 useColors: false, | 70 useColors: false, |
| 74 outputDart: dartGen, | 71 outputDart: dartGen, |
| 75 formatOutput: dartGen, | 72 formatOutput: dartGen, |
| 76 emitSourceMaps: sourceMaps, | 73 emitSourceMaps: sourceMaps, |
| 77 forceCompile: checkSdk, | 74 forceCompile: checkSdk, |
| 78 cheapTestFormat: checkSdk, | |
| 79 checkSdk: checkSdk, | 75 checkSdk: checkSdk, |
| 80 entryPointFile: entryPoint, | 76 entryPointFile: entryPoint, |
| 81 dartSdkPath: sdkPath, | 77 dartSdkPath: sdkPath, |
| 82 runtimeDir: runtimeDir, | 78 runtimeDir: runtimeDir, |
| 83 serverMode: serverMode, | 79 serverMode: serverMode, |
| 84 enableHashing: serverMode); | 80 enableHashing: serverMode); |
| 85 return new Compiler(options).run(); | 81 return new Compiler(options).run(); |
| 86 } | 82 } |
| 87 var realSdk = getSdkDir(arguments).path; | 83 var realSdk = getSdkDir(arguments).path; |
| 88 | 84 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 AnalysisEngine.instance.logger = new PrintLogger(); | 130 AnalysisEngine.instance.logger = new PrintLogger(); |
| 135 }); | 131 }); |
| 136 tearDown(() { | 132 tearDown(() { |
| 137 AnalysisEngine.instance.logger = savedLogger; | 133 AnalysisEngine.instance.logger = savedLogger; |
| 138 }); | 134 }); |
| 139 | 135 |
| 140 test('devc dart:core', () { | 136 test('devc dart:core', () { |
| 141 // Get the test SDK. We use a checked in copy so test expectations can | 137 // Get the test SDK. We use a checked in copy so test expectations can |
| 142 // be generated against a specific SDK version. | 138 // be generated against a specific SDK version. |
| 143 var testSdk = dartGen | 139 var testSdk = dartGen |
| 144 ? path.join(testDir, '..', 'tool', 'input_sdk') | 140 ? path.join(testDirectory, '..', 'tool', 'input_sdk') |
| 145 : path.join(testDir, 'generated_sdk'); | 141 : path.join(testDirectory, 'generated_sdk'); |
| 146 var result = compile('dart:core', testSdk, checkSdk: true); | 142 var result = compile('dart:core', testSdk, checkSdk: true); |
| 147 var outputDir = new Directory(path.join(actualDir, 'core')); | 143 var outputDir = new Directory(path.join(actualDir, 'core')); |
| 148 var outFile = new File( | 144 var outFile = new File( |
| 149 path.join(actualDir, dartGen ? 'core/core' : 'dart/core.js')); | 145 path.join(actualDir, dartGen ? 'core/core' : 'dart/core.js')); |
| 150 expect(outFile.existsSync(), true, | 146 expect(outFile.existsSync(), true, |
| 151 reason: '${outFile.path} was created for dart:core'); | 147 reason: '${outFile.path} was created for dart:core'); |
| 152 }); | 148 }); |
| 153 }); | 149 }); |
| 154 } | 150 } |
| 155 | 151 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 print('[AnalysisEngine] error $message $exception'); | 278 print('[AnalysisEngine] error $message $exception'); |
| 283 } | 279 } |
| 284 | 280 |
| 285 @override void logError2(String message, Object exception) { | 281 @override void logError2(String message, Object exception) { |
| 286 print('[AnalysisEngine] error $message $exception'); | 282 print('[AnalysisEngine] error $message $exception'); |
| 287 } | 283 } |
| 288 | 284 |
| 289 void logInformation(String message, [CaughtException exception]) {} | 285 void logInformation(String message, [CaughtException exception]) {} |
| 290 void logInformation2(String message, Object exception) {} | 286 void logInformation2(String message, Object exception) {} |
| 291 } | 287 } |
| OLD | NEW |