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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/intl/test/message_extraction/sample_with_messages.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/intl/test/message_extraction/verify_messages.dart
diff --git a/pkg/intl/test/message_extraction/message_extraction_test.dart b/pkg/intl/test/message_extraction/verify_messages.dart
similarity index 57%
copy from pkg/intl/test/message_extraction/message_extraction_test.dart
copy to pkg/intl/test/message_extraction/verify_messages.dart
index e472cdaed51b4e5bad91c27c6bfda3aa0050f80e..2203be633067b600b0b2eb66f62e45811e79f153 100644
--- a/pkg/intl/test/message_extraction/message_extraction_test.dart
+++ b/pkg/intl/test/message_extraction/verify_messages.dart
@@ -1,107 +1,9 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
+library verify_messages;
-library message_extraction_test;
+import "print_to_list.dart";
+import "package:unittest/unittest.dart";
-import 'package:unittest/unittest.dart';
-import 'dart:io';
-import 'dart:async';
-import 'dart:convert';
-import 'package:path/path.dart' as path;
-import '../data_directory.dart';
-
-final dart = Platform.executable;
-
-/** The VM arguments we were given, most important package-root. */
-final vmArgs = Platform.executableArguments;
-
-/**
- * Translate a file path into this test directory, regardless of the
- * working directory.
- */
-String dir([String s]) {
- if (s != null && s.startsWith("--")) { // Don't touch command-line options.
- return s;
- } else {
- return path.join(intlDirectory, 'test', 'message_extraction', s);
- }
-}
-
-main() {
- test("Test round trip message extraction, translation, code generation, "
- "and printing", () {
- deleteGeneratedFiles();
- return extractMessages(null).then((result) {
- return generateTranslationFiles(result);
- }).then((result) {
- return generateCodeFromTranslation(result);
- }).then((result) {
- return runGeneratedCode(result);
- }).then(verifyResult)
- .whenComplete(deleteGeneratedFiles);
- });
-}
-
-void deleteGeneratedFiles() {
- var files = [dir('intl_messages.json'), dir('translation_fr.json'),
- dir('foo_messages_fr.dart'), dir('foo_messages_de_DE.dart'),
- dir('translation_de_DE.json'), dir('foo_messages_all.dart')];
- files.map((name) => new File(name)).forEach((x) {
- if (x.existsSync()) x.deleteSync();});
-}
-
-/**
- * Run the process with the given list of filenames, which we assume
- * are in dir() and need to be qualified in case that's not our working
- * directory.
- */
-Future<ProcessResult> run(ProcessResult previousResult, List<String> filenames)
-{
- // If there's a failure in one of the sub-programs, print its output.
- if (previousResult != null) {
- if (previousResult.exitCode != 0) {
- print("Error running sub-program:");
- }
- print(previousResult.stdout);
- print(previousResult.stderr);
- print("exitCode=${previousResult.exitCode}");
- }
- var filesInTheRightDirectory = filenames.map((x) => dir(x)).toList();
- // Inject the script argument --output-dir in between the script and its
- // arguments.
- var args = []
- ..addAll(vmArgs)
- ..add(filesInTheRightDirectory.first)
- ..addAll(["--output-dir=${dir()}"])
- ..addAll(filesInTheRightDirectory.skip(1));
- var result = Process.run(dart, args, stdoutEncoding: UTF8,
- stderrEncoding: UTF8);
- return result;
-}
-
-Future<ProcessResult> extractMessages(ProcessResult previousResult) => run(
- previousResult,
- ['extract_to_json.dart', '--suppress-warnings', 'sample_with_messages.dart',
- 'part_of_sample_with_messages.dart']);
-
-Future<ProcessResult> generateTranslationFiles(ProcessResult previousResult) =>
- run(
- previousResult,
- ['make_hardcoded_translation.dart', 'intl_messages.json']);
-
-Future<ProcessResult> generateCodeFromTranslation(ProcessResult previousResult)
- => run(
- previousResult,
- ['generate_from_json.dart', '--generated-file-prefix=foo_',
- 'sample_with_messages.dart',
- 'part_of_sample_with_messages.dart', 'translation_fr.json',
- 'translation_de_DE.json' ]);
-
-Future<ProcessResult> runGeneratedCode(ProcessResult previousResult) =>
- run(previousResult, ['sample_with_messages.dart']);
-
-verifyResult(results) {
+verifyResult(ignored) {
var lineIterator;
verify(String s) {
lineIterator.moveNext();
@@ -109,13 +11,8 @@ verifyResult(results) {
expect(value, s);
}
- var output = results.stdout;
- var lines = output.split("\n");
- // If it looks like these are CRLF delimited, then use that.
- if (lines.first.endsWith("\r")) {
- lines = output.split("\r\n");
- }
- lineIterator = lines.iterator..moveNext();
+ var expanded = lines.expand((line) => line.split("\n")).toList();
+ lineIterator = expanded.iterator..moveNext();
verify("Printing messages for en_US");
verify("This is a message");
verify("Another message with parameter hello");
@@ -155,7 +52,7 @@ verifyResult(results) {
verify('1 Canadian dollar');
verify('2 Canadian dollars');
- var fr_lines = lines.skip(1).skipWhile(
+ var fr_lines = expanded.skip(1).skipWhile(
(line) => !line.contains('----')).toList();
lineIterator = fr_lines.iterator..moveNext();
verify("Printing messages for fr");
@@ -248,4 +145,4 @@ verifyResult(results) {
verify('5 einige Währung oder anderen.');
verify('1 Kanadischer dollar');
verify('2 Kanadischen dollar');
-}
+}
« 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