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

Side by Side Diff: tests/standalone/io/test_runner_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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:io"; 5 import "dart:io";
6 import "dart:isolate"; 6 import "dart:isolate";
7 import "dart:async"; 7 import "dart:async";
8 import "../../../tools/testing/dart/test_runner.dart"; 8 import "../../../tools/testing/dart/test_runner.dart";
9 import "../../../tools/testing/dart/test_suite.dart"; 9 import "../../../tools/testing/dart/test_suite.dart";
10 import "../../../tools/testing/dart/test_progress.dart" as progress; 10 import "../../../tools/testing/dart/test_progress.dart" as progress;
(...skipping 23 matching lines...) Expand all
34 numCompletedTests++; 34 numCompletedTests++;
35 if (testCase.displayName == "fail-unexpected") { 35 if (testCase.displayName == "fail-unexpected") {
36 if (!testCase.unexpectedOutput) { 36 if (!testCase.unexpectedOutput) {
37 var stdout = 37 var stdout =
38 new String.fromCharCodes(testCase.lastCommandOutput.stdout); 38 new String.fromCharCodes(testCase.lastCommandOutput.stdout);
39 var stderr = 39 var stderr =
40 new String.fromCharCodes(testCase.lastCommandOutput.stderr); 40 new String.fromCharCodes(testCase.lastCommandOutput.stderr);
41 print("stdout = [$stdout]"); 41 print("stdout = [$stdout]");
42 print("stderr = [$stderr]"); 42 print("stderr = [$stderr]");
43 throw "Test case ${testCase.displayName} passed unexpectedly, " 43 throw "Test case ${testCase.displayName} passed unexpectedly, "
44 "result == ${testCase.result}"; 44 "result == ${testCase.result}";
45 } 45 }
46 } else { 46 } else {
47 if (testCase.unexpectedOutput) { 47 if (testCase.unexpectedOutput) {
48 var stdout = 48 var stdout =
49 new String.fromCharCodes(testCase.lastCommandOutput.stdout); 49 new String.fromCharCodes(testCase.lastCommandOutput.stdout);
50 var stderr = 50 var stderr =
51 new String.fromCharCodes(testCase.lastCommandOutput.stderr); 51 new String.fromCharCodes(testCase.lastCommandOutput.stderr);
52 print("stdout = [$stdout]"); 52 print("stdout = [$stdout]");
53 print("stderr = [$stderr]"); 53 print("stderr = [$stderr]");
54 throw "Test case ${testCase.displayName} failed, " 54 throw "Test case ${testCase.displayName} failed, "
55 "result == ${testCase.result}"; 55 "result == ${testCase.result}";
56 } 56 }
57 } 57 }
58 } 58 }
59 59
60 static void finished() { 60 static void finished() {
61 if (numTests != numCompletedTests) { 61 if (numTests != numCompletedTests) {
62 throw "bad completion count. " 62 throw "bad completion count. "
63 "expected: $numTests, actual: $numCompletedTests"; 63 "expected: $numTests, actual: $numCompletedTests";
64 } 64 }
65 } 65 }
66 } 66 }
67 67
68
69 class CustomTestSuite extends TestSuite { 68 class CustomTestSuite extends TestSuite {
70 CustomTestSuite(Map configuration) : super(configuration, "CustomTestSuite"); 69 CustomTestSuite(Map configuration) : super(configuration, "CustomTestSuite");
71 70
72 void forEachTest(TestCaseEvent onTest, Map testCache, [onDone]) { 71 void forEachTest(TestCaseEvent onTest, Map testCache, [onDone]) {
73 void enqueueTestCase(testCase) { 72 void enqueueTestCase(testCase) {
74 TestController.numTests++; 73 TestController.numTests++;
75 onTest(testCase); 74 onTest(testCase);
76 } 75 }
77 76
78 var testCaseCrash = _makeCrashTestCase("crash", [Expectation.CRASH]); 77 var testCaseCrash = _makeCrashTestCase("crash", [Expectation.CRASH]);
(...skipping 10 matching lines...) Expand all
89 enqueueTestCase(testCaseFailUnexpected); 88 enqueueTestCase(testCaseFailUnexpected);
90 89
91 if (onDone != null) { 90 if (onDone != null) {
92 onDone(); 91 onDone();
93 } 92 }
94 } 93 }
95 94
96 TestCase _makeNormalTestCase(name, expectations) { 95 TestCase _makeNormalTestCase(name, expectations) {
97 var args = packageOptions(); 96 var args = packageOptions();
98 args.addAll([Platform.script.toFilePath(), name]); 97 args.addAll([Platform.script.toFilePath(), name]);
99 var command = CommandBuilder.instance.getProcessCommand( 98 var command = CommandBuilder.instance
100 'custom', Platform.executable, 99 .getProcessCommand('custom', Platform.executable, args, {});
101 args,
102 {});
103 return _makeTestCase(name, DEFAULT_TIMEOUT, command, expectations); 100 return _makeTestCase(name, DEFAULT_TIMEOUT, command, expectations);
104 } 101 }
105 102
106 _makeCrashTestCase(name, expectations) { 103 _makeCrashTestCase(name, expectations) {
107 var crashCommand = CommandBuilder.instance.getProcessCommand( 104 var crashCommand = CommandBuilder.instance.getProcessCommand(
108 'custom_crash', getProcessTestFileName(), ["0", "0", "1", "1"], 105 'custom_crash', getProcessTestFileName(), ["0", "0", "1", "1"], {});
109 {});
110 // The crash test sometimes times out. Run it with a large timeout 106 // The crash test sometimes times out. Run it with a large timeout
111 // to help diagnose the delay. 107 // to help diagnose the delay.
112 // The test loads a new executable, which may sometimes take a long time. 108 // The test loads a new executable, which may sometimes take a long time.
113 // It involves a wait on the VM event loop, and possible system 109 // It involves a wait on the VM event loop, and possible system
114 // delays. 110 // delays.
115 return _makeTestCase(name, LONG_TIMEOUT, crashCommand, expectations); 111 return _makeTestCase(name, LONG_TIMEOUT, crashCommand, expectations);
116 } 112 }
117 113
118 _makeTestCase(name, timeout, command, expectations) { 114 _makeTestCase(name, timeout, command, expectations) {
119 var configuration = new TestOptionsParser() 115 var configuration =
120 .parse(['--timeout', '$timeout'])[0]; 116 new TestOptionsParser().parse(['--timeout', '$timeout'])[0];
121 return new TestCase(name, 117 return new TestCase(name, [command], configuration,
122 [command], 118 new Set<Expectation>.from(expectations));
123 configuration,
124 new Set<Expectation>.from(expectations));
125 } 119 }
126 } 120 }
127 121
128 void testProcessQueue() { 122 void testProcessQueue() {
129 var maxProcesses = 2; 123 var maxProcesses = 2;
130 var maxBrowserProcesses = maxProcesses; 124 var maxBrowserProcesses = maxProcesses;
131 var config = new TestOptionsParser().parse(['--nobatch'])[0]; 125 var config = new TestOptionsParser().parse(['--nobatch'])[0];
132 new ProcessQueue(config, maxProcesses, maxBrowserProcesses, 126 new ProcessQueue(
133 new DateTime.now(), [new CustomTestSuite(config)], 127 config,
134 [new EventListener()], TestController.finished); 128 maxProcesses,
129 maxBrowserProcesses,
130 new DateTime.now(),
131 [new CustomTestSuite(config)],
132 [new EventListener()],
133 TestController.finished);
135 } 134 }
136 135
137 class EventListener extends progress.EventListener{ 136 class EventListener extends progress.EventListener {
138 void done(TestCase test) { 137 void done(TestCase test) {
139 TestController.processCompletedTest(test); 138 TestController.processCompletedTest(test);
140 } 139 }
141 } 140 }
142 141
143 void main(List<String> arguments) { 142 void main(List<String> arguments) {
144 // This script is in [sdk]/tests/standalone/io. 143 // This script is in [sdk]/tests/standalone/io.
145 TestUtils.setDartDirUri(Platform.script.resolve('../../..')); 144 TestUtils.setDartDirUri(Platform.script.resolve('../../..'));
146 // Run the test_runner_test if there are no command-line options. 145 // Run the test_runner_test if there are no command-line options.
147 // Otherwise, run one of the component tests that always pass, 146 // Otherwise, run one of the component tests that always pass,
148 // fail, or timeout. 147 // fail, or timeout.
149 if (arguments.isEmpty) { 148 if (arguments.isEmpty) {
150 testProcessQueue(); 149 testProcessQueue();
151 } else { 150 } else {
152 switch (arguments[0]) { 151 switch (arguments[0]) {
153 case 'pass': 152 case 'pass':
154 return; 153 return;
155 case 'fail-unexpected': 154 case 'fail-unexpected':
156 case 'fail': 155 case 'fail':
157 throw "This test always fails, to test the test scripts."; 156 throw "This test always fails, to test the test scripts.";
158 break; 157 break;
159 case 'timeout': 158 case 'timeout':
160 // This process should be killed by the test after DEFAULT_TIMEOUT 159 // This process should be killed by the test after DEFAULT_TIMEOUT
161 new Timer(new Duration(hours: 42), (){ }); 160 new Timer(new Duration(hours: 42), () {});
162 break; 161 break;
163 default: 162 default:
164 throw "Unknown option ${arguments[0]} passed to test_runner_test"; 163 throw "Unknown option ${arguments[0]} passed to test_runner_test";
165 } 164 }
166 } 165 }
167 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698