mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 05:33:14 +00:00
Add asynchronous test suite runner to Dart rewrite of test scripts.
BUG= TEST= Review URL: http://codereview.chromium.org//8492013 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1316 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
e25f373799
commit
70da4ae316
59
tests/corelib/test_config.dart
Normal file
59
tests/corelib/test_config.dart
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#library("corelib_test_config");
|
||||
|
||||
#import("../../tools/testing/dart/test_runner.dart");
|
||||
|
||||
class CorelibTestSuite {
|
||||
final String directoryPath = "tests/corelib/src";
|
||||
Function doTest;
|
||||
Function doDone;
|
||||
String shellPath;
|
||||
String pathSeparator;
|
||||
|
||||
CorelibTestSuite() {
|
||||
shellPath = getDartShellFileName() ;
|
||||
pathSeparator = new Platform().pathSeparator();
|
||||
}
|
||||
|
||||
void forEachTest(Function onTest, [Function onDone = null]) {
|
||||
doTest = onTest;
|
||||
doDone = onDone;
|
||||
processDirectory();
|
||||
}
|
||||
|
||||
void processDirectory() {
|
||||
Directory dir = new Directory(directoryPath);
|
||||
if (!dir.existsSync()) {
|
||||
dir = new Directory(".." + pathSeparator + directoryPath);
|
||||
Expect.isTrue(dir.existsSync(),
|
||||
"Cannot find tests/corelib/src or ../tests/corelib/src");
|
||||
// TODO(ager): Use dir.errorHandler instead when it is implemented.
|
||||
}
|
||||
dir.fileHandler = processFile;
|
||||
dir.doneHandler = doDone;
|
||||
dir.list(false);
|
||||
}
|
||||
|
||||
void processFile(String filename) {
|
||||
if (filename.endsWith("Test.dart")) {
|
||||
int start = filename.lastIndexOf(pathSeparator);
|
||||
String displayName = filename.substring(start + 1, filename.length - 5);
|
||||
// TODO(whesse): Gather test case info from status file and test file.
|
||||
doTest(new TestCase(displayName,
|
||||
shellPath,
|
||||
<String>["--enable_type_checks",
|
||||
"--ignore-unrecognized-flags",
|
||||
filename ],
|
||||
completeHandler,
|
||||
new Set.from([PASS, FAIL, CRASH, TIMEOUT])));
|
||||
}
|
||||
}
|
||||
|
||||
void completeHandler(TestCase testCase) {
|
||||
TestOutput output = testCase.output;
|
||||
print("Exit code: ${output.exitCode} Time: ${output.time}");
|
||||
}
|
||||
}
|
|
@ -44,7 +44,8 @@ TestCase MakeTestCase(String testName, List<String> expectations) {
|
|||
test_path = "../tests/standalone/src/${testName}.dart";
|
||||
}
|
||||
|
||||
return new TestCase(getDartShellFileName(),
|
||||
return new TestCase(testName,
|
||||
getDartShellFileName(),
|
||||
<String>["--ignore-unrecognized-flags",
|
||||
"--enable_type_checks",
|
||||
test_path],
|
||||
|
@ -73,7 +74,8 @@ void main() {
|
|||
new RunningProcess(MakeTestCase("FailTest", [FAIL]), timeout).start();
|
||||
new RunningProcess(MakeTestCase("TimeoutTest", [TIMEOUT]), timeout).start();
|
||||
|
||||
new RunningProcess(new TestCase(getProcessTestFileName(),
|
||||
new RunningProcess(new TestCase("CrashTest",
|
||||
getProcessTestFileName(),
|
||||
const ["0", "0", "1", "1"],
|
||||
TestController.processCompletedTest,
|
||||
new Set<String>.from([CRASH])),
|
||||
|
|
59
tests/standalone/test_config.dart
Normal file
59
tests/standalone/test_config.dart
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#library("standalone_test_config");
|
||||
|
||||
#import("../../tools/testing/dart/test_runner.dart");
|
||||
|
||||
class StandaloneTestSuite {
|
||||
final String directoryPath = "tests/standalone/src";
|
||||
Function doTest;
|
||||
Function doDone;
|
||||
String shellPath;
|
||||
String pathSeparator;
|
||||
|
||||
StandaloneTestSuite() {
|
||||
shellPath = getDartShellFileName() ;
|
||||
pathSeparator = new Platform().pathSeparator();
|
||||
}
|
||||
|
||||
void forEachTest(Function onTest, [Function onDone = null]) {
|
||||
doTest = onTest;
|
||||
doDone = onDone;
|
||||
processDirectory();
|
||||
}
|
||||
|
||||
void processDirectory() {
|
||||
Directory dir = new Directory(directoryPath);
|
||||
if (!dir.existsSync()) {
|
||||
dir = new Directory(".." + pathSeparator + directoryPath);
|
||||
Expect.isTrue(dir.existsSync(),
|
||||
"Cannot find tests/corelib/src or ../tests/corelib/src");
|
||||
// TODO(ager): Use dir.errorHandler instead when it is implemented.
|
||||
}
|
||||
dir.fileHandler = processFile;
|
||||
dir.doneHandler = doDone;
|
||||
dir.list(false);
|
||||
}
|
||||
|
||||
void processFile(String filename) {
|
||||
if (filename.endsWith("Test.dart")) {
|
||||
int start = filename.lastIndexOf(pathSeparator);
|
||||
String displayName = filename.substring(start + 1, filename.length - 5);
|
||||
// TODO(whesse): Gather test case info from status file and test file.
|
||||
doTest(new TestCase(displayName,
|
||||
shellPath,
|
||||
<String>["--enable_type_checks",
|
||||
"--ignore-unrecognized-flags",
|
||||
filename ],
|
||||
completeHandler,
|
||||
new Set.from([PASS, FAIL, CRASH, TIMEOUT])));
|
||||
}
|
||||
}
|
||||
|
||||
void completeHandler(TestCase testCase) {
|
||||
TestOutput output = testCase.output;
|
||||
print("Exit code: ${output.exitCode} Time: ${output.time}");
|
||||
}
|
||||
}
|
17
tools/test.dart
Executable file
17
tools/test.dart
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env dart_bin
|
||||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#library("test");
|
||||
|
||||
#import("testing/dart/test_runner.dart");
|
||||
#import("../tests/standalone/test_config.dart");
|
||||
#import("../tests/corelib/test_config.dart");
|
||||
|
||||
main() {
|
||||
int numProcessors = new Platform().numberOfProcessors();
|
||||
var queue = new ProcessQueue(numProcessors);
|
||||
new StandaloneTestSuite().forEachTest(queue.runTest);
|
||||
new CorelibTestSuite().forEachTest(queue.runTest);
|
||||
}
|
|
@ -23,6 +23,8 @@ final PASS = "Pass";
|
|||
// An indication to skip the test. The caller is responsible for skipping it.
|
||||
final SKIP = "Skip";
|
||||
|
||||
final int NO_TIMEOUT = 0;
|
||||
|
||||
String getDartShellFileName() {
|
||||
var names = ["out/Debug_ia32/dart_bin",
|
||||
"out/Release_ia32/dart_bin",
|
||||
|
@ -43,11 +45,12 @@ class TestCase {
|
|||
String executablePath;
|
||||
List<String> arguments;
|
||||
String commandLine;
|
||||
String displayName;
|
||||
TestOutput output;
|
||||
Set<String> expectedOutcomes;
|
||||
Function completedHandler;
|
||||
|
||||
TestCase(this.executablePath, this.arguments,
|
||||
TestCase(this.displayName, this.executablePath, this.arguments,
|
||||
this.completedHandler, this.expectedOutcomes) {
|
||||
commandLine = executablePath;
|
||||
for (var arg in arguments) {
|
||||
|
@ -103,7 +106,6 @@ class RunningProcess {
|
|||
List<String> stderr;
|
||||
List<Function> handlers;
|
||||
|
||||
static final int NO_TIMEOUT = 0;
|
||||
|
||||
RunningProcess(this.testCase, [this.timeout = NO_TIMEOUT]);
|
||||
|
||||
|
@ -154,3 +156,36 @@ class RunningProcess {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
class ProcessQueue {
|
||||
int numProcesses = 0;
|
||||
final int maxProcesses;
|
||||
Queue<TestCase> tests;
|
||||
|
||||
ProcessQueue(this.maxProcesses) : tests = new Queue<TestCase>();
|
||||
|
||||
tryRunTest() {
|
||||
if (numProcesses < maxProcesses && !tests.isEmpty()) {
|
||||
TestCase test = tests.removeFirst();
|
||||
print("running ${test.displayName}");
|
||||
// TODO(whesse): Refactor into various test output methods.
|
||||
Function old_callback = test.completedHandler;
|
||||
Function wrapper = (TestCase test_arg) {
|
||||
numProcesses--;
|
||||
print("finished ${test_arg.displayName}");
|
||||
tryRunTest();
|
||||
old_callback(test_arg);
|
||||
};
|
||||
test.completedHandler = wrapper;
|
||||
|
||||
// TODO(whesse): Add timeout information to TestCase, use it here.
|
||||
new RunningProcess(test, 60).start();
|
||||
numProcesses++;
|
||||
}
|
||||
}
|
||||
|
||||
runTest(TestCase test) {
|
||||
tests.add(test);
|
||||
tryRunTest();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue