Chromium Code Reviews| 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()) |
| 95 as List<Map<String, Map<String, dynamic>>>; | |
|
Siggi Cherem (dart-lang)
2017/05/30 20:48:39
same here: looks to me like this would fail in str
Bob Nystrom
2017/05/30 21:01:46
Done.
| |
| 95 _commandOutputRecordings = {}; | 96 _commandOutputRecordings = {}; |
| 96 for (var commandRecording in commandRecordings) { | 97 for (var commandRecording in commandRecordings) { |
| 97 var key = _indexKey(commandRecording['command']['executable'], | 98 var key = _indexKey(commandRecording['command']['executable'] as String, |
| 98 commandRecording['command']['arguments'].join(' ')); | 99 (commandRecording['command']['arguments'] as List).join(' ')); |
| 99 _commandOutputRecordings[key] = commandRecording['command_output']; | 100 _commandOutputRecordings[key] = commandRecording['command_output']; |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 103 CommandOutput outputOf(ProcessCommand command) { | 104 CommandOutput outputOf(ProcessCommand command) { |
| 104 // Convert arguments from absolute to relative paths (relative to the dart | 105 // Convert arguments from absolute to relative paths (relative to the dart |
| 105 // directory) because the absolute path on the machine where we record | 106 // 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 | 107 // may be different from the absolute path on the machine where we execute |
| 107 // the commands. | 108 // the commands. |
| 108 var arguments = makePathsRelativeToDart(_cwd, command.arguments); | 109 var arguments = makePathsRelativeToDart(_cwd, command.arguments); |
| 109 | 110 |
| 110 var key = _indexKey(command.executable, arguments.join(' ')); | 111 var key = _indexKey(command.executable, arguments.join(' ')); |
| 111 var command_output = _commandOutputRecordings[key]; | 112 var command_output = _commandOutputRecordings[key]; |
| 112 if (command_output == null) { | 113 if (command_output == null) { |
| 113 print("Sorry, but there is no command output for ${command.displayName}" | 114 print("Sorry, but there is no command output for ${command.displayName}" |
| 114 " ($command)"); | 115 " ($command)"); |
| 115 exit(42); | 116 exit(42); |
| 116 } | 117 } |
| 117 | 118 |
| 118 double seconds = command_output['duration']; | 119 double seconds = command_output['duration'] as double; |
| 119 var duration = new Duration( | 120 var duration = new Duration( |
| 120 seconds: seconds.round(), milliseconds: (seconds / 1000).round()); | 121 seconds: seconds.round(), milliseconds: (seconds / 1000).round()); |
| 121 var commandOutput = createCommandOutput( | 122 var commandOutput = createCommandOutput( |
| 122 command, | 123 command, |
| 123 command_output['exit_code'], | 124 command_output['exit_code'] as int, |
| 124 command_output['did_timeout'], | 125 command_output['did_timeout'] as bool, |
| 125 UTF8.encode(command_output['stdout']), | 126 UTF8.encode(command_output['stdout'] as String), |
| 126 UTF8.encode(command_output['stderr']), | 127 UTF8.encode(command_output['stderr'] as String), |
| 127 duration, | 128 duration, |
| 128 false); | 129 false); |
| 129 return commandOutput; | 130 return commandOutput; |
| 130 } | 131 } |
| 131 | 132 |
| 132 String _indexKey(String executable, String arguments) { | 133 String _indexKey(String executable, String arguments) { |
| 133 return "${executable}__$arguments"; | 134 return "${executable}__$arguments"; |
| 134 } | 135 } |
| 135 } | 136 } |
| OLD | NEW |