Chromium Code Reviews| Index: tests/stub-generator/test_config.dart |
| diff --git a/tests/stub-generator/test_config.dart b/tests/stub-generator/test_config.dart |
| index 989d6dc7281ee1f072a316c52fcaff45b6d8a565..27c1e180260cba7974d6fec24869b6f1f21828b1 100644 |
| --- a/tests/stub-generator/test_config.dart |
| +++ b/tests/stub-generator/test_config.dart |
| @@ -7,17 +7,116 @@ |
| #import("../../tools/testing/dart/test_suite.dart"); |
| class StubGeneratorTestSuite extends StandardTestSuite { |
| + String dartcPath; |
| + |
| StubGeneratorTestSuite(Map configuration) |
| : super(configuration, |
| "stub-generator", |
| "tests/stub-generator/src", |
| ["tests/stub-generator/stub-generator.status"]) { |
| - // TODO(ager): Support the stub generation part of this test on |
| - // dartc. |
| - if (configuration["component"] == "dartc") { |
| - print("Warning: stub-generator tests on dartc do not test generation"); |
| + try { |
| + dartcPath = TestUtils.dartcCompilationShellPath(configuration); |
| + } catch (var e) { |
| + // ignore |
| } |
| } |
| - bool isTestFile(String filename) => filename.contains("-generatedTest.dart"); |
| + void combineFiles(String filename, |
| + String stubsFile, |
| + Function onGenerated) { |
| + File orig = new File(filename); |
| + File stubs = new File(stubsFile); |
| + Expect.isTrue(filename.endsWith(".dart")); |
| + String baseName = filename.substring(0, filename.length - 5); |
| + String resultPath = '${baseName}-generatedTest.dart'; |
| + File result = new File(resultPath); |
| + StringInputStream origStream = |
| + new StringInputStream(orig.openInputStream()); |
| + FileOutputStream resultStream = result.openOutputStream(); |
| + |
| + // First copy first comments and imports from original file. |
| + var origLine = origStream.readLine(); |
| + while (origLine != null) { |
| + origLine = origLine.trim(); |
| + if (origLine.isEmpty() || |
| + origLine.startsWith('//') || |
| + origLine.startsWith('#')) { |
| + resultStream.write(origLine.charCodes()); |
| + resultStream.write('\n'.charCodes()); |
| + origLine = origStream.readLine(); |
| + } else { |
| + break; |
| + } |
| + } |
| + |
| + // Then copy in the generated stubs code. |
| + StringInputStream stubsStream = |
| + new StringInputStream(stubs.openInputStream()); |
| + var stubsLine = stubsStream.readLine(); |
| + while (stubsLine != null) { |
| + resultStream.write(stubsLine.charCodes()); |
| + resultStream.write('\n'.charCodes()); |
| + stubsLine = stubsStream.readLine(); |
| + } |
| + |
| + // Then copy in the rest of the original file. |
| + while (origLine != null) { |
| + resultStream.write(origLine.charCodes()); |
| + resultStream.write('\n'.charCodes()); |
| + origLine = origStream.readLine(); |
| + } |
| + |
| + // Done. |
| + resultStream.close(); |
| + onGenerated(resultPath); |
| + } |
| + |
| + void generateTestCase(String filename, |
| + String interfaceFile, |
| + String classes, |
| + Function onGenerated) { |
| + ++activeTestGenerators; |
|
Søren Gjesse
2011/12/06 13:35:32
Should there be a method for this instead of just
Mads Ager (google)
2011/12/06 13:39:31
Done.
|
| + Directory temp = new Directory(''); |
| + temp.createTempSync(); |
| + File stubsOutFile = new File("${temp.path}/${interfaceFile}"); |
| + stubsOutFile.createSync(); |
| + String stubsPath = stubsOutFile.fullPathSync(); |
| + Process dartcProcess = new Process(dartcPath, |
| + [filename, |
| + '-noincremental', |
| + '-out', temp.path, |
| + '-isolate-stub-out', stubsPath, |
| + '-generate-isolate-stubs', classes ]); |
| + dartcProcess.exitHandler = (int exitCode) { |
| + combineFiles(filename, stubsPath, onGenerated); |
| + }; |
| + dartcProcess.start(); |
| + } |
| + |
| + void processFile(String filename) { |
| + // Only run the tests that match the pattern. |
| + RegExp pattern = configuration['selectors'][suiteName]; |
| + if (!pattern.hasMatch(filename)) return; |
| + var optionsFromFile = optionsFromFile(filename); |
| + var timeout = configuration['timeout']; |
| + Function createTestCase = makeTestCaseCreator(optionsFromFile, timeout); |
| + |
| + if (filename.endsWith("-generatedTest.dart")) { |
| + if (dartcPath == null) { |
| + createTestCase(filename, optionsFromFile['isNegative']); |
| + } |
| + } else if (filename.endsWith("Test.dart")) { |
| + if (dartcPath != null) { |
| + String isolateStubsOptions = optionsFromFile['isolateStubs']; |
| + List<String> splitIsolateStubsOptions = isolateStubsOptions.split(':'); |
| + Expect.equals(2, splitIsolateStubsOptions.length); |
| + String interfaceFile = splitIsolateStubsOptions[0]; |
| + String classes = splitIsolateStubsOptions[1]; |
| + generateTestCase(filename, interfaceFile, classes, (String filename) { |
| + createTestCase(filename, optionsFromFile['isNegative']); |
| + testGeneratorDone(); |
| + }); |
| + } |
| + } |
| + } |
| } |