| 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 'path.dart'; | 10 import 'path.dart'; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 class TestCaseOutputArchive { | 84 class TestCaseOutputArchive { |
| 85 Map<String, Map> _commandOutputRecordings; | 85 Map<String, Map> _commandOutputRecordings; |
| 86 String _cwd; | 86 String _cwd; |
| 87 | 87 |
| 88 TestCaseOutputArchive() { | 88 TestCaseOutputArchive() { |
| 89 _cwd = Directory.current.path; | 89 _cwd = Directory.current.path; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void loadFromPath(Path recordingPath) { | 92 void loadFromPath(Path recordingPath) { |
| 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()) as List; |
| 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'] as String, |
| 98 commandRecording['command']['arguments'].join(' ')); | 98 (commandRecording['command']['arguments'] as List).join(' ')); |
| 99 _commandOutputRecordings[key] = commandRecording['command_output']; | 99 _commandOutputRecordings[key] = commandRecording['command_output'] as Map; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 CommandOutput outputOf(ProcessCommand 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}" |
| 114 " ($command)"); | 114 " ($command)"); |
| 115 exit(42); | 115 exit(42); |
| 116 } | 116 } |
| 117 | 117 |
| 118 double seconds = command_output['duration']; | 118 double seconds = command_output['duration'] as double; |
| 119 var duration = new Duration( | 119 var duration = new Duration( |
| 120 seconds: seconds.round(), milliseconds: (seconds / 1000).round()); | 120 seconds: seconds.round(), milliseconds: (seconds / 1000).round()); |
| 121 var commandOutput = createCommandOutput( | 121 var commandOutput = createCommandOutput( |
| 122 command, | 122 command, |
| 123 command_output['exit_code'], | 123 command_output['exit_code'] as int, |
| 124 command_output['did_timeout'], | 124 command_output['did_timeout'] as bool, |
| 125 UTF8.encode(command_output['stdout']), | 125 UTF8.encode(command_output['stdout'] as String), |
| 126 UTF8.encode(command_output['stderr']), | 126 UTF8.encode(command_output['stderr'] as String), |
| 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 } |
| OLD | NEW |