| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #library("test_runner"); | 5 #library("test_runner"); |
| 6 | 6 |
| 7 #import("status_file_parser.dart"); | 7 #import("status_file_parser.dart"); |
| 8 #import("test_progress.dart"); | 8 #import("test_progress.dart"); |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 bool isNegative; | 28 bool isNegative; |
| 29 Set<String> expectedOutcomes; | 29 Set<String> expectedOutcomes; |
| 30 Function completedHandler; | 30 Function completedHandler; |
| 31 | 31 |
| 32 TestCase(this.displayName, | 32 TestCase(this.displayName, |
| 33 this.executablePath, | 33 this.executablePath, |
| 34 this.arguments, | 34 this.arguments, |
| 35 this.timeout, | 35 this.timeout, |
| 36 this.completedHandler, | 36 this.completedHandler, |
| 37 this.expectedOutcomes, | 37 this.expectedOutcomes, |
| 38 [this.isNegative = false]) { | 38 [isNegative = false]) |
| 39 : this.isNegative = isNegative { |
| 39 if (!isNegative) { | 40 if (!isNegative) { |
| 40 isNegative = displayName.contains("NegativeTest"); | 41 isNegative = displayName.contains("NegativeTest"); |
| 41 } | 42 } |
| 42 commandLine = executablePath; | 43 commandLine = executablePath; |
| 43 for (var arg in arguments) { | 44 for (var arg in arguments) { |
| 44 commandLine += " " + arg; | 45 commandLine += " " + arg; |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 void completed() { completedHandler(this); } | 49 void completed() { completedHandler(this); } |
| 49 } | 50 } |
| 50 | 51 |
| 51 | 52 |
| 52 class TestOutput { | 53 class TestOutput { |
| 53 // The TestCase this is the output from. | 54 // The TestCase this is the output from. |
| 54 TestCase testCase; | 55 TestCase testCase; |
| 55 int exitCode; | 56 int exitCode; |
| 56 bool timedOut; | 57 bool timedOut; |
| 57 bool failed = false; | 58 bool failed = false; |
| 58 List<String> stdout; | 59 List<String> stdout; |
| 59 List<String> stderr; | 60 List<String> stderr; |
| 60 Duration time; | 61 Duration time; |
| 61 | 62 |
| 62 TestOutput(this.testCase, this.exitCode, this.timedOut, this.stdout, | 63 TestOutput(this.testCase, this.exitCode, this.timedOut, this.stdout, |
| 63 this.stderr, this.time) { | 64 this.stderr, this.time) { |
| 64 testCase.output = this; | 65 testCase.output = this; |
| 65 } | 66 } |
| 66 | 67 |
| 67 String get result() => | 68 String get result() => |
| 68 hasCrashed ? CRASH : (hasTimedOut ? TIMEOUT : (hasFailed ? FAIL : PASS)); | 69 hasCrashed ? CRASH : (hasTimedOut ? TIMEOUT : (hasFailed ? FAIL : PASS)); |
| 69 | 70 |
| 70 bool get unexpectedOutput() => !testCase.expectedOutcomes.contains(result); | 71 bool get unexpectedOutput() => !testCase.expectedOutcomes.contains(result); |
| 71 | 72 |
| 72 // The Java dartc runner exits with code 253 in case of unhandles | 73 // The Java dartc runner exits with code 253 in case of unhandles |
| 73 // exceptions. | 74 // exceptions. |
| 74 // The VM uses std::abort to terminate on asserts. | 75 // The VM uses std::abort to terminate on asserts. |
| 75 // std::abort terminates with exit code 3 on Windows. | 76 // std::abort terminates with exit code 3 on Windows. |
| 76 bool get hasCrashed() { | 77 bool get hasCrashed() { |
| 77 if (new Platform().operatingSystem() == 'windows') { | 78 if (new Platform().operatingSystem() == 'windows') { |
| 78 if (exitCode == 3) { | 79 if (exitCode == 3) { |
| 79 return !timedOut; | 80 return !timedOut; |
| 80 } | 81 } |
| 81 return (!timedOut && | 82 return (!timedOut && |
| (...skipping 19 matching lines...) Expand all Loading... |
| 101 Process process; | 102 Process process; |
| 102 TestCase testCase; | 103 TestCase testCase; |
| 103 int timeout; | 104 int timeout; |
| 104 bool timedOut = false; | 105 bool timedOut = false; |
| 105 Date startTime; | 106 Date startTime; |
| 106 Timer timeoutTimer; | 107 Timer timeoutTimer; |
| 107 List<String> stdout; | 108 List<String> stdout; |
| 108 List<String> stderr; | 109 List<String> stderr; |
| 109 List<Function> handlers; | 110 List<Function> handlers; |
| 110 | 111 |
| 111 RunningProcess(this.testCase, [this.timeout = NO_TIMEOUT]); | 112 RunningProcess(this.testCase, [timeout = NO_TIMEOUT]) |
| 113 : this.timeout = timeout; |
| 112 | 114 |
| 113 void exitHandler(int exitCode) { | 115 void exitHandler(int exitCode) { |
| 114 new TestOutput(testCase, exitCode, timedOut, stdout, | 116 new TestOutput(testCase, exitCode, timedOut, stdout, |
| 115 stderr, new Date.now().difference(startTime)); | 117 stderr, new Date.now().difference(startTime)); |
| 116 process.close(); | 118 process.close(); |
| 117 timeoutTimer.cancel(); | 119 timeoutTimer.cancel(); |
| 118 testCase.completed(); | 120 testCase.completed(); |
| 119 } | 121 } |
| 120 | 122 |
| 121 void makeReadHandler(StringInputStream source, List<String> destination) { | 123 void makeReadHandler(StringInputStream source, List<String> destination) { |
| 122 return () { | 124 return () { |
| 123 if (source.closed) return; // TODO(whesse): Remove when bug is fixed. | 125 if (source.closed) return; // TODO(whesse): Remove when bug is fixed. |
| 124 var line = source.readLine(); | 126 var line = source.readLine(); |
| 125 while (null != line) { | 127 while (null != line) { |
| 126 destination.add(line); | 128 destination.add(line); |
| 127 line = source.readLine(); | 129 line = source.readLine(); |
| 128 } | 130 } |
| 129 }; | 131 }; |
| 130 } | 132 } |
| 131 | 133 |
| 132 void start() { | 134 void start() { |
| 133 Expect.isFalse(testCase.expectedOutcomes.contains(SKIP)); | 135 Expect.isFalse(testCase.expectedOutcomes.contains(SKIP)); |
| 134 process = new Process(testCase.executablePath, testCase.arguments); | 136 process = new Process(testCase.executablePath, testCase.arguments); |
| 135 process.exitHandler = exitHandler; | 137 process.exitHandler = exitHandler; |
| 136 startTime = new Date.now(); | 138 startTime = new Date.now(); |
| 137 process.start(); | 139 process.start(); |
| 138 | 140 |
| 139 InputStream stdoutStream = process.stdout; | 141 InputStream stdoutStream = process.stdout; |
| 140 InputStream stderrStream = process.stderr; | 142 InputStream stderrStream = process.stderr; |
| 141 stdout = new List<String>(); | 143 stdout = new List<String>(); |
| 142 stderr = new List<String>(); | 144 stderr = new List<String>(); |
| 143 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); | 145 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); |
| 144 StringInputStream stderrStringStream = new StringInputStream(stderrStream); | 146 StringInputStream stderrStringStream = new StringInputStream(stderrStream); |
| 145 stdoutStringStream.dataHandler = | 147 stdoutStringStream.dataHandler = |
| 146 makeReadHandler(stdoutStringStream, stdout); | 148 makeReadHandler(stdoutStringStream, stdout); |
| 147 stderrStringStream.dataHandler = | 149 stderrStringStream.dataHandler = |
| 148 makeReadHandler(stderrStringStream, stderr); | 150 makeReadHandler(stderrStringStream, stderr); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 numProcesses++; | 194 numProcesses++; |
| 193 } | 195 } |
| 194 } | 196 } |
| 195 | 197 |
| 196 runTest(TestCase test) { | 198 runTest(TestCase test) { |
| 197 progress.testAdded(); | 199 progress.testAdded(); |
| 198 tests.add(test); | 200 tests.add(test); |
| 199 tryRunTest(); | 201 tryRunTest(); |
| 200 } | 202 } |
| 201 } | 203 } |
| OLD | NEW |