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'; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 var inputDir = dartGen | 49 var inputDir = dartGen |
50 ? path.join(testDir, 'dart_codegen') | 50 ? path.join(testDir, 'dart_codegen') |
51 : path.join(testDir, 'codegen'); | 51 : path.join(testDir, 'codegen'); |
52 var actualDir = path.join(inputDir, 'actual'); | 52 var actualDir = path.join(inputDir, 'actual'); |
53 var paths = new Directory(inputDir) | 53 var paths = new Directory(inputDir) |
54 .listSync() | 54 .listSync() |
55 .where((f) => f is File) | 55 .where((f) => f is File) |
56 .map((f) => f.path) | 56 .map((f) => f.path) |
57 .where((p) => p.endsWith('.dart') && filePattern.hasMatch(p)); | 57 .where((p) => p.endsWith('.dart') && filePattern.hasMatch(p)); |
58 | 58 |
59 compile(String entryPoint, String sdkPath, [bool checkSdk = false]) { | 59 compile(String entryPoint, String sdkPath, |
| 60 {bool checkSdk: false, bool serverMode: false}) { |
60 var options = new CompilerOptions( | 61 var options = new CompilerOptions( |
61 outputDir: actualDir, | 62 outputDir: serverMode ? path.join(actualDir, 'server_mode') : actualDir, |
62 useColors: false, | 63 useColors: false, |
63 outputDart: dartGen, | 64 outputDart: dartGen, |
64 formatOutput: dartGen, | 65 formatOutput: dartGen, |
65 emitSourceMaps: false, | 66 emitSourceMaps: false, |
66 forceCompile: checkSdk, | 67 forceCompile: checkSdk, |
67 cheapTestFormat: checkSdk, | 68 cheapTestFormat: checkSdk, |
68 checkSdk: checkSdk, | 69 checkSdk: checkSdk, |
69 entryPointFile: entryPoint, | 70 entryPointFile: entryPoint, |
70 dartSdkPath: sdkPath); | 71 dartSdkPath: sdkPath, |
| 72 serverMode: serverMode); |
71 return new Compiler(options).run(); | 73 return new Compiler(options).run(); |
72 } | 74 } |
73 var realSdk = getSdkDir(arguments).path; | 75 var realSdk = getSdkDir(arguments).path; |
74 | 76 |
75 // Validate that old output is gone before running. | 77 // Validate that old output is gone before running. |
76 // TODO(jmesserly): it'd be nice to do all cleanup here, including removing | 78 // TODO(jmesserly): it'd be nice to do all cleanup here, including removing |
77 // pub's 'packages' symlinks which mess up the diff. That way this test | 79 // pub's 'packages' symlinks which mess up the diff. That way this test |
78 // can be self contained instead of depending on a shell script. | 80 // can be self contained instead of depending on a shell script. |
79 if (new Directory(actualDir).existsSync()) { | 81 if (new Directory(actualDir).existsSync()) { |
80 throw 'Old compiler output should be cleaned up first. Use ./test/test.sh'; | 82 throw 'Old compiler output should be cleaned up first. Use ./test/test.sh'; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 }); | 122 }); |
121 | 123 |
122 test('devc dart:core', () { | 124 test('devc dart:core', () { |
123 // Get the test SDK. We use a checked in copy so test expectations can be | 125 // Get the test SDK. We use a checked in copy so test expectations can be |
124 // generated against a specific SDK version. | 126 // generated against a specific SDK version. |
125 // TODO(jmesserly): eventually we should track compiler messages. | 127 // TODO(jmesserly): eventually we should track compiler messages. |
126 // For now we're just trying to get decent code generation. | 128 // For now we're just trying to get decent code generation. |
127 var testSdk = dartGen | 129 var testSdk = dartGen |
128 ? path.join(testDir, '..', 'tool', 'input_sdk') | 130 ? path.join(testDir, '..', 'tool', 'input_sdk') |
129 : path.join(testDir, 'generated_sdk'); | 131 : path.join(testDir, 'generated_sdk'); |
130 var result = compile('dart:core', testSdk, true); | 132 var result = compile('dart:core', testSdk, checkSdk: true); |
131 var outputDir = new Directory(path.join(actualDir, 'core')); | 133 var outputDir = new Directory(path.join(actualDir, 'core')); |
132 var outFile = dartGen | 134 var outFile = dartGen |
133 ? new File(path.join(actualDir, 'core/core')) | 135 ? new File(path.join(actualDir, 'core/core')) |
134 : new File(path.join(actualDir, 'dart/core.js')); | 136 : new File(path.join(actualDir, 'dart/core.js')); |
135 expect(outFile.existsSync(), true, | 137 expect(outFile.existsSync(), true, |
136 reason: '${outFile.path} was created for dart:core'); | 138 reason: '${outFile.path} was created for dart:core'); |
137 }); | 139 }); |
138 }); | 140 }); |
139 | 141 |
140 if (!dartGen) { | 142 if (!dartGen) { |
141 test('devc jscodegen html_input.html', () { | 143 test('devc jscodegen html_input.html', () { |
142 var filePath = path.join(inputDir, 'html_input.html'); | 144 var filePath = path.join(inputDir, 'html_input.html'); |
143 compilerMessages.writeln('// Messages from compiling html_input.html'); | 145 compilerMessages.writeln('// Messages from compiling html_input.html'); |
144 | 146 |
145 var result = compile(filePath, realSdk); | 147 var result = compile(filePath, realSdk); |
146 var success = !result.failure; | 148 var success = !result.failure; |
147 | 149 |
148 // Write compiler messages to disk. | 150 // Write compiler messages to disk. |
149 new File(path.join(actualDir, 'html_input.txt')) | 151 new File(path.join(actualDir, 'html_input.txt')) |
150 .writeAsStringSync(compilerMessages.toString()); | 152 .writeAsStringSync(compilerMessages.toString()); |
151 | 153 |
152 var outFile = new File(path.join(actualDir, 'html_input.html')); | 154 var outFile = new File(path.join(actualDir, 'html_input.html')); |
153 expect(outFile.existsSync(), success, | 155 expect(outFile.existsSync(), success, |
154 reason: '${outFile.path} was created iff compilation succeeds'); | 156 reason: '${outFile.path} was created iff compilation succeeds'); |
155 }); | 157 }); |
| 158 |
| 159 test('devc jscodegen html_input.html server mode', () { |
| 160 var filePath = path.join(inputDir, 'html_input.html'); |
| 161 compilerMessages.writeln('// Messages from compiling html_input.html'); |
| 162 |
| 163 var result = compile(filePath, realSdk, serverMode: true); |
| 164 var success = !result.failure; |
| 165 |
| 166 // Write compiler messages to disk. |
| 167 new File(path.join(actualDir, 'server_mode', 'html_input.txt')) |
| 168 .writeAsStringSync(compilerMessages.toString()); |
| 169 |
| 170 var outFile = |
| 171 new File(path.join(actualDir, 'server_mode', 'html_input.html')); |
| 172 expect(outFile.existsSync(), success, |
| 173 reason: '${outFile.path} was created iff compilation succeeds'); |
| 174 }); |
156 } | 175 } |
157 } | 176 } |
158 | 177 |
159 /// An implementation of analysis engine's [Logger] that prints. | 178 /// An implementation of analysis engine's [Logger] that prints. |
160 class PrintLogger implements Logger { | 179 class PrintLogger implements Logger { |
161 @override void logError(String message, [CaughtException exception]) { | 180 @override void logError(String message, [CaughtException exception]) { |
162 print('[AnalysisEngine] error $message $exception'); | 181 print('[AnalysisEngine] error $message $exception'); |
163 } | 182 } |
164 | 183 |
165 @override void logError2(String message, Object exception) { | 184 @override void logError2(String message, Object exception) { |
166 print('[AnalysisEngine] error $message $exception'); | 185 print('[AnalysisEngine] error $message $exception'); |
167 } | 186 } |
168 | 187 |
169 void logInformation(String message, [CaughtException exception]) {} | 188 void logInformation(String message, [CaughtException exception]) {} |
170 void logInformation2(String message, Object exception) {} | 189 void logInformation2(String message, Object exception) {} |
171 } | 190 } |
OLD | NEW |