Chromium Code Reviews| Index: tools/testing/dart/test_runner.dart |
| diff --git a/tools/testing/dart/test_runner.dart b/tools/testing/dart/test_runner.dart |
| index 482b7fdd6389b6c58d0c1f3883282fc7496af6b9..23e6456aea318ac9222a21dd4a385e5a4843981f 100644 |
| --- a/tools/testing/dart/test_runner.dart |
| +++ b/tools/testing/dart/test_runner.dart |
| @@ -72,10 +72,10 @@ class TestCase { |
| * multiple sources that are run in isolation. |
| */ |
| List<Command> commands; |
| + Map<Command,CommandOutput> commandOutputs = new Map<Command,CommandOutput>(); |
|
ricow1
2012/11/14 16:59:53
space after ,
kustermann
2012/11/14 17:41:22
Done.
|
| Map configuration; |
| String displayName; |
| - TestOutput output; |
| bool isNegative; |
| Set<String> expectedOutcomes; |
| TestCaseEvent completedHandler; |
| @@ -144,6 +144,19 @@ class TestCase { |
| } |
| } |
| + CommandOutput get lastCommandOutput { |
| + // Note: If commands = [cmd1, cmd2, cmd3] and cmd2 fails then |
| + // commandOutputs contains only outputs for cmd1 and cmd2. |
|
ricow1
2012/11/14 16:59:53
you could just do
return commandOutputs[commands[c
kustermann
2012/11/14 17:41:22
Done.
|
| + var i = commands.length-1; |
| + while (i>=0) { |
|
ricow1
2012/11/14 16:59:53
spaces around >=
kustermann
2012/11/14 17:41:22
This code is now removed!
On 2012/11/14 16:59:53,
|
| + if (commandOutputs.containsKey(commands[i])) { |
| + return commandOutputs[commands[i]]; |
| + } |
| + i--; |
| + } |
| + throw new Exception("CommandOutputs is empty, maybe no command was run?"); |
| + } |
| + |
| int get timeout { |
| if (expectedOutcomes.contains(SLOW)) { |
| return configuration['timeout'] * SLOW_TIMEOUT_MULTIPLIER; |
| @@ -244,16 +257,17 @@ class BrowserTestCase extends TestCase { |
| * the time the process took to run. It also contains a pointer to the |
| * [TestCase] this is the output of. |
| */ |
| -abstract class TestOutput { |
| - factory TestOutput.fromCase(TestCase testCase, |
| - int exitCode, |
| - bool incomplete, |
| - bool timedOut, |
| - List<String> stdout, |
| - List<String> stderr, |
| - Duration time) { |
| - return new TestOutputImpl.fromCase( |
| - testCase, exitCode, incomplete, timedOut, stdout, stderr, time); |
| +abstract class CommandOutput { |
| + factory CommandOutput.fromCase(TestCase testCase, |
| + Command command, |
| + int exitCode, |
| + bool incomplete, |
| + bool timedOut, |
| + List<String> stdout, |
| + List<String> stderr, |
| + Duration time) { |
| + return new CommandOutputImpl.fromCase(testCase, |
| + command, exitCode, incomplete, timedOut, stdout, stderr, time); |
|
ricow1
2012/11/14 16:59:53
one argument per line
kustermann
2012/11/14 17:41:22
Done.
|
| } |
| bool get incomplete; |
| @@ -281,7 +295,7 @@ abstract class TestOutput { |
| List<String> get diagnostics; |
| } |
| -class TestOutputImpl implements TestOutput { |
| +class CommandOutputImpl implements CommandOutput { |
| TestCase testCase; |
| int exitCode; |
| @@ -309,17 +323,19 @@ class TestOutputImpl implements TestOutput { |
| // Don't call this constructor, call TestOutput.fromCase() to |
| // get a new TestOutput instance. |
| - TestOutputImpl(TestCase this.testCase, |
| + CommandOutputImpl(TestCase this.testCase, |
| + Command command, |
|
ricow1
2012/11/14 16:59:53
indentation
kustermann
2012/11/14 17:41:22
Done.
|
| int this.exitCode, |
| bool this.incomplete, |
| bool this.timedOut, |
| List<String> this.stdout, |
| List<String> this.stderr, |
| Duration this.time) { |
| - testCase.output = this; |
| + testCase.commandOutputs[command] = this; |
| diagnostics = []; |
| } |
| - factory TestOutputImpl.fromCase(TestCase testCase, |
| + factory CommandOutputImpl.fromCase(TestCase testCase, |
| + Command command, |
|
ricow1
2012/11/14 16:59:53
indentation
kustermann
2012/11/14 17:41:22
Done.
|
| int exitCode, |
| bool incomplete, |
| bool timedOut, |
| @@ -327,14 +343,14 @@ class TestOutputImpl implements TestOutput { |
| List<String> stderr, |
| Duration time) { |
| if (testCase is BrowserTestCase) { |
| - return new BrowserTestOutputImpl(testCase, exitCode, incomplete, |
| - timedOut, stdout, stderr, time); |
| + return new BrowserCommandOutputImpl(testCase, command, exitCode, |
| + incomplete, timedOut, stdout, stderr, time); |
|
ricow1
2012/11/14 16:59:53
all or one per line
Bill Hesse
2012/11/14 17:07:34
These arguments should be all on one line or one o
kustermann
2012/11/14 17:41:22
Done.
kustermann
2012/11/14 17:41:22
Done.
|
| } else if (testCase.configuration['compiler'] == 'dartc') { |
| - return new AnalysisTestOutputImpl(testCase, exitCode, timedOut, |
| - stdout, stderr, time); |
| + return new AnalysisCommandOutputImpl(testCase, command, exitCode, |
|
ricow1
2012/11/14 16:59:53
all or one per line
kustermann
2012/11/14 17:41:22
Done.
|
| + timedOut, stdout, stderr, time); |
| } |
| - return new TestOutputImpl(testCase, exitCode, incomplete, timedOut, |
| - stdout, stderr, time); |
| + return new CommandOutputImpl(testCase, command, exitCode, incomplete, |
|
ricow1
2012/11/14 16:59:53
all or one per line
kustermann
2012/11/14 17:41:22
Done.
|
| + timedOut, stdout, stderr, time); |
| } |
| String get result => |
| @@ -374,10 +390,11 @@ class TestOutputImpl implements TestOutput { |
| } |
| -class BrowserTestOutputImpl extends TestOutputImpl { |
| - BrowserTestOutputImpl(testCase, exitCode, incomplete, |
| +class BrowserCommandOutputImpl extends CommandOutputImpl { |
| + BrowserCommandOutputImpl(testCase, command, exitCode, incomplete, |
| timedOut, stdout, stderr, time) : |
|
ricow1
2012/11/14 16:59:53
indentation
kustermann
2012/11/14 17:41:22
Done.
|
| - super(testCase, exitCode, incomplete, timedOut, stdout, stderr, time); |
| + super(testCase, command, exitCode, incomplete, timedOut, stdout, stderr, |
| + time); |
| bool get didFail { |
| // Browser case: |
| @@ -420,7 +437,7 @@ class BrowserTestOutputImpl extends TestOutputImpl { |
| // The static analyzer does not actually execute code, so |
| // the criteria for success now depend on the text sent |
| // to stderr. |
| -class AnalysisTestOutputImpl extends TestOutputImpl { |
| +class AnalysisCommandOutputImpl extends CommandOutputImpl { |
| // An error line has 8 fields that look like: |
| // ERROR|COMPILER|MISSING_SOURCE|file:/tmp/t.dart|15|1|24|Missing source. |
| final int ERROR_LEVEL = 0; |
| @@ -429,8 +446,9 @@ class AnalysisTestOutputImpl extends TestOutputImpl { |
| bool alreadyComputed = false; |
| bool failResult; |
| - AnalysisTestOutputImpl(testCase, exitCode, timedOut, stdout, stderr, time) : |
| - super(testCase, exitCode, false, timedOut, stdout, stderr, time); |
| + AnalysisCommandOutputImpl(testCase, command, exitCode, timedOut, stdout, |
| + stderr, time) : |
| + super(testCase, command, exitCode, false, timedOut, stdout, stderr, time); |
| bool get didFail { |
| if (!alreadyComputed) { |
| @@ -611,25 +629,26 @@ class RunningProcess { |
| * succeded, otherwise it will have the exit code of the first failing |
| * command. |
| */ |
| - void testComplete(int exitCode, bool incomplete) { |
| - new TestOutput.fromCase(testCase, exitCode, incomplete, timedOut, stdout, |
| - stderr, new Date.now().difference(startTime)); |
| + void testComplete(Command lastCommand, int exitCode, bool incomplete) { |
| + var lastCmdOut = new CommandOutput.fromCase(testCase, lastCommand, |
|
Bill Hesse
2012/11/14 17:07:34
lastCommandOutput, not lastCmdOut. Never abbrevia
kustermann
2012/11/14 17:41:22
Done.
|
| + exitCode, incomplete, timedOut, stdout, stderr, |
| + new Date.now().difference(startTime)); |
| timeoutTimer.cancel(); |
| - if (testCase.output.unexpectedOutput |
| + if (lastCmdOut.unexpectedOutput |
| && testCase.configuration['verbose'] != null |
| && testCase.configuration['verbose']) { |
| print(testCase.displayName); |
| - for (var line in testCase.output.stderr) print(line); |
| - for (var line in testCase.output.stdout) print(line); |
| + for (var line in lastCmdOut.stderr) print(line); |
| + for (var line in lastCmdOut.stdout) print(line); |
| } |
| if (allowRetries && testCase.usesWebDriver |
| - && testCase.output.unexpectedOutput |
| + && lastCmdOut.unexpectedOutput |
| && (testCase as BrowserTestCase).numRetries > 0) { |
| // Selenium tests can be flaky. Try rerunning. |
| - testCase.output.requestRetry = true; |
| + lastCmdOut.requestRetry = true; |
| } |
| - if (testCase.output.requestRetry) { |
| - testCase.output.requestRetry = false; |
| + if (lastCmdOut.requestRetry) { |
| + lastCmdOut.requestRetry = false; |
| this.timedOut = false; |
| (testCase as BrowserTestCase).numRetries--; |
| print("Potential flake. Re-running ${testCase.displayName} " |
| @@ -648,7 +667,7 @@ class RunningProcess { |
| * treats all but the last command as compilation steps. The last command is |
| * the actual test and its output is analyzed in [testComplete]. |
| */ |
| - void stepExitHandler(int exitCode) { |
| + void commandComplete(Command cmd, int exitCode) { |
|
Bill Hesse
2012/11/14 17:07:34
command
kustermann
2012/11/14 17:41:22
Done.
|
| process = null; |
| int totalSteps = testCase.commands.length; |
| String suffix =' (step $currentStep of $totalSteps)'; |
| @@ -656,14 +675,14 @@ class RunningProcess { |
| // Non-webdriver test timed out before it could complete. Webdriver tests |
| // run their own timeouts by timing from the launch of the browser (which |
| // could be delayed). |
| - testComplete(0, true); |
| + testComplete(cmd, 0, true); |
| } else if (currentStep == totalSteps) { |
| // Done with all test commands. |
| - testComplete(exitCode, false); |
| + testComplete(cmd, exitCode, false); |
| } else if (exitCode != 0) { |
| // One of the steps failed. |
| stderr.add('test.dart: Compilation failed$suffix, exit code $exitCode\n'); |
| - testComplete(exitCode, true); |
| + testComplete(cmd, exitCode, true); |
| } else { |
| // One compilation step successfully completed, move on to the |
| // next step. |
| @@ -678,7 +697,7 @@ class RunningProcess { |
| timeoutTimer.cancel(); |
| processQueue._getBatchRunner(testCase).startTest(testCase); |
| } else { |
| - runCommand(testCase.commands[currentStep++], stepExitHandler); |
| + runCommand(testCase.commands[currentStep++], commandComplete); |
| } |
| } |
| } |
| @@ -702,14 +721,19 @@ class RunningProcess { |
| stderr = new List<String>(); |
| currentStep = 0; |
| startTime = new Date.now(); |
| - runCommand(testCase.commands[currentStep++], stepExitHandler); |
| + runCommand(testCase.commands[currentStep++], commandComplete); |
| } |
| - void runCommand(Command command, void exitHandler(int exitCode)) { |
| + void runCommand(Command command, void cmdCompleteHandler(Command cmd, |
|
Bill Hesse
2012/11/14 17:07:34
Can we leave the parameter names out of the argume
Bill Hesse
2012/11/14 17:07:34
commandCompleteHandler
kustermann
2012/11/14 17:41:22
Done.
kustermann
2012/11/14 17:41:22
Done.
|
| + int exitCode)) { |
| + void processExitHandler(int returnCode) { |
| + cmdCompleteHandler(command, returnCode); |
| + } |
| + |
| Future processFuture = Process.start(command.executable, command.arguments); |
| processFuture.then((Process p) { |
| process = p; |
| - process.onExit = exitHandler; |
| + process.onExit = processExitHandler; |
| var stdoutStringStream = new StringInputStream(process.stdout); |
| var stderrStringStream = new StringInputStream(process.stderr); |
| stdoutStringStream.onLine = |
| @@ -728,7 +752,7 @@ class RunningProcess { |
| print("Process error:"); |
| print(" Command: $command"); |
| print(" Error: $e"); |
| - testComplete(-1, false); |
| + testComplete(command, -1, false); |
| return true; |
| }); |
| } |
| @@ -759,6 +783,7 @@ class MutableValue<T> { |
| } |
| class BatchRunnerProcess { |
| + Command _command; |
| String _executable; |
| List<String> _batchArguments; |
| @@ -779,6 +804,7 @@ class BatchRunnerProcess { |
| bool _isWebDriver; |
| BatchRunnerProcess(TestCase testCase) { |
| + _command = testCase.commands.last; |
| _executable = testCase.commands.last.executable; |
| _batchArguments = testCase.batchRunnerArguments; |
| _isWebDriver = testCase.usesWebDriver; |
| @@ -789,6 +815,7 @@ class BatchRunnerProcess { |
| void startTest(TestCase testCase) { |
| Expect.isNull(_currentTest); |
| _currentTest = testCase; |
| + _command = testCase.commands.last; |
| if (_process === null) { |
| // Start process if not yet started. |
| _executable = testCase.commands.last.executable; |
| @@ -869,7 +896,7 @@ class BatchRunnerProcess { |
| var exitCode = 0; |
| if (outcome == "CRASH") exitCode = -10; |
| if (outcome == "FAIL" || outcome == "TIMEOUT") exitCode = 1; |
| - new TestOutput.fromCase(_currentTest, exitCode, false, |
| + new CommandOutput.fromCase(_currentTest, _command, exitCode, false, |
| (outcome == "TIMEOUT"), |
| _testStdout, _testStderr, |
| new Date.now().difference(_startTime)); |