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

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

Issue 23484010: Re-arrange tests to allow testing generated messages code in dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Regenerated code Created 7 years, 3 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
« no previous file with comments | « pkg/intl/test/message_extraction/sample_with_messages.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 library verify_messages;
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.
4 2
5 library message_extraction_test; 3 import "print_to_list.dart";
4 import "package:unittest/unittest.dart";
6 5
7 import 'package:unittest/unittest.dart'; 6 verifyResult(ignored) {
8 import 'dart:io';
9 import 'dart:async';
10 import 'dart:convert';
11 import 'package:path/path.dart' as path;
12 import '../data_directory.dart';
13
14 final dart = Platform.executable;
15
16 /** The VM arguments we were given, most important package-root. */
17 final vmArgs = Platform.executableArguments;
18
19 /**
20 * Translate a file path into this test directory, regardless of the
21 * working directory.
22 */
23 String dir([String s]) {
24 if (s != null && s.startsWith("--")) { // Don't touch command-line options.
25 return s;
26 } else {
27 return path.join(intlDirectory, 'test', 'message_extraction', s);
28 }
29 }
30
31 main() {
32 test("Test round trip message extraction, translation, code generation, "
33 "and printing", () {
34 deleteGeneratedFiles();
35 return extractMessages(null).then((result) {
36 return generateTranslationFiles(result);
37 }).then((result) {
38 return generateCodeFromTranslation(result);
39 }).then((result) {
40 return runGeneratedCode(result);
41 }).then(verifyResult)
42 .whenComplete(deleteGeneratedFiles);
43 });
44 }
45
46 void deleteGeneratedFiles() {
47 var files = [dir('intl_messages.json'), dir('translation_fr.json'),
48 dir('foo_messages_fr.dart'), dir('foo_messages_de_DE.dart'),
49 dir('translation_de_DE.json'), dir('foo_messages_all.dart')];
50 files.map((name) => new File(name)).forEach((x) {
51 if (x.existsSync()) x.deleteSync();});
52 }
53
54 /**
55 * Run the process with the given list of filenames, which we assume
56 * are in dir() and need to be qualified in case that's not our working
57 * directory.
58 */
59 Future<ProcessResult> run(ProcessResult previousResult, List<String> filenames)
60 {
61 // If there's a failure in one of the sub-programs, print its output.
62 if (previousResult != null) {
63 if (previousResult.exitCode != 0) {
64 print("Error running sub-program:");
65 }
66 print(previousResult.stdout);
67 print(previousResult.stderr);
68 print("exitCode=${previousResult.exitCode}");
69 }
70 var filesInTheRightDirectory = filenames.map((x) => dir(x)).toList();
71 // Inject the script argument --output-dir in between the script and its
72 // arguments.
73 var args = []
74 ..addAll(vmArgs)
75 ..add(filesInTheRightDirectory.first)
76 ..addAll(["--output-dir=${dir()}"])
77 ..addAll(filesInTheRightDirectory.skip(1));
78 var result = Process.run(dart, args, stdoutEncoding: UTF8,
79 stderrEncoding: UTF8);
80 return result;
81 }
82
83 Future<ProcessResult> extractMessages(ProcessResult previousResult) => run(
84 previousResult,
85 ['extract_to_json.dart', '--suppress-warnings', 'sample_with_messages.dart',
86 'part_of_sample_with_messages.dart']);
87
88 Future<ProcessResult> generateTranslationFiles(ProcessResult previousResult) =>
89 run(
90 previousResult,
91 ['make_hardcoded_translation.dart', 'intl_messages.json']);
92
93 Future<ProcessResult> generateCodeFromTranslation(ProcessResult previousResult)
94 => run(
95 previousResult,
96 ['generate_from_json.dart', '--generated-file-prefix=foo_',
97 'sample_with_messages.dart',
98 'part_of_sample_with_messages.dart', 'translation_fr.json',
99 'translation_de_DE.json' ]);
100
101 Future<ProcessResult> runGeneratedCode(ProcessResult previousResult) =>
102 run(previousResult, ['sample_with_messages.dart']);
103
104 verifyResult(results) {
105 var lineIterator; 7 var lineIterator;
106 verify(String s) { 8 verify(String s) {
107 lineIterator.moveNext(); 9 lineIterator.moveNext();
108 var value = lineIterator.current; 10 var value = lineIterator.current;
109 expect(value, s); 11 expect(value, s);
110 } 12 }
111 13
112 var output = results.stdout; 14 var expanded = lines.expand((line) => line.split("\n")).toList();
113 var lines = output.split("\n"); 15 lineIterator = expanded.iterator..moveNext();
114 // If it looks like these are CRLF delimited, then use that.
115 if (lines.first.endsWith("\r")) {
116 lines = output.split("\r\n");
117 }
118 lineIterator = lines.iterator..moveNext();
119 verify("Printing messages for en_US"); 16 verify("Printing messages for en_US");
120 verify("This is a message"); 17 verify("This is a message");
121 verify("Another message with parameter hello"); 18 verify("Another message with parameter hello");
122 verify("Characters that need escaping, e.g slashes \\ dollars \${ " 19 verify("Characters that need escaping, e.g slashes \\ dollars \${ "
123 "(curly braces are ok) and xml reserved characters <& and " 20 "(curly braces are ok) and xml reserved characters <& and "
124 "quotes \" parameters 1, 2, and 3"); 21 "quotes \" parameters 1, 2, and 3");
125 verify("This string extends across multiple lines."); 22 verify("This string extends across multiple lines.");
126 verify("1, b, [c, d]"); 23 verify("1, b, [c, d]");
127 verify('"So-called"'); 24 verify('"So-called"');
128 verify("Cette chaîne est toujours traduit"); 25 verify("Cette chaîne est toujours traduit");
(...skipping 19 matching lines...) Expand all
148 verify('none'); 45 verify('none');
149 verify('one'); 46 verify('one');
150 verify('m'); 47 verify('m');
151 verify('f'); 48 verify('f');
152 verify('7 male'); 49 verify('7 male');
153 verify('7 Canadian dollars'); 50 verify('7 Canadian dollars');
154 verify('5 some currency or other.'); 51 verify('5 some currency or other.');
155 verify('1 Canadian dollar'); 52 verify('1 Canadian dollar');
156 verify('2 Canadian dollars'); 53 verify('2 Canadian dollars');
157 54
158 var fr_lines = lines.skip(1).skipWhile( 55 var fr_lines = expanded.skip(1).skipWhile(
159 (line) => !line.contains('----')).toList(); 56 (line) => !line.contains('----')).toList();
160 lineIterator = fr_lines.iterator..moveNext(); 57 lineIterator = fr_lines.iterator..moveNext();
161 verify("Printing messages for fr"); 58 verify("Printing messages for fr");
162 verify("Il s'agit d'un message"); 59 verify("Il s'agit d'un message");
163 verify("Un autre message avec un seul paramètre hello"); 60 verify("Un autre message avec un seul paramètre hello");
164 verify( 61 verify(
165 "Caractères qui doivent être échapper, par exemple barres \\ " 62 "Caractères qui doivent être échapper, par exemple barres \\ "
166 "dollars \${ (les accolades sont ok), et xml/html réservés <& et " 63 "dollars \${ (les accolades sont ok), et xml/html réservés <& et "
167 "des citations \" " 64 "des citations \" "
168 "avec quelques paramètres ainsi 1, 2, et 3"); 65 "avec quelques paramètres ainsi 1, 2, et 3");
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 verify('Alice, Alice gingen zum magasin'); 138 verify('Alice, Alice gingen zum magasin');
242 verify('Null'); 139 verify('Null');
243 verify('ein'); 140 verify('ein');
244 verify('Mann'); 141 verify('Mann');
245 verify('Frau'); 142 verify('Frau');
246 verify('7 Mann'); 143 verify('7 Mann');
247 verify('7 Kanadischen dollar'); 144 verify('7 Kanadischen dollar');
248 verify('5 einige Währung oder anderen.'); 145 verify('5 einige Währung oder anderen.');
249 verify('1 Kanadischer dollar'); 146 verify('1 Kanadischer dollar');
250 verify('2 Kanadischen dollar'); 147 verify('2 Kanadischen dollar');
251 } 148 }
OLDNEW
« no previous file with comments | « pkg/intl/test/message_extraction/sample_with_messages.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698