| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library rasta.dart2js_test; | 5 library rasta.dart2js_test; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 Future, | 8 Future, |
| 9 Stream; | 9 Stream; |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 import 'package:rasta/src/rastask.dart' show | 40 import 'package:rasta/src/rastask.dart' show |
| 41 Rastask, | 41 Rastask, |
| 42 openWrite; | 42 openWrite; |
| 43 | 43 |
| 44 import 'package:rasta/src/options.dart' show | 44 import 'package:rasta/src/options.dart' show |
| 45 Options; | 45 Options; |
| 46 | 46 |
| 47 const bool generateExpectations = | 47 const bool generateExpectations = |
| 48 const bool.fromEnvironment("generateExpectations"); | 48 const bool.fromEnvironment("generateExpectations"); |
| 49 | 49 |
| 50 const String dartExtension = ".dart"; |
| 51 const String kernelExtension = ".dill"; |
| 52 |
| 50 Future<Null> addRegressions(Map<Uri, Uri> tests, Uri temp) async { | 53 Future<Null> addRegressions(Map<Uri, Uri> tests, Uri temp) async { |
| 51 Stream<TestDescription> regressions = listTests( | 54 Stream<TestDescription> regressions = listTests( |
| 52 <Uri>[Uri.base.resolve("test/kernel/regression/")], pattern: ".dart"); | 55 <Uri>[Uri.base.resolve("test/kernel/regression/")], |
| 56 pattern: dartExtension); |
| 53 await for (TestDescription regression in regressions) { | 57 await for (TestDescription regression in regressions) { |
| 54 tests[regression.uri] = temp.resolve("${regression.shortName}.bart"); | 58 tests[regression.uri] = |
| 59 temp.resolve("${regression.shortName}$kernelExtension"); |
| 55 } | 60 } |
| 56 } | 61 } |
| 57 | 62 |
| 58 Future<Null> main() async { | 63 Future<Null> main() async { |
| 59 Stopwatch wallClock = new Stopwatch()..start(); | 64 Stopwatch wallClock = new Stopwatch()..start(); |
| 60 Rastask task = await Rastask.create( | 65 Rastask task = await Rastask.create( |
| 61 wallClock, <String>["--library", "${Platform.script}"]); | 66 wallClock, <String>["--library", "${Platform.script}"]); |
| 62 await task.measureSubtask("runTests", () => runTests(task)); | 67 await task.measureSubtask("runTests", () => runTests(task)); |
| 63 } | 68 } |
| 64 | 69 |
| 65 Future<Null> runTests(Rastask task) async { | 70 Future<Null> runTests(Rastask task) async { |
| 66 await task.setup(); | 71 await task.setup(); |
| 67 | 72 |
| 68 // When running via `testa.dart`, [Platform.script] is located in a temporary | 73 // When running via `testa.dart`, [Platform.script] is located in a temporary |
| 69 // directory. | 74 // directory. |
| 70 Uri temp = Platform.script; | 75 Uri temp = Platform.script; |
| 71 Map<Uri, Uri> tests = <Uri, Uri>{ | 76 Map<Uri, Uri> tests = <Uri, Uri>{ |
| 72 Uri.parse("dart:core"): temp.resolve("core.bart"), | 77 Uri.parse("dart:core"): temp.resolve("core$kernelExtension"), |
| 73 | 78 |
| 74 Uri.parse("package:compiler/src/dart2js.dart"): | 79 Uri.parse("package:compiler/src/dart2js$dartExtension"): |
| 75 temp.resolve("dart2js.bart"), | 80 temp.resolve("dart2js$kernelExtension"), |
| 76 }; | 81 }; |
| 77 | 82 |
| 78 await addRegressions(tests, temp); | 83 await addRegressions(tests, temp); |
| 79 | 84 |
| 80 Uri statusFile = Uri.base.resolve("test/rasta.status"); | 85 Uri statusFile = Uri.base.resolve("test/rasta.status"); |
| 81 TestExpectations expectations = | 86 TestExpectations expectations = |
| 82 await ReadTestExpectations(<String>[statusFile.toFilePath()], {}); | 87 await ReadTestExpectations(<String>[statusFile.toFilePath()], {}); |
| 83 | 88 |
| 84 List<Uri> fails = <Uri>[]; | 89 List<Uri> fails = <Uri>[]; |
| 85 | 90 |
| 86 for (Uri source in tests.keys) { | 91 for (Uri source in tests.keys) { |
| 87 assert(task.kernel.isInternalStateConsistent); | 92 assert(task.kernel.isInternalStateConsistent); |
| 88 | 93 |
| 89 bool isRegression = source.path.contains("/regression/"); | 94 bool isRegression = source.path.contains("/regression/"); |
| 90 | 95 |
| 91 print("Rastarizing $source"); | 96 print("Rastarizing $source"); |
| 92 Uri bart = tests[source]; | 97 Uri dill = tests[source]; |
| 93 File output = new File.fromUri(bart); | 98 File output = new File.fromUri(dill); |
| 94 await output.parent.create(recursive: true); | 99 await output.parent.create(recursive: true); |
| 95 | 100 |
| 96 Options options = new Options( | 101 Options options = new Options( |
| 97 source, bart, dependenciesFile: null, | 102 source, dill, dependenciesFile: null, |
| 98 generateLibrary: isRegression ? isRegression : null, | 103 generateLibrary: isRegression ? isRegression : null, |
| 99 isVerbose: true, isBatch: false, pattern: null); | 104 isVerbose: true, isBatch: false, pattern: null); |
| 100 | 105 |
| 101 ir.TreeNode node; | 106 ir.TreeNode node; |
| 102 Expectation outcome = Expectation.PASS; | 107 Expectation outcome = Expectation.PASS; |
| 103 var error; | 108 var error; |
| 104 StackTrace trace; | 109 StackTrace trace; |
| 105 try { | 110 try { |
| 106 node = await task.runOne(options); | 111 node = await task.runOne(options); |
| 107 } catch (e, t) { | 112 } catch (e, t) { |
| 108 outcome = Expectation.CRASH; | 113 outcome = Expectation.CRASH; |
| 109 task.kernel.recoverFromCrash(); | 114 task.kernel.recoverFromCrash(); |
| 110 error = e; | 115 error = e; |
| 111 trace = t; | 116 trace = t; |
| 112 } | 117 } |
| 113 | 118 |
| 114 if (isRegression && outcome == Expectation.PASS) { | 119 if (isRegression && outcome == Expectation.PASS) { |
| 115 outcome = await checkAgainstExpectations(node); | 120 outcome = await checkAgainstExpectations(node); |
| 116 } | 121 } |
| 117 if (outcome == Expectation.PASS) { | 122 if (outcome == Expectation.PASS) { |
| 118 outcome = checkRoundTrip(bart); | 123 outcome = checkRoundTrip(dill); |
| 119 } | 124 } |
| 120 | 125 |
| 121 Set<Expectation> expectedOutcomes = isRegression | 126 Set<Expectation> expectedOutcomes = isRegression |
| 122 ? expectations.expectations( | 127 ? expectations.expectations( |
| 123 relativize(statusFile.resolve("."), source, false)) | 128 relativize(statusFile.resolve("."), source, false)) |
| 124 : <Expectation>[Expectation.PASS].toSet(); | 129 : <Expectation>[Expectation.PASS].toSet(); |
| 125 | 130 |
| 126 if (!expectedOutcomes.contains(outcome)) { | 131 if (!expectedOutcomes.contains(outcome)) { |
| 127 print("$source: '$outcome' isn't one of '$expectedOutcomes'."); | 132 print("$source: '$outcome' isn't one of '$expectedOutcomes'."); |
| 128 if (error != null) print(error); | 133 if (error != null) print(error); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 ir.TreeNode programOrLibrary = | 186 ir.TreeNode programOrLibrary = |
| 182 new BinaryLoader(repository).loadProgramOrLibrary("$uri"); | 187 new BinaryLoader(repository).loadProgramOrLibrary("$uri"); |
| 183 Printer printer = new Printer(new StringBuffer()); | 188 Printer printer = new Printer(new StringBuffer()); |
| 184 if (programOrLibrary is ir.Program) { | 189 if (programOrLibrary is ir.Program) { |
| 185 printer.writeProgramFile(programOrLibrary); | 190 printer.writeProgramFile(programOrLibrary); |
| 186 } else { | 191 } else { |
| 187 printer.writeLibraryFile(programOrLibrary); | 192 printer.writeLibraryFile(programOrLibrary); |
| 188 } | 193 } |
| 189 return Expectation.PASS; | 194 return Expectation.PASS; |
| 190 } | 195 } |
| OLD | NEW |