| 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 16 matching lines...) Expand all Loading... |
| 27 * 'stderr' : '...', | 27 * 'stderr' : '...', |
| 28 * 'duration' : 1.5, | 28 * 'duration' : 1.5, |
| 29 * 'did_timeout' : false, | 29 * 'did_timeout' : false, |
| 30 * }, | 30 * }, |
| 31 * }, | 31 * }, |
| 32 * .... | 32 * .... |
| 33 * ] | 33 * ] |
| 34 */ | 34 */ |
| 35 | 35 |
| 36 List<String> makePathsRelativeToDart(String cwd, List<String> arguments) { | 36 List<String> makePathsRelativeToDart(String cwd, List<String> arguments) { |
| 37 var relativeArguments = []; | 37 var relativeArguments = <String>[]; |
| 38 for (var rawArgument in arguments) { | 38 for (var rawArgument in arguments) { |
| 39 if (rawArgument.startsWith(cwd)) { | 39 if (rawArgument.startsWith(cwd)) { |
| 40 var relative = new Path(rawArgument).relativeTo(new Path(cwd)); | 40 var relative = new Path(rawArgument).relativeTo(new Path(cwd)); |
| 41 relativeArguments.add(relative.toNativePath()); | 41 relativeArguments.add(relative.toNativePath()); |
| 42 } else { | 42 } else { |
| 43 relativeArguments.add(rawArgument); | 43 relativeArguments.add(rawArgument); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 return relativeArguments; | 46 return relativeArguments; |
| 47 } | 47 } |
| 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 String _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(ProcessCommand 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. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 76 void finish() { | 76 void finish() { |
| 77 var file = new File(_outputPath.toNativePath()); | 77 var file = new File(_outputPath.toNativePath()); |
| 78 var jsonString = JSON.encode(_recordedCommandInvocations); | 78 var jsonString = JSON.encode(_recordedCommandInvocations); |
| 79 file.writeAsStringSync(jsonString); | 79 file.writeAsStringSync(jsonString); |
| 80 print("TestCaseRecorder: written all TestCases to ${_outputPath}"); | 80 print("TestCaseRecorder: written all TestCases to ${_outputPath}"); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 class TestCaseOutputArchive { | 84 class TestCaseOutputArchive { |
| 85 Map<String, Map> _commandOutputRecordings; | 85 Map<String, Map> _commandOutputRecordings; |
| 86 var _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 _commandOutputRecordings = {}; | 95 _commandOutputRecordings = {}; |
| 96 for (var commandRecording in commandRecordings) { | 96 for (var commandRecording in commandRecordings) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 126 UTF8.encode(command_output['stderr']), | 126 UTF8.encode(command_output['stderr']), |
| 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 |