| 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 library record_and_replay; | 5 library record_and_replay; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'test_runner.dart'; | 10 import 'test_runner.dart'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 class TestCaseRecorder { | 49 class TestCaseRecorder { |
| 50 Path _outputPath; | 50 Path _outputPath; |
| 51 List<Map> _recordedCommandInvocations = []; | 51 List<Map> _recordedCommandInvocations = []; |
| 52 var _cwd; | 52 var _cwd; |
| 53 | 53 |
| 54 TestCaseRecorder(this._outputPath) { | 54 TestCaseRecorder(this._outputPath) { |
| 55 _cwd = Directory.current.path; | 55 _cwd = Directory.current.path; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void nextCommand(Command command, int timeout) { | 58 void nextCommand(ProcessCommand command, int timeout) { |
| 59 // Convert arguments from absolute to relative paths (relative to the dart | 59 // Convert arguments from absolute to relative paths (relative to the dart |
| 60 // directory) because the absolute path on the machine where we record | 60 // directory) because the absolute path on the machine where we record |
| 61 // may be different from the absolute path on the machine where we execute | 61 // may be different from the absolute path on the machine where we execute |
| 62 // the commands. | 62 // the commands. |
| 63 var arguments = makePathsRelativeToDart(_cwd, command.arguments); | 63 var arguments = makePathsRelativeToDart(_cwd, command.arguments); |
| 64 | 64 |
| 65 var commandExecution = { | 65 var commandExecution = { |
| 66 'name' : command.displayName, | 66 'name' : command.displayName, |
| 67 'command' : { | 67 'command' : { |
| 68 'timeout_limit' : timeout, | 68 'timeout_limit' : timeout, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 var file = new File(recordingPath.toNativePath()); | 93 var file = new File(recordingPath.toNativePath()); |
| 94 var commandRecordings = JSON.decode(file.readAsStringSync()); | 94 var commandRecordings = JSON.decode(file.readAsStringSync()); |
| 95 _commandOutputRecordings = {}; | 95 _commandOutputRecordings = {}; |
| 96 for (var commandRecording in commandRecordings) { | 96 for (var commandRecording in commandRecordings) { |
| 97 var key = _indexKey(commandRecording['command']['executable'], | 97 var key = _indexKey(commandRecording['command']['executable'], |
| 98 commandRecording['command']['arguments'].join(' ')); | 98 commandRecording['command']['arguments'].join(' ')); |
| 99 _commandOutputRecordings[key] = commandRecording['command_output']; | 99 _commandOutputRecordings[key] = commandRecording['command_output']; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 CommandOutput outputOf(Command command) { | 103 CommandOutput outputOf(ProcessCommand command) { |
| 104 // Convert arguments from absolute to relative paths (relative to the dart | 104 // Convert arguments from absolute to relative paths (relative to the dart |
| 105 // directory) because the absolute path on the machine where we record | 105 // directory) because the absolute path on the machine where we record |
| 106 // may be different from the absolute path on the machine where we execute | 106 // may be different from the absolute path on the machine where we execute |
| 107 // the commands. | 107 // the commands. |
| 108 var arguments = makePathsRelativeToDart(_cwd, command.arguments); | 108 var arguments = makePathsRelativeToDart(_cwd, command.arguments); |
| 109 | 109 |
| 110 var key = _indexKey(command.executable, arguments.join(' ')); | 110 var key = _indexKey(command.executable, arguments.join(' ')); |
| 111 var command_output = _commandOutputRecordings[key]; | 111 var command_output = _commandOutputRecordings[key]; |
| 112 if (command_output == null) { | 112 if (command_output == null) { |
| 113 print("Sorry, but there is no command output for ${command.displayName}" | 113 print("Sorry, but there is no command output for ${command.displayName}" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 127 duration, | 127 duration, |
| 128 false); | 128 false); |
| 129 return commandOutput; | 129 return commandOutput; |
| 130 } | 130 } |
| 131 | 131 |
| 132 String _indexKey(String executable, String arguments) { | 132 String _indexKey(String executable, String arguments) { |
| 133 return "${executable}__$arguments"; | 133 return "${executable}__$arguments"; |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| OLD | NEW |