| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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("../../../../tools/testing/dart/test_runner.dart"); | 6 #import("../../../tools/testing/dart/test_runner.dart"); |
| 7 #import("../../../../tools/testing/dart/status_file_parser.dart"); | 7 #import("../../../tools/testing/dart/status_file_parser.dart"); |
| 8 #import("../../../../tools/testing/dart/test_options.dart"); | 8 #import("../../../tools/testing/dart/test_options.dart"); |
| 9 #source("ProcessTestUtil.dart"); | 9 #source("process_test_util.dart"); |
| 10 | 10 |
| 11 class TestController { | 11 class TestController { |
| 12 static final int numTests = 4; | 12 static final int numTests = 4; |
| 13 static int numCompletedTests = 0; | 13 static int numCompletedTests = 0; |
| 14 | 14 |
| 15 // Used as TestCase.completedCallback. | 15 // Used as TestCase.completedCallback. |
| 16 static processCompletedTest(TestCase testCase) { | 16 static processCompletedTest(TestCase testCase) { |
| 17 TestOutput output = testCase.output; | 17 TestOutput output = testCase.output; |
| 18 print("Test: ${testCase.commands.last().commandLine}"); | 18 print("Test: ${testCase.commands.last().commandLine}"); |
| 19 if (output.unexpectedOutput) { | 19 if (output.unexpectedOutput) { |
| 20 throw "Unexpected output: ${output.result}"; | 20 throw "Unexpected output: ${output.result}"; |
| 21 } | 21 } |
| 22 print("stdout: "); | 22 print("stdout: "); |
| 23 for (var line in output.stdout) print(line); | 23 for (var line in output.stdout) print(line); |
| 24 print("stderr: "); | 24 print("stderr: "); |
| 25 for (var line in output.stderr) print(line); | 25 for (var line in output.stderr) print(line); |
| 26 | 26 |
| 27 print("Time: ${output.time}"); | 27 print("Time: ${output.time}"); |
| 28 print("Exit code: ${output.exitCode}"); | 28 print("Exit code: ${output.exitCode}"); |
| 29 | 29 |
| 30 ++numCompletedTests; | 30 ++numCompletedTests; |
| 31 print("$numCompletedTests/$numTests"); | 31 print("$numCompletedTests/$numTests"); |
| 32 if (numCompletedTests == numTests) { | 32 if (numCompletedTests == numTests) { |
| 33 print("TestRunnerTest.dart PASSED"); | 33 print("test_runner_test.dart PASSED"); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 TestCase MakeTestCase(String testName, List<String> expectations) { | 39 TestCase MakeTestCase(String testName, List<String> expectations) { |
| 40 String test_path = "tests/standalone/src/${testName}.dart"; | 40 String test_path = "tests/standalone/${testName}.dart"; |
| 41 // Working directory may be dart/runtime rather than dart. | 41 // Working directory may be dart/runtime rather than dart. |
| 42 if (!new File(test_path).existsSync()) { | 42 if (!new File(test_path).existsSync()) { |
| 43 test_path = "../tests/standalone/src/${testName}.dart"; | 43 test_path = "../tests/standalone/${testName}.dart"; |
| 44 } | 44 } |
| 45 | 45 |
| 46 var configuration = new TestOptionsParser().parse(['--timeout', '2'])[0]; | 46 var configuration = new TestOptionsParser().parse(['--timeout', '2'])[0]; |
| 47 return new TestCase(testName, | 47 return new TestCase(testName, |
| 48 [new Command(getDartFileName(), | 48 [new Command(getDartFileName(), |
| 49 <String>["--ignore-unrecognized-flags", | 49 <String>["--ignore-unrecognized-flags", |
| 50 "--enable_type_checks", | 50 "--enable_type_checks", |
| 51 test_path])], | 51 test_path])], |
| 52 configuration, | 52 configuration, |
| 53 TestController.processCompletedTest, | 53 TestController.processCompletedTest, |
| 54 new Set<String>.from(expectations)); | 54 new Set<String>.from(expectations)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 void main() { | 58 void main() { |
| 59 new RunningProcess(MakeTestCase("PassTest", [PASS])).start(); | 59 new RunningProcess(MakeTestCase("pass_test", [PASS])).start(); |
| 60 new RunningProcess(MakeTestCase("FailTest", [FAIL])).start(); | 60 new RunningProcess(MakeTestCase("fail_test", [FAIL])).start(); |
| 61 new RunningProcess(MakeTestCase("TimeoutTest", [TIMEOUT])).start(); | 61 new RunningProcess(MakeTestCase("timeout_test", [TIMEOUT])).start(); |
| 62 | 62 |
| 63 // The crash test sometimes times out. Run it with a large timeout to help | 63 // The crash test sometimes times out. Run it with a large timeout to help |
| 64 // diagnose the delay. | 64 // diagnose the delay. |
| 65 // The test loads a new executable, which may sometimes take a long time. | 65 // The test loads a new executable, which may sometimes take a long time. |
| 66 // It involves a wait on the VM event loop, and possible system delays. | 66 // It involves a wait on the VM event loop, and possible system delays. |
| 67 var configuration = new TestOptionsParser().parse(['--timeout', '60'])[0]; | 67 var configuration = new TestOptionsParser().parse(['--timeout', '60'])[0]; |
| 68 new RunningProcess(new TestCase("CrashTest", | 68 new RunningProcess(new TestCase("CrashTest", |
| 69 [new Command(getProcessTestFileName(), | 69 [new Command(getProcessTestFileName(), |
| 70 const ["0", "0", "1", "1"])], | 70 const ["0", "0", "1", "1"])], |
| 71 configuration, | 71 configuration, |
| 72 TestController.processCompletedTest, | 72 TestController.processCompletedTest, |
| 73 new Set<String>.from([CRASH]))).start(); | 73 new Set<String>.from([CRASH]))).start(); |
| 74 Expect.equals(4, TestController.numTests); | 74 Expect.equals(4, TestController.numTests); |
| 75 // Throw must be from body of start() function for this test to work. | 75 // Throw must be from body of start() function for this test to work. |
| 76 Expect.throws(new RunningProcess(MakeTestCase("PassTest", [SKIP])).start); | 76 Expect.throws(new RunningProcess(MakeTestCase("pass_test", [SKIP])).start); |
| 77 } | 77 } |
| OLD | NEW |