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

Side by Side Diff: sdk/lib/_internal/pub/test/test_pub.dart

Issue 184113007: Support JSON output for pub build. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Extend timeout. Created 6 years, 9 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 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub
6 /// tests are integration tests that stage some stuff on the file system, run 6 /// tests are integration tests that stage some stuff on the file system, run
7 /// pub, and then validate the results. This library provides an API to build 7 /// pub, and then validate the results. This library provides an API to build
8 /// tests like that. 8 /// tests like that.
9 library test_pub; 9 library test_pub;
10 10
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 schedule( 374 schedule(
375 () => createSymlink( 375 () => createSymlink(
376 path.join(sandboxDir, target), 376 path.join(sandboxDir, target),
377 path.join(sandboxDir, symlink)), 377 path.join(sandboxDir, symlink)),
378 'symlinking $target to $symlink'); 378 'symlinking $target to $symlink');
379 } 379 }
380 380
381 /// Schedules a call to the Pub command-line utility. 381 /// Schedules a call to the Pub command-line utility.
382 /// 382 ///
383 /// Runs Pub with [args] and validates that its results match [output] (or 383 /// Runs Pub with [args] and validates that its results match [output] (or
384 /// [outputJson]), [error], and [exitCode]. If [outputJson] is given, validates 384 /// [outputJson]), [error], and [exitCode].
385 /// that pub outputs stringified JSON matching that object. 385 ///
386 /// If [outputJson] is given, validates that pub outputs stringified JSON
387 /// matching that object, which can be a literal JSON object or any other
388 /// [Matcher].
386 void schedulePub({List args, Pattern output, Pattern error, outputJson, 389 void schedulePub({List args, Pattern output, Pattern error, outputJson,
387 Future<Uri> tokenEndpoint, int exitCode: exit_codes.SUCCESS}) { 390 Future<Uri> tokenEndpoint, int exitCode: exit_codes.SUCCESS}) {
388 // Cannot pass both output and outputJson. 391 // Cannot pass both output and outputJson.
389 assert(output == null || outputJson == null); 392 assert(output == null || outputJson == null);
390 393
391 var pub = startPub(args: args, tokenEndpoint: tokenEndpoint); 394 var pub = startPub(args: args, tokenEndpoint: tokenEndpoint);
392 pub.shouldExit(exitCode); 395 pub.shouldExit(exitCode);
393 396
394 var failures = []; 397 var failures = [];
395 var stderr; 398 var stderr;
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 808
806 // If any lines mismatched, show the expected and actual. 809 // If any lines mismatched, show the expected and actual.
807 if (failed) { 810 if (failed) {
808 failures.add('Expected $pipe:'); 811 failures.add('Expected $pipe:');
809 failures.addAll(expected.map((line) => '| $line')); 812 failures.addAll(expected.map((line) => '| $line'));
810 failures.add('Got:'); 813 failures.add('Got:');
811 failures.addAll(results); 814 failures.addAll(results);
812 } 815 }
813 } 816 }
814 817
818 /// Validates that [actualText] is a string of JSON that matches [expected],
819 /// which may be a literal JSON object, or any other [Matcher].
815 void _validateOutputJson(List<String> failures, String pipe, 820 void _validateOutputJson(List<String> failures, String pipe,
816 expected, String actualText) { 821 expected, String actualText) {
817 var actual; 822 var actual;
818 try { 823 try {
819 actual = JSON.decode(actualText); 824 actual = JSON.decode(actualText);
820 } on FormatException catch(error) { 825 } on FormatException catch(error) {
821 failures.add('Expected $pipe JSON:'); 826 failures.add('Expected $pipe JSON:');
822 failures.add(expected); 827 failures.add(expected);
823 failures.add('Got invalid JSON:'); 828 failures.add('Got invalid JSON:');
824 failures.add(actualText); 829 failures.add(actualText);
825 } 830 }
826 831
827 // Do a deep comparison of the JSON objects. 832 // Match against the expectation.
828 expect(actual, equals(expected)); 833 expect(actual, expected);
829 } 834 }
830 835
831 /// A function that creates a [Validator] subclass. 836 /// A function that creates a [Validator] subclass.
832 typedef Validator ValidatorCreator(Entrypoint entrypoint); 837 typedef Validator ValidatorCreator(Entrypoint entrypoint);
833 838
834 /// Schedules a single [Validator] to run on the [appPath]. Returns a scheduled 839 /// Schedules a single [Validator] to run on the [appPath]. Returns a scheduled
835 /// Future that contains the errors and warnings produced by that validator. 840 /// Future that contains the errors and warnings produced by that validator.
836 Future<Pair<List<String>, List<String>>> schedulePackageValidation( 841 Future<Pair<List<String>, List<String>>> schedulePackageValidation(
837 ValidatorCreator fn) { 842 ValidatorCreator fn) {
838 return schedule(() { 843 return schedule(() {
(...skipping 24 matching lines...) Expand all
863 _lastMatcher.matches(item.last, matchState); 868 _lastMatcher.matches(item.last, matchState);
864 } 869 }
865 870
866 Description describe(Description description) { 871 Description describe(Description description) {
867 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); 872 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]);
868 } 873 }
869 } 874 }
870 875
871 /// A [StreamMatcher] that matches multiple lines of output. 876 /// A [StreamMatcher] that matches multiple lines of output.
872 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); 877 StreamMatcher emitsLines(String output) => inOrder(output.split("\n"));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698