Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1248)

Side by Side Diff: pkg/intl/test/message_extraction/message_extraction_test.dart

Issue 13898014: Allow suppressing message extraction warnings, providing a prefix for generated files, and format w… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More fixes Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 'package:pathos/path.dart' as path; 10 import 'package:pathos/path.dart' as path;
(...skipping 30 matching lines...) Expand all
41 return null; 41 return null;
42 } 42 }
43 43
44 /** If our package root directory is set, return it as a VM argument. */ 44 /** If our package root directory is set, return it as a VM argument. */
45 final vmArgs = (packageDir == null) ? [] : ['--package-root=$packageDir']; 45 final vmArgs = (packageDir == null) ? [] : ['--package-root=$packageDir'];
46 46
47 /** 47 /**
48 * Translate a file path into this test directory, regardless of the 48 * Translate a file path into this test directory, regardless of the
49 * working directory. 49 * working directory.
50 */ 50 */
51 String dir([String s]) => 51 String dir([String s]) {
52 path.join(intlDirectory, 'test', 'message_extraction', s); 52 if (s != null && s.startsWith("--")) { // Don't touch command-line options.
53 return s;
54 } else {
55 return path.join(intlDirectory, 'test', 'message_extraction', s);
56 }
57 }
53 58
54 main() { 59 main() {
55 test("Test round trip message extraction, translation, code generation, " 60 test("Test round trip message extraction, translation, code generation, "
56 "and printing", () { 61 "and printing", () {
57 deleteGeneratedFiles(); 62 deleteGeneratedFiles();
58 return extractMessages(null).then((result) { 63 return extractMessages(null).then((result) {
59 return generateTranslationFiles(result); 64 return generateTranslationFiles(result);
60 }).then((result) { 65 }).then((result) {
61 return generateCodeFromTranslation(result); 66 return generateCodeFromTranslation(result);
62 }).then((result) { 67 }).then((result) {
63 return runGeneratedCode(result); 68 return runGeneratedCode(result);
64 }).then(verifyResult) 69 }).then(verifyResult)
65 .whenComplete(deleteGeneratedFiles); 70 .whenComplete(deleteGeneratedFiles);
66 }); 71 });
67 } 72 }
68 73
69 void deleteGeneratedFiles() { 74 void deleteGeneratedFiles() {
70 var files = [dir('intl_messages.json'), dir('translation_fr.json'), 75 var files = [dir('intl_messages.json'), dir('translation_fr.json'),
71 dir('messages_fr.dart'), dir('messages_de_DE.dart'), 76 dir('foo_messages_fr.dart'), dir('foo_messages_de_DE.dart'),
72 dir('translation_de_DE.json'), dir('messages_all.dart')]; 77 dir('translation_de_DE.json'), dir('foo_messages_all.dart')];
73 files.map((name) => new File(name)).forEach((x) { 78 files.map((name) => new File(name)).forEach((x) {
74 if (x.existsSync()) x.deleteSync();}); 79 if (x.existsSync()) x.deleteSync();});
75 } 80 }
76 81
77 /** 82 /**
78 * Run the process with the given list of filenames, which we assume 83 * Run the process with the given list of filenames, which we assume
79 * are in dir() and need to be qualified in case that's not our working 84 * are in dir() and need to be qualified in case that's not our working
80 * directory. 85 * directory.
81 */ 86 */
82 Future<ProcessResult> run(ProcessResult previousResult, List<String> filenames) 87 Future<ProcessResult> run(ProcessResult previousResult, List<String> filenames)
(...skipping 17 matching lines...) Expand all
100 ..addAll(filesInTheRightDirectory.skip(1)); 105 ..addAll(filesInTheRightDirectory.skip(1));
101 var options = new ProcessOptions() 106 var options = new ProcessOptions()
102 ..stdoutEncoding=Encoding.UTF_8 107 ..stdoutEncoding=Encoding.UTF_8
103 ..stderrEncoding=Encoding.UTF_8; 108 ..stderrEncoding=Encoding.UTF_8;
104 var result = Process.run(dart, args); 109 var result = Process.run(dart, args);
105 return result; 110 return result;
106 } 111 }
107 112
108 Future<ProcessResult> extractMessages(ProcessResult previousResult) => run( 113 Future<ProcessResult> extractMessages(ProcessResult previousResult) => run(
109 previousResult, 114 previousResult,
110 ['extract_to_json.dart', 'sample_with_messages.dart', 115 ['extract_to_json.dart', '--suppress-warnings', 'sample_with_messages.dart',
111 'part_of_sample_with_messages.dart']); 116 'part_of_sample_with_messages.dart']);
112 117
113 Future<ProcessResult> generateTranslationFiles(ProcessResult previousResult) => 118 Future<ProcessResult> generateTranslationFiles(ProcessResult previousResult) =>
114 run( 119 run(
115 previousResult, 120 previousResult,
116 ['make_hardcoded_translation.dart', 'intl_messages.json']); 121 ['make_hardcoded_translation.dart', 'intl_messages.json']);
117 122
118 Future<ProcessResult> generateCodeFromTranslation(ProcessResult previousResult) 123 Future<ProcessResult> generateCodeFromTranslation(ProcessResult previousResult)
119 => run( 124 => run(
120 previousResult, 125 previousResult,
121 ['generate_from_json.dart', 'sample_with_messages.dart', 126 ['generate_from_json.dart', '--generated-file-prefix=foo_',
127 'sample_with_messages.dart',
122 'part_of_sample_with_messages.dart', 'translation_fr.json', 128 'part_of_sample_with_messages.dart', 'translation_fr.json',
123 'translation_de_DE.json' ]); 129 'translation_de_DE.json' ]);
124 130
125 Future<ProcessResult> runGeneratedCode(ProcessResult previousResult) => 131 Future<ProcessResult> runGeneratedCode(ProcessResult previousResult) =>
126 run(previousResult, ['sample_with_messages.dart']); 132 run(previousResult, ['sample_with_messages.dart']);
127 133
128 verifyResult(results) { 134 verifyResult(results) {
129 var lineIterator; 135 var lineIterator;
130 verify(String s) { 136 verify(String s) {
131 lineIterator.moveNext(); 137 lineIterator.moveNext();
132 var value = lineIterator.current; 138 var value = lineIterator.current;
133 expect(value, s); 139 expect(value, s);
134 } 140 }
135 141
136 var output = results.stdout; 142 var output = results.stdout;
137 var lines = output.split("\n"); 143 var lines = output.split("\n");
138 // If it looks like these are CRLF delimited, then use that. Wish strings 144 // If it looks like these are CRLF delimited, then use that.
139 // just implemented last. 145 if (lines.first.endsWith("\r")) {
140 if (lines.first.codeUnits.last == "\r".codeUnits.first) {
141 lines = output.split("\r\n"); 146 lines = output.split("\r\n");
142 } 147 }
143 lineIterator = lines.iterator..moveNext(); 148 lineIterator = lines.iterator..moveNext();
144 verify("Printing messages for en_US"); 149 verify("Printing messages for en_US");
145 verify("This is a message"); 150 verify("This is a message");
146 verify("Another message with parameter hello"); 151 verify("Another message with parameter hello");
147 verify("Characters that need escaping, e.g slashes \\ dollars \${ " 152 verify("Characters that need escaping, e.g slashes \\ dollars \${ "
148 "(curly braces are ok) and xml reserved characters <& and " 153 "(curly braces are ok) and xml reserved characters <& and "
149 "quotes \" parameters 1, 2, and 3"); 154 "quotes \" parameters 1, 2, and 3");
150 verify("This string extends across multiple lines."); 155 verify("This string extends across multiple lines.");
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 verify("Diese Methode ist nicht eine Lambda"); 219 verify("Diese Methode ist nicht eine Lambda");
215 verify("Dies ergibt sich aus einer statischen Methode"); 220 verify("Dies ergibt sich aus einer statischen Methode");
216 verify("This is missing some translations"); 221 verify("This is missing some translations");
217 verify("Antike griechische Galgenmännchen Zeichen: 𐅆𐅇"); 222 verify("Antike griechische Galgenmännchen Zeichen: 𐅆𐅇");
218 // verify("Die Sache ist, well"); 223 // verify("Die Sache ist, well");
219 // expect("Einer der knifflige Dinge ist der Plural"); 224 // expect("Einer der knifflige Dinge ist der Plural");
220 // expect("Zu den kniffligen Dinge Pluralformen"); 225 // expect("Zu den kniffligen Dinge Pluralformen");
221 verify("Escapes: "); 226 verify("Escapes: ");
222 verify("\r\f\b\t\v."); 227 verify("\r\f\b\t\v.");
223 } 228 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698