Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 message_extraction_test; | 5 library message_extraction_test; |
| 6 | 6 |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| 11 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
| 12 import '../data_directory.dart'; | 12 import '../data_directory.dart'; |
| 13 | 13 |
| 14 final dart = Platform.executable; | 14 final dart = Platform.executable; |
| 15 | 15 |
| 16 /** The VM arguments we were given, most important package-root. */ | 16 /** The VM arguments we were given, most important package-root. */ |
| 17 final vmArgs = Platform.executableArguments; | 17 final vmArgs = Platform.executableArguments; |
| 18 | 18 |
| 19 var tempDir = Directory.systemTemp.createTempSync('message_extraction_test' | 19 String get tempDir => _tempDir == null ? _tempDir = _createTempDir() : _tempDir; |
|
Emily Fortuna
2014/05/15 19:24:36
can you put a brief comment above this section her
Alan Knight
2014/05/15 20:02:18
Done.
| |
| 20 ).path; | 20 var _tempDir; |
| 21 _createTempDir() => useLocalDirectory ? '.' : | |
| 22 Directory.systemTemp.createTempSync('message_extraction_test').path; | |
| 23 | |
| 24 var useLocalDirectory = false; | |
| 21 | 25 |
| 22 /** | 26 /** |
| 23 * Translate a relative file path into this test directory. This is | 27 * Translate a relative file path into this test directory. This is |
| 24 * applied to all the arguments of [run]. It will ignore a string that | 28 * applied to all the arguments of [run]. It will ignore a string that |
| 25 * is an absolute path or begins with "--", because some of the arguments | 29 * is an absolute path or begins with "--", because some of the arguments |
| 26 * might be command-line options. | 30 * might be command-line options. |
| 27 */ | 31 */ |
| 28 String asTestDirPath([String s]) { | 32 String asTestDirPath([String s]) { |
| 29 if (s == null || s.startsWith("--") || path.isAbsolute(s)) return s; | 33 if (s == null || s.startsWith("--") || path.isAbsolute(s)) return s; |
| 30 return path.join(intlDirectory, 'test', 'message_extraction', s); | 34 return path.join(intlDirectory, 'test', 'message_extraction', s); |
| 31 } | 35 } |
| 32 | 36 |
| 33 /** | 37 /** |
| 34 * Translate a relative file path into our temp directory. This is | 38 * Translate a relative file path into our temp directory. This is |
| 35 * applied to all the arguments of [run]. It will ignore a string that | 39 * applied to all the arguments of [run]. It will ignore a string that |
| 36 * is an absolute path or begins with "--", because some of the arguments | 40 * is an absolute path or begins with "--", because some of the arguments |
| 37 * might be command-line options. | 41 * might be command-line options. |
| 38 */ | 42 */ |
| 39 String asTempDirPath([String s]) { | 43 String asTempDirPath([String s]) { |
| 40 if (s == null || s.startsWith("--") || path.isAbsolute(s)) return s; | 44 if (s == null || s.startsWith("--") || path.isAbsolute(s)) return s; |
| 41 return path.join(tempDir, s); | 45 return path.join(tempDir, s); |
| 42 } | 46 } |
| 43 | 47 |
| 44 main() { | 48 main(arguments) { |
| 49 // If debugging, use --local to avoid copying everything to temporary | |
| 50 // directories to make it even harder to debug. Note that this will also | |
| 51 // not delete the generated files, so may require manual cleanup. | |
| 52 if (arguments.contains("--local")) { | |
| 53 print("Testing using local directory for generated files"); | |
| 54 useLocalDirectory = true; | |
| 55 } | |
| 45 setUp(copyFilesToTempDirectory); | 56 setUp(copyFilesToTempDirectory); |
| 46 test("Test round trip message extraction, translation, code generation, " | 57 test("Test round trip message extraction, translation, code generation, " |
| 47 "and printing", () { | 58 "and printing", () { |
| 48 var makeSureWeVerify = expectAsync(runAndVerify); | 59 var makeSureWeVerify = expectAsync(runAndVerify); |
| 49 return extractMessages(null).then((result) { | 60 return extractMessages(null).then((result) { |
| 50 return generateTranslationFiles(result); | 61 return generateTranslationFiles(result); |
| 51 }).then((result) { | 62 }).then((result) { |
| 52 return generateCodeFromTranslation(result); | 63 return generateCodeFromTranslation(result); |
| 53 }).then(makeSureWeVerify).then(checkResult); | 64 }).then(makeSureWeVerify).then(checkResult); |
| 54 }); | 65 }); |
| 55 tearDown(deleteGeneratedFiles); | 66 tearDown(deleteGeneratedFiles); |
| 56 } | 67 } |
| 57 | 68 |
| 58 void copyFilesToTempDirectory() { | 69 void copyFilesToTempDirectory() { |
| 70 if (useLocalDirectory) return; | |
| 59 var files = [asTestDirPath('sample_with_messages.dart'), | 71 var files = [asTestDirPath('sample_with_messages.dart'), |
| 60 asTestDirPath('part_of_sample_with_messages.dart'), | 72 asTestDirPath('part_of_sample_with_messages.dart'), |
| 61 asTestDirPath('verify_messages.dart'), | 73 asTestDirPath('verify_messages.dart'), |
| 62 asTestDirPath('run_and_verify.dart'), | 74 asTestDirPath('run_and_verify.dart'), |
| 63 asTestDirPath('print_to_list.dart')]; | 75 asTestDirPath('print_to_list.dart')]; |
| 64 for (var filename in files) { | 76 for (var filename in files) { |
| 65 var file = new File(filename); | 77 var file = new File(filename); |
| 66 file.copySync(path.join(tempDir, path.basename(filename))); | 78 file.copySync(path.join(tempDir, path.basename(filename))); |
| 67 } | 79 } |
| 68 } | 80 } |
| 69 | 81 |
| 70 void deleteGeneratedFiles() { | 82 void deleteGeneratedFiles() { |
| 83 if (useLocalDirectory) return; | |
| 71 try { | 84 try { |
| 72 var dir = new Directory(tempDir); | 85 var dir = new Directory(tempDir); |
| 73 dir.listSync().forEach((x) => x.deleteSync()); | 86 dir.listSync().forEach((x) => x.deleteSync()); |
| 74 dir.deleteSync(); | 87 dir.deleteSync(); |
| 75 } on Error catch (e) { | 88 } on Error catch (e) { |
| 76 print("Failed to delete $tempDir"); | 89 print("Failed to delete $tempDir"); |
| 77 print("Exception:\n$e"); | 90 print("Exception:\n$e"); |
| 78 } | 91 } |
| 79 } | 92 } |
| 80 | 93 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 'intl_messages.json']); | 138 'intl_messages.json']); |
| 126 | 139 |
| 127 Future<ProcessResult> generateCodeFromTranslation(ProcessResult previousResult) | 140 Future<ProcessResult> generateCodeFromTranslation(ProcessResult previousResult) |
| 128 => run(previousResult, [asTestDirPath('generate_from_json.dart'), | 141 => run(previousResult, [asTestDirPath('generate_from_json.dart'), |
| 129 '--generated-file-prefix=foo_', 'sample_with_messages.dart', | 142 '--generated-file-prefix=foo_', 'sample_with_messages.dart', |
| 130 'part_of_sample_with_messages.dart', 'translation_fr.json', | 143 'part_of_sample_with_messages.dart', 'translation_fr.json', |
| 131 'translation_de_DE.json']); | 144 'translation_de_DE.json']); |
| 132 | 145 |
| 133 Future<ProcessResult> runAndVerify(ProcessResult previousResult) => run( | 146 Future<ProcessResult> runAndVerify(ProcessResult previousResult) => run( |
| 134 previousResult, [asTempDirPath('run_and_verify.dart')]); | 147 previousResult, [asTempDirPath('run_and_verify.dart')]); |
| OLD | NEW |