OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 /** | |
6 * A [PipelineRunner] represents the execution of our pipeline for | |
7 * one test file. | |
8 */ | |
9 class PipelineRunner { | |
10 // The path of the test file. | |
Siggi Cherem (dart-lang)
2012/08/29 20:47:35
use /** */ here too...
gram
2012/08/30 00:16:55
Done.
| |
11 Path _path; | |
12 | |
13 // The pipeline template. | |
14 List _pipelineTemplate; | |
15 | |
16 // String lists used to capture output. | |
17 List _stdout; | |
18 List _stderr; | |
19 | |
20 // Whether the output should be verbose. | |
21 bool _verbose; | |
22 | |
23 // Which stage of the pipeline is being executed. | |
24 int _stageNum; | |
25 | |
26 // The handler to call when the pipeline is done. | |
27 Function _completeHandler; | |
28 | |
29 PipelineRunner( | |
30 List pipelineTemplate, | |
31 String test, | |
32 bool verbose, | |
33 Function completeHandler) : | |
34 _verbose = verbose, | |
35 _completeHandler = completeHandler { | |
36 _pipelineTemplate = pipelineTemplate; | |
37 _path = new Path(test); | |
38 _stdout = new List(); | |
39 _stderr = new List(); | |
40 } | |
41 | |
42 /** Kick off excution with the first stage. */ | |
43 void execute() { | |
44 _runStage(_stageNum = 0); | |
45 } | |
46 | |
47 /** Execute a stage of the pipeline. */ | |
48 void _runStage(int stageNum) { | |
49 _pipelineTemplate[stageNum]. | |
50 execute(_path, _stdout, _stderr, _verbose, _handleExit); | |
51 } | |
52 | |
53 /** | |
54 * [_handleExit] is called at the end of each stage. It will execute the | |
55 * next stage or call the completion handler if all are done. | |
56 */ | |
57 void _handleExit(int exitCode) { | |
58 int totalStages = _pipelineTemplate.length; | |
59 _stageNum++; | |
60 String suffix = _verbose ? ' (step $_stageNum of $totalStages)' : ''; | |
61 | |
62 if (_verbose && exitCode != 0) { | |
63 _stderr.add('Test failed$suffix, exit code $exitCode\n'); | |
64 } | |
65 | |
66 if (_stageNum == totalStages || exitCode != 0) { // Done with pipeline. | |
67 completeHandler(makePathAbsolute(_path.toString()), exitCode, | |
68 _stdout, _stderr); | |
69 } else { | |
70 if (_verbose) { | |
71 _stdout.add('Finished $suffix\n'); | |
72 } | |
73 _runStage(_stageNum); | |
74 } | |
75 } | |
76 } | |
OLD | NEW |