Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: pkg/front_end/test/fasta/bootstrap_test.dart

Issue 2723173002: Apply transformers and other work arounds to get boostrapping to work. (Closed)
Patch Set: Add exception class. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async' show Future; 5 import 'dart:async' show Future;
6 6
7 import 'dart:io' show Directory, Platform; 7 import 'dart:io' show Directory, File, Platform;
8 8
9 import 'dart:isolate' show Isolate; 9 import 'dart:isolate' show Isolate;
10 10
11 import 'package:async_helper/async_helper.dart' show asyncEnd, asyncStart; 11 import 'package:async_helper/async_helper.dart' show asyncEnd, asyncStart;
12 12
13 import 'package:front_end/src/fasta/testing/kernel_chain.dart' 13 import 'package:front_end/src/fasta/testing/kernel_chain.dart'
14 show computePatchedSdk; 14 show computePatchedSdk;
15 15
16 import 'package:testing/testing.dart' show StdioProcess; 16 import 'package:testing/testing.dart' show StdioProcess;
17 17
18 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
19
20 import 'package:kernel/ast.dart' show Program;
21
22 import 'package:kernel/text/ast_to_text.dart' show programToString;
23
18 Future main() async { 24 Future main() async {
19 asyncStart(); 25 asyncStart();
20 Uri sourceCompiler = await Isolate.resolvePackageUri( 26 Uri sourceCompiler = await Isolate.resolvePackageUri(
21 Uri.parse("package:front_end/src/fasta/bin/compile.dart")); 27 Uri.parse("package:front_end/src/fasta/bin/compile.dart"));
28 Uri outline = await Isolate.resolvePackageUri(
29 Uri.parse("package:front_end/src/fasta/bin/outline.dart"));
22 Uri packages = await Isolate.packageConfig; 30 Uri packages = await Isolate.packageConfig;
23 Directory tmp = await Directory.systemTemp.createTemp("fasta_bootstrap"); 31 Directory tmp = await Directory.systemTemp.createTemp("fasta_bootstrap");
24 Uri compiledOnceOutput = tmp.uri.resolve("fasta1.dill"); 32 Uri compiledOnceOutput = tmp.uri.resolve("fasta1.dill");
25 Uri compiledTwiceOutput = tmp.uri.resolve("fasta2.dill"); 33 Uri compiledTwiceOutput = tmp.uri.resolve("fasta2.dill");
34 Uri outlineOutput = tmp.uri.resolve("outline.dill");
26 try { 35 try {
27 await runCompiler(sourceCompiler, sourceCompiler, compiledOnceOutput); 36 await runCompiler(sourceCompiler, sourceCompiler, compiledOnceOutput);
28 await runCompiler(compiledOnceOutput, sourceCompiler, compiledTwiceOutput); 37 await runCompiler(compiledOnceOutput, sourceCompiler, compiledTwiceOutput);
38 await compare(compiledOnceOutput, compiledTwiceOutput);
39 await runCompiler(compiledTwiceOutput, outline, outlineOutput);
40 try {
41 // Test that compare actually works by comparing the compile program to
42 // the outline program (which are different, but similar).
43 await compare(compiledOnceOutput, outlineOutput, silent: true);
44 throw "Expected an error.";
45 } on ComparisonFailed {
46 // Expected.
47 }
29 } finally { 48 } finally {
30 await tmp.delete(recursive: true); 49 await tmp.delete(recursive: true);
31 } 50 }
32 asyncEnd(); 51 asyncEnd();
33 } 52 }
34 53
35 Future runCompiler(Uri compiler, Uri input, Uri output) async { 54 Future runCompiler(Uri compiler, Uri input, Uri output) async {
36 Uri patchedSdk = await computePatchedSdk(); 55 Uri patchedSdk = await computePatchedSdk();
37 Uri dartVm = Uri.base.resolve(Platform.resolvedExecutable); 56 Uri dartVm = Uri.base.resolve(Platform.resolvedExecutable);
38 StdioProcess result = await StdioProcess.run(dartVm.toFilePath(), <String>[ 57 StdioProcess result = await StdioProcess.run(dartVm.toFilePath(), <String>[
39 "-c", 58 "-c",
40 compiler.toFilePath(), 59 compiler.toFilePath(),
41 "--compile-sdk=${patchedSdk.toFilePath()}", 60 "--compile-sdk=${patchedSdk.toFilePath()}",
42 "--output=${output.toFilePath()}", 61 "--output=${output.toFilePath()}",
43 "--verify", 62 "--verify",
44 input.toFilePath(), 63 input.toFilePath(),
45 ]); 64 ]);
46 print(result.output); 65 print(result.output);
47 if (result.exitCode != 0) { 66 if (result.exitCode != 0) {
48 throw "Compilation failed."; 67 throw "Compilation failed.";
49 } 68 }
50 } 69 }
70
71 Future compare(Uri a, Uri b, {bool silent: false}) async {
72 List<int> bytesA = await new File.fromUri(a).readAsBytes();
73 List<int> bytesB = await new File.fromUri(b).readAsBytes();
74 if (bytesA.length == bytesB.length) {
75 bool same = true;
76 for (int i = 0; i < bytesA.length; i++) {
77 if (bytesA[i] != bytesB[i]) {
78 same = false;
79 break;
80 }
81 }
82 if (same) return;
83 }
84 if (!silent) {
85 print("$a is different from $b");
86 }
87 Program programA = new Program();
88 Program programB = new Program();
89 new BinaryBuilder(bytesA, a.toFilePath()).readProgram(programA);
90 new BinaryBuilder(bytesB, b.toFilePath()).readProgram(programB);
91 RegExp splitLines = new RegExp('^', multiLine: true);
92 List<String> linesA = programToString(programA).split(splitLines);
93 List<String> linesB = programToString(programB).split(splitLines);
94 for (int i = 0; i < linesA.length && i < linesB.length; i++) {
95 String lineA = linesA[i].trimRight();
96 String lineB = linesB[i].trimRight();
97 if (lineA != lineB) {
98 String diffHunk = "${i}c$i\n>$lineA\n---\n<$lineB";
99 if (!silent) {
100 print(diffHunk);
101 }
102 }
103 }
104 throw new ComparisonFailed(a, b);
105 }
106
107 class ComparisonFailed {
108 final Uri a;
109 final Uri b;
110
111 ComparisonFailed(this.a, this.b);
112
113 toString() => "Error: $a is different from $b";
114 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/verifier.dart ('k') | pkg/front_end/test/fasta/compile.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698