| 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("TestRunnerTest"); | 5 #library("TestRunnerTest"); |
| 6 | 6 |
| 7 #import("../../../tools/testing/dart/test_runner.dart"); | 7 #import("../../../tools/testing/dart/test_runner.dart"); |
| 8 #import("../../../tools/testing/dart/status_file_parser.dart"); | 8 #import("../../../tools/testing/dart/status_file_parser.dart"); |
| 9 #source("ProcessTestUtil.dart"); | 9 #source("ProcessTestUtil.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.commandLine}"); | 18 print("Test: ${testCase.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("TestRunnerTest.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/src/${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/src/${testName}.dart"; |
| 44 } | 44 } |
| 45 | 45 |
| 46 var timeout = 2; | 46 var timeout = 2; |
| 47 return new TestCase(testName, | 47 return new TestCase(testName, |
| 48 getDartBinName(), | 48 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 timeout, | 52 timeout, |
| 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 String getDartBinName() { | |
| 59 var os = new Platform().operatingSystem(); | |
| 60 | |
| 61 var outDir = ''; | |
| 62 if (os == 'linux') { | |
| 63 outDir = 'out'; | |
| 64 } else if (os == 'macos') { | |
| 65 outDir = 'xcodebuild'; | |
| 66 } | |
| 67 | |
| 68 var names = ['$outDir/Debug_ia32/dart', | |
| 69 '$outDir/Release_ia32/dart']; | |
| 70 | |
| 71 for (var name in names) { | |
| 72 if (new File(name).existsSync()) { | |
| 73 return name; | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 | |
| 79 void main() { | 58 void main() { |
| 80 int timeout = 2; | 59 int timeout = 2; |
| 81 new RunningProcess(MakeTestCase("PassTest", [PASS]), timeout).start(); | 60 new RunningProcess(MakeTestCase("PassTest", [PASS]), timeout).start(); |
| 82 new RunningProcess(MakeTestCase("FailTest", [FAIL]), timeout).start(); | 61 new RunningProcess(MakeTestCase("FailTest", [FAIL]), timeout).start(); |
| 83 new RunningProcess(MakeTestCase("TimeoutTest", [TIMEOUT]), timeout).start(); | 62 new RunningProcess(MakeTestCase("TimeoutTest", [TIMEOUT]), timeout).start(); |
| 84 | 63 |
| 85 new RunningProcess(new TestCase("CrashTest", | 64 new RunningProcess(new TestCase("CrashTest", |
| 86 getProcessTestFileName(), | 65 getProcessTestFileName(), |
| 87 const ["0", "0", "1", "1"], | 66 const ["0", "0", "1", "1"], |
| 88 timeout, | 67 timeout, |
| 89 TestController.processCompletedTest, | 68 TestController.processCompletedTest, |
| 90 new Set<String>.from([CRASH])), | 69 new Set<String>.from([CRASH])), |
| 91 timeout).start(); | 70 timeout).start(); |
| 92 Expect.equals(4, TestController.numTests); | 71 Expect.equals(4, TestController.numTests); |
| 93 // Throw must be from body of start() function for this test to work. | 72 // Throw must be from body of start() function for this test to work. |
| 94 Expect.throws( | 73 Expect.throws( |
| 95 new RunningProcess(MakeTestCase("PassTest", [SKIP]), timeout).start); | 74 new RunningProcess(MakeTestCase("PassTest", [SKIP]), timeout).start); |
| 96 } | 75 } |
| 97 | 76 |
| OLD | NEW |