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

Side by Side Diff: test/runner/browser/runner_test.dart

Issue 1083433002: More gracefully handle load errors. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 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
« no previous file with comments | « test/runner/browser/loader_test.dart ('k') | test/runner/loader_test.dart » ('j') | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 @TestOn("vm") 5 @TestOn("vm")
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 import 'package:test/src/util/exit_codes.dart' as exit_codes; 10 import 'package:test/src/util/exit_codes.dart' as exit_codes;
(...skipping 24 matching lines...) Expand all
35 }); 35 });
36 36
37 group("fails gracefully if", () { 37 group("fails gracefully if", () {
38 test("a test file fails to compile", () { 38 test("a test file fails to compile", () {
39 var testPath = p.join(_sandbox, "test.dart"); 39 var testPath = p.join(_sandbox, "test.dart");
40 new File(testPath).writeAsStringSync("invalid Dart file"); 40 new File(testPath).writeAsStringSync("invalid Dart file");
41 var result = _runUnittest(["-p", "chrome", "test.dart"]); 41 var result = _runUnittest(["-p", "chrome", "test.dart"]);
42 42
43 expect(result.stdout, 43 expect(result.stdout,
44 contains("Expected a declaration, but got 'invalid'")); 44 contains("Expected a declaration, but got 'invalid'"));
45 expect(result.stderr, equals( 45 expect(result.stdout, allOf([
46 'Failed to load "${p.relative(testPath, from: _sandbox)}": dart2js ' 46 contains('-1: load error'),
47 'failed.\n')); 47 contains(
48 expect(result.exitCode, equals(exit_codes.data)); 48 'Failed to load "${p.relative(testPath, from: _sandbox)}": dart2js '
49 'failed.')
50 ]));
51 expect(result.exitCode, equals(1));
49 }); 52 });
50 53
51 test("a test file throws", () { 54 test("a test file throws", () {
52 var testPath = p.join(_sandbox, "test.dart"); 55 var testPath = p.join(_sandbox, "test.dart");
53 new File(testPath).writeAsStringSync("void main() => throw 'oh no';"); 56 new File(testPath).writeAsStringSync("void main() => throw 'oh no';");
54 57
55 var result = _runUnittest(["-p", "chrome", "test.dart"]); 58 var result = _runUnittest(["-p", "chrome", "test.dart"]);
56 expect(result.stderr, startsWith( 59 expect(result.stdout, allOf([
57 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no\n')); 60 contains('-1: load error'),
58 expect(result.exitCode, equals(exit_codes.data)); 61 contains(
62 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no')
63 ]));
64 expect(result.exitCode, equals(1));
59 }); 65 });
60 66
61 test("a test file doesn't have a main defined", () { 67 test("a test file doesn't have a main defined", () {
62 var testPath = p.join(_sandbox, "test.dart"); 68 var testPath = p.join(_sandbox, "test.dart");
63 new File(testPath).writeAsStringSync("void foo() {}"); 69 new File(testPath).writeAsStringSync("void foo() {}");
64 70
65 var result = _runUnittest(["-p", "chrome", "test.dart"]); 71 var result = _runUnittest(["-p", "chrome", "test.dart"]);
66 expect(result.stderr, startsWith( 72 expect(result.stdout, allOf([
67 'Failed to load "${p.relative(testPath, from: _sandbox)}": No ' 73 contains('-1: load error'),
68 'top-level main() function defined.\n')); 74 contains(
69 expect(result.exitCode, equals(exit_codes.data)); 75 'Failed to load "${p.relative(testPath, from: _sandbox)}": No '
76 'top-level main() function defined.')
77 ]));
78 expect(result.exitCode, equals(1));
70 }); 79 });
71 80
72 test("a test file has a non-function main", () { 81 test("a test file has a non-function main", () {
73 var testPath = p.join(_sandbox, "test.dart"); 82 var testPath = p.join(_sandbox, "test.dart");
74 new File(testPath).writeAsStringSync("int main;"); 83 new File(testPath).writeAsStringSync("int main;");
75 84
76 var result = _runUnittest(["-p", "chrome", "test.dart"]); 85 var result = _runUnittest(["-p", "chrome", "test.dart"]);
77 expect(result.stderr, startsWith( 86 expect(result.stdout, allOf([
78 'Failed to load "${p.relative(testPath, from: _sandbox)}": Top-level ' 87 contains('-1: load error'),
79 'main getter is not a function.\n')); 88 contains(
80 expect(result.exitCode, equals(exit_codes.data)); 89 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
90 'Top-level main getter is not a function.\n')
91 ]));
92 expect(result.exitCode, equals(1));
81 }); 93 });
82 94
83 test("a test file has a main with arguments", () { 95 test("a test file has a main with arguments", () {
84 var testPath = p.join(_sandbox, "test.dart"); 96 var testPath = p.join(_sandbox, "test.dart");
85 new File(testPath).writeAsStringSync("void main(arg) {}"); 97 new File(testPath).writeAsStringSync("void main(arg) {}");
86 98
87 var result = _runUnittest(["-p", "chrome", "test.dart"]); 99 var result = _runUnittest(["-p", "chrome", "test.dart"]);
88 expect(result.stderr, startsWith( 100 expect(result.stdout, allOf([
89 'Failed to load "${p.relative(testPath, from: _sandbox)}": Top-level ' 101 contains('-1: load error'),
90 'main() function takes arguments.\n')); 102 contains(
91 expect(result.exitCode, equals(exit_codes.data)); 103 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
104 'Top-level main() function takes arguments.\n')
105 ]));
106 expect(result.exitCode, equals(1));
92 }); 107 });
93 108
94 // TODO(nweiz): test what happens when a test file is unreadable once issue 109 // TODO(nweiz): test what happens when a test file is unreadable once issue
95 // 15078 is fixed. 110 // 15078 is fixed.
96 }); 111 });
97 112
98 group("runs successful tests", () { 113 group("runs successful tests", () {
99 test("on Chrome", () { 114 test("on Chrome", () {
100 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 115 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
101 var result = _runUnittest(["-p", "chrome", "test.dart"]); 116 var result = _runUnittest(["-p", "chrome", "test.dart"]);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 """); 216 """);
202 217
203 var result = _runUnittest(["-p", "chrome", "test.dart"]); 218 var result = _runUnittest(["-p", "chrome", "test.dart"]);
204 expect(result.stdout, contains("Hello,\nworld!\n")); 219 expect(result.stdout, contains("Hello,\nworld!\n"));
205 expect(result.exitCode, equals(0)); 220 expect(result.exitCode, equals(0));
206 }); 221 });
207 } 222 }
208 223
209 ProcessResult _runUnittest(List<String> args) => 224 ProcessResult _runUnittest(List<String> args) =>
210 runUnittest(args, workingDirectory: _sandbox); 225 runUnittest(args, workingDirectory: _sandbox);
OLDNEW
« no previous file with comments | « test/runner/browser/loader_test.dart ('k') | test/runner/loader_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698