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

Side by Side Diff: test/runner/loader_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/runner_test.dart ('k') | test/runner/pub_serve_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/backend/state.dart'; 10 import 'package:test/src/backend/state.dart';
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 new Directory(_sandbox).deleteSync(recursive: true); 42 new Directory(_sandbox).deleteSync(recursive: true);
43 return _loader.close(); 43 return _loader.close();
44 }); 44 });
45 45
46 group(".loadFile()", () { 46 group(".loadFile()", () {
47 var suite; 47 var suite;
48 setUp(() { 48 setUp(() {
49 /// TODO(nweiz): Use scheduled_test for this once it's compatible with 49 /// TODO(nweiz): Use scheduled_test for this once it's compatible with
50 /// this version of test. 50 /// this version of test.
51 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); 51 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests);
52 return _loader.loadFile(p.join(_sandbox, 'a_test.dart')).then((suites) { 52 return _loader.loadFile(p.join(_sandbox, 'a_test.dart')).toList()
53 .then((suites) {
53 expect(suites, hasLength(1)); 54 expect(suites, hasLength(1));
54 suite = suites.first; 55 suite = suites.first;
55 }); 56 });
56 }); 57 });
57 58
58 test("returns a suite with the file path and platform", () { 59 test("returns a suite with the file path and platform", () {
59 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart'))); 60 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart')));
60 expect(suite.platform, equals('VM')); 61 expect(suite.platform, equals('VM'));
61 }); 62 });
62 63
(...skipping 18 matching lines...) Expand all
81 82
82 test("can load and run a failing test", () { 83 test("can load and run a failing test", () {
83 var liveTest = suite.tests[1].load(suite); 84 var liveTest = suite.tests[1].load(suite);
84 expectSingleFailure(liveTest); 85 expectSingleFailure(liveTest);
85 return liveTest.run().whenComplete(() => liveTest.close()); 86 return liveTest.run().whenComplete(() => liveTest.close());
86 }); 87 });
87 88
88 test("throws a nice error if the package root doesn't exist", () { 89 test("throws a nice error if the package root doesn't exist", () {
89 var loader = new Loader([TestPlatform.vm]); 90 var loader = new Loader([TestPlatform.vm]);
90 expect( 91 expect(
91 loader.loadFile(p.join(_sandbox, 'a_test.dart')) 92 loader.loadFile(p.join(_sandbox, 'a_test.dart')).first
92 .whenComplete(loader.close), 93 .whenComplete(loader.close),
93 throwsA(isLoadException( 94 throwsA(isLoadException(
94 "Directory ${p.join(_sandbox, 'packages')} does not exist."))); 95 "Directory ${p.join(_sandbox, 'packages')} does not exist.")));
95 }); 96 });
96 }); 97 });
97 98
98 group(".loadDir()", () { 99 group(".loadDir()", () {
99 test("ignores non-Dart files", () { 100 test("ignores non-Dart files", () {
100 new File(p.join(_sandbox, 'a_test.txt')).writeAsStringSync(_tests); 101 new File(p.join(_sandbox, 'a_test.txt')).writeAsStringSync(_tests);
101 expect(_loader.loadDir(_sandbox), completion(isEmpty)); 102 expect(_loader.loadDir(_sandbox).toList(), completion(isEmpty));
102 }); 103 });
103 104
104 test("ignores files in packages/ directories", () { 105 test("ignores files in packages/ directories", () {
105 var dir = p.join(_sandbox, 'packages'); 106 var dir = p.join(_sandbox, 'packages');
106 new Directory(dir).createSync(); 107 new Directory(dir).createSync();
107 new File(p.join(dir, 'a_test.dart')).writeAsStringSync(_tests); 108 new File(p.join(dir, 'a_test.dart')).writeAsStringSync(_tests);
108 expect(_loader.loadDir(_sandbox), completion(isEmpty)); 109 expect(_loader.loadDir(_sandbox).toList(), completion(isEmpty));
109 }); 110 });
110 111
111 test("ignores files that don't end in _test.dart", () { 112 test("ignores files that don't end in _test.dart", () {
112 new File(p.join(_sandbox, 'test.dart')).writeAsStringSync(_tests); 113 new File(p.join(_sandbox, 'test.dart')).writeAsStringSync(_tests);
113 expect(_loader.loadDir(_sandbox), completion(isEmpty)); 114 expect(_loader.loadDir(_sandbox).toList(), completion(isEmpty));
114 }); 115 });
115 116
116 group("with suites loaded from a directory", () { 117 group("with suites loaded from a directory", () {
117 var suites; 118 var suites;
118 setUp(() { 119 setUp(() {
119 /// TODO(nweiz): Use scheduled_test for this once it's compatible with 120 /// TODO(nweiz): Use scheduled_test for this once it's compatible with
120 /// this version of test. 121 /// this version of test.
121 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); 122 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests);
122 new File(p.join(_sandbox, 'another_test.dart')) 123 new File(p.join(_sandbox, 'another_test.dart'))
123 .writeAsStringSync(_tests); 124 .writeAsStringSync(_tests);
124 new Directory(p.join(_sandbox, 'dir')).createSync(); 125 new Directory(p.join(_sandbox, 'dir')).createSync();
125 new File(p.join(_sandbox, 'dir/sub_test.dart')) 126 new File(p.join(_sandbox, 'dir/sub_test.dart'))
126 .writeAsStringSync(_tests); 127 .writeAsStringSync(_tests);
127 128
128 return _loader.loadDir(_sandbox).then((suites_) => suites = suites_); 129 return _loader.loadDir(_sandbox).toList()
130 .then((suites_) => suites = suites_);
129 }); 131 });
130 132
131 test("gives those suites the correct paths", () { 133 test("gives those suites the correct paths", () {
132 expect(suites.map((suite) => suite.path), unorderedEquals([ 134 expect(suites.map((suite) => suite.path), unorderedEquals([
133 p.join(_sandbox, 'a_test.dart'), 135 p.join(_sandbox, 'a_test.dart'),
134 p.join(_sandbox, 'another_test.dart'), 136 p.join(_sandbox, 'another_test.dart'),
135 p.join(_sandbox, 'dir/sub_test.dart') 137 p.join(_sandbox, 'dir/sub_test.dart')
136 ])); 138 ]));
137 }); 139 });
138 140
139 test("can run tests in those suites", () { 141 test("can run tests in those suites", () {
140 var suite = suites.firstWhere((suite) => suite.path.contains("a_test")); 142 var suite = suites.firstWhere((suite) => suite.path.contains("a_test"));
141 var liveTest = suite.tests[1].load(suite); 143 var liveTest = suite.tests[1].load(suite);
142 expectSingleFailure(liveTest); 144 expectSingleFailure(liveTest);
143 return liveTest.run().whenComplete(() => liveTest.close()); 145 return liveTest.run().whenComplete(() => liveTest.close());
144 }); 146 });
145 }); 147 });
146 }); 148 });
147 } 149 }
OLDNEW
« no previous file with comments | « test/runner/browser/runner_test.dart ('k') | test/runner/pub_serve_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698