Skip to content

Commit 8e92aa7

Browse files
committed
refactor(tests): replace deprecated toThrow with toThrowWith
Closes dart-archive#1425
1 parent 2c87e84 commit 8e92aa7

14 files changed

+109
-110
lines changed

test/angular_spec.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ main() {
4040
it('should fail with not enough arguments', () {
4141
expect(() {
4242
relaxFnApply((required, alsoRequired) => "happy", [1]);
43-
}).toThrow('Unknown function type, expecting 0 to 5 args.');
43+
}).toThrowWith(message: 'Unknown function type, expecting 0 to 5 args.');
4444
});
4545
});
4646

test/change_detection/watch_group_spec.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ void main() {
293293
watchLast.remove();
294294
expect(watchGrp.fieldCost).toEqual(0);
295295

296-
expect(() => watch.remove()).toThrow('Already deleted!');
296+
expect(() => watch.remove()).toThrowWith(message: 'Already deleted!');
297297
});
298298

299299
it('should eval pure FunctionApply', () {

test/core/core_directive_spec.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void main() {
5252
var injector = applicationFactory().addModule(module).createInjector();
5353
expect(() {
5454
injector.get(DirectiveMap);
55-
}).toThrow('Mapping for attribute foo is already defined (while '
55+
}).toThrowWith(message: 'Mapping for attribute foo is already defined (while '
5656
'processing annottation for field foo of Bad1Component)');
5757
});
5858

@@ -63,7 +63,7 @@ void main() {
6363
var injector = applicationFactory().addModule(module).createInjector();
6464
expect(() {
6565
injector.get(DirectiveMap);
66-
}).toThrow('Attribute annotation for foo is defined more than once '
66+
}).toThrowWith(message: 'Attribute annotation for foo is defined more than once '
6767
'in Bad2Component');
6868
});
6969
});

test/core/parser/lexer_spec.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ main() {
225225
it('should throws exception for invalid exponent', () {
226226
expect(() {
227227
lex("0.5E-");
228-
}).toThrow('Lexer Error: Invalid exponent at column 4 in expression [0.5E-]');
228+
}).toThrowWith(message: 'Lexer Error: Invalid exponent at column 4 in expression [0.5E-]');
229229

230230
expect(() {
231231
lex("0.5E-A");
232-
}).toThrow('Lexer Error: Invalid exponent at column 4 in expression [0.5E-A]');
232+
}).toThrowWith(message: 'Lexer Error: Invalid exponent at column 4 in expression [0.5E-A]');
233233
});
234234

235235
it('should tokenize number starting with a dot', () {
@@ -240,7 +240,7 @@ main() {
240240
it('should throw error on invalid unicode', () {
241241
expect(() {
242242
lex("'\\u1''bla'");
243-
}).toThrow("Lexer Error: Invalid unicode escape [\\u1''b] at column 2 in expression ['\\u1''bla']");
243+
}).toThrowWith(message: "Lexer Error: Invalid unicode escape [\\u1''b] at column 2 in expression ['\\u1''bla']");
244244
});
245245
});
246246
}

test/core/parser/parser_spec.dart

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -165,111 +165,111 @@ main() {
165165

166166
// PARSER ERRORS
167167
it('should throw a reasonable error for unconsumed tokens', () {
168-
expectEval(")").toThrow('Parser Error: Unconsumed token ) at column 1 in [)]');
168+
expectEval(")").toThrowWith(message: 'Parser Error: Unconsumed token ) at column 1 in [)]');
169169
});
170170

171171

172172
it('should throw on missing expected token', () {
173-
expectEval("a(b").toThrow('Parser Error: Missing expected ) the end of the expression [a(b]');
173+
expectEval("a(b").toThrowWith(message: 'Parser Error: Missing expected ) the end of the expression [a(b]');
174174
});
175175

176176

177177
it('should throw on bad assignment', () {
178-
expectEval("5=4").toThrow('Parser Error: Expression 5 is not assignable at column 2 in [5=4]');
179-
expectEval("array[5=4]").toThrow('Parser Error: Expression 5 is not assignable at column 8 in [array[5=4]]');
178+
expectEval("5=4").toThrowWith(message: 'Parser Error: Expression 5 is not assignable at column 2 in [5=4]');
179+
expectEval("array[5=4]").toThrowWith(message: 'Parser Error: Expression 5 is not assignable at column 8 in [array[5=4]]');
180180
});
181181

182182

183183
it('should throw on incorrect ternary operator syntax', () {
184-
expectEval("true?1").toThrow('Parser Error: Conditional expression true?1 requires all 3 expressions');
184+
expectEval("true?1").toThrowWith(message: 'Parser Error: Conditional expression true?1 requires all 3 expressions');
185185
});
186186

187187

188188
it('should throw on non-function function calls', () {
189-
expectEval("4()").toThrow('4 is not a function');
189+
expectEval("4()").toThrowWith(message: '4 is not a function');
190190
});
191191

192192
it("should throw on an unexpected token", (){
193193
expectEval("[1,2] trac")
194-
.toThrow('Parser Error: \'trac\' is an unexpected token at column 7 in [[1,2] trac]');
194+
.toThrowWith(message: 'Parser Error: \'trac\' is an unexpected token at column 7 in [[1,2] trac]');
195195
});
196196

197197
it('should fail gracefully when invoking non-function', () {
198198
expect(() {
199199
parser('a[0]()').eval({'a': [4]});
200-
}).toThrow('a[0] is not a function');
200+
}).toThrowWith(message:'a[0] is not a function');
201201

202202
expect(() {
203203
parser('a[x()]()').eval({'a': [4], 'x': () => 0});
204-
}).toThrow('a[x()] is not a function');
204+
}).toThrowWith(message:'a[x()] is not a function');
205205

206206
expect(() {
207207
parser('{}()').eval({});
208-
}).toThrow('{} is not a function');
208+
}).toThrowWith(message:'{} is not a function');
209209
});
210210

211211

212212
it('should throw on undefined functions (relaxed message)', () {
213-
expectEval("notAFn()").toThrow('notAFn');
213+
expectEval("notAFn()").toThrowWith(message:'notAFn');
214214
});
215215

216216

217217
it('should fail gracefully when missing a function (relaxed message)', () {
218218
expect(() {
219219
parser('doesNotExist()').eval({});
220-
}).toThrow('doesNotExist');
220+
}).toThrowWith(message:'doesNotExist');
221221

222222
expect(() {
223223
parser('exists(doesNotExist())').eval({'exists': () => true});
224-
}).toThrow('doesNotExist');
224+
}).toThrowWith(message:'doesNotExist');
225225

226226
expect(() {
227227
parser('doesNotExists(exists())').eval({'exists': () => true});
228-
}).toThrow('doesNotExist');
228+
}).toThrowWith(message:'doesNotExist');
229229

230230
expect(() {
231231
parser('doesNotExist(1)').eval({});
232-
}).toThrow('doesNotExist');
232+
}).toThrowWith(message:'doesNotExist');
233233

234234
expect(() {
235235
parser('doesNotExist(1, 2)').eval({});
236-
}).toThrow('doesNotExist');
236+
}).toThrowWith(message:'doesNotExist');
237237

238238
expect(() {
239239
parser('doesNotExist()').eval(new TestData());
240-
}).toThrow('doesNotExist');
240+
}).toThrowWith(message:'doesNotExist');
241241

242242
expect(() {
243243
parser('doesNotExist(1)').eval(new TestData());
244-
}).toThrow('doesNotExist');
244+
}).toThrowWith(message:'doesNotExist');
245245

246246
expect(() {
247247
parser('doesNotExist(1, 2)').eval(new TestData());
248-
}).toThrow('doesNotExist');
248+
}).toThrowWith(message:'doesNotExist');
249249

250250
expect(() {
251251
parser('a.doesNotExist()').eval({'a': {}});
252-
}).toThrow('doesNotExist');
252+
}).toThrowWith(message:'doesNotExist');
253253

254254
expect(() {
255255
parser('a.doesNotExist(1)').eval({'a': {}});
256-
}).toThrow('doesNotExist');
256+
}).toThrowWith(message:'doesNotExist');
257257

258258
expect(() {
259259
parser('a.doesNotExist(1, 2)').eval({'a': {}});
260-
}).toThrow('doesNotExist');
260+
}).toThrowWith(message:'doesNotExist');
261261

262262
expect(() {
263263
parser('a.doesNotExist()').eval({'a': new TestData()});
264-
}).toThrow('doesNotExist');
264+
}).toThrowWith(message:'doesNotExist');
265265

266266
expect(() {
267267
parser('a.doesNotExist(1)').eval({'a': new TestData()});
268-
}).toThrow('doesNotExist');
268+
}).toThrowWith(message:'doesNotExist');
269269

270270
expect(() {
271271
parser('a.doesNotExist(1, 2)').eval({'a': new TestData()});
272-
}).toThrow('doesNotExist');
272+
}).toThrowWith(message:'doesNotExist');
273273
});
274274

275275

@@ -278,7 +278,7 @@ main() {
278278

279279
expect(eval('null')).toBe(null);
280280
expect(() => eval('map.null'))
281-
.toThrow("Identifier 'null' is a reserved word.");
281+
.toThrowWith(message:"Identifier 'null' is a reserved word.");
282282
});
283283

284284

@@ -304,14 +304,14 @@ main() {
304304
it('should pass exceptions through getters', () {
305305
expect(() {
306306
parser('boo').eval(new ScopeWithErrors());
307-
}).toThrow('boo to you');
307+
}).toThrowWith(message:'boo to you');
308308
});
309309

310310

311311
it('should pass noSuchMethodExceptions through getters', () {
312312
expect(() {
313313
parser('getNoSuchMethod').eval(new ScopeWithErrors());
314-
}).toThrow("null");
314+
}).toThrowWith(message:"null");
315315
// Dartium throws: The null object does not have a method 'iDontExist'
316316
// Chrome throws: NullError: Cannot call "iDontExist$0" on null
317317
// Firefox throws: NullError: null has no properties
@@ -321,14 +321,14 @@ main() {
321321
it('should pass exceptions through methods', () {
322322
expect(() {
323323
parser('foo()').eval(new ScopeWithErrors());
324-
}).toThrow('foo to you');
324+
}).toThrowWith(message:'foo to you');
325325
});
326326

327327

328328
it('should fail if reflected object has no property', () {
329329
expect(() {
330330
parser('notAProperty').eval(new TestData());
331-
}).toThrow("notAProperty");
331+
}).toThrowWith(message:"notAProperty");
332332
});
333333

334334

@@ -344,22 +344,22 @@ main() {
344344

345345

346346
it('should only allow identifier or keyword as formatter names', () {
347-
expect(() => parser('"Foo"|(')).toThrow('identifier or keyword');
348-
expect(() => parser('"Foo"|1234')).toThrow('identifier or keyword');
349-
expect(() => parser('"Foo"|"uppercase"')).toThrow('identifier or keyword');
347+
expect(() => parser('"Foo"|(')).toThrowWith(message:'identifier or keyword');
348+
expect(() => parser('"Foo"|1234')).toThrowWith(message:'identifier or keyword');
349+
expect(() => parser('"Foo"|"uppercase"')).toThrowWith(message:'identifier or keyword');
350350
});
351351

352352

353353
it('should only allow identifier or keyword as member names', () {
354-
expect(() => parser('x.(')).toThrow('identifier or keyword');
355-
expect(() => parser('x. 1234')).toThrow('identifier or keyword');
356-
expect(() => parser('x."foo"')).toThrow('identifier or keyword');
354+
expect(() => parser('x.(')).toThrowWith(message:'identifier or keyword');
355+
expect(() => parser('x. 1234')).toThrowWith(message:'identifier or keyword');
356+
expect(() => parser('x."foo"')).toThrowWith(message:'identifier or keyword');
357357
});
358358

359359

360360
it('should only allow identifier, string, or keyword as object literal key', () {
361-
expect(() => parser('{(:0}')).toThrow('expected identifier, keyword, or string');
362-
expect(() => parser('{1234:0}')).toThrow('expected identifier, keyword, or string');
361+
expect(() => parser('{(:0}')).toThrowWith(message:'expected identifier, keyword, or string');
362+
expect(() => parser('{1234:0}')).toThrowWith(message:'expected identifier, keyword, or string');
363363
});
364364
});
365365

@@ -433,15 +433,15 @@ main() {
433433
it('should rethrow an error from a function', () {
434434
expect(() {
435435
parser("causeException()").eval(new TestData());
436-
}).toThrow('NoSuchMethodError');
436+
}).toThrowWith(message:'NoSuchMethodError');
437437
});
438438

439439

440440
xit('should throw a nice error for type mismatch', () {
441441
context['obj'] = new SetterObject();
442442
expect(() {
443443
eval('obj.integer = "hello"');
444-
}).toThrow("Eval Error: Caught type 'String' is not a subtype of type 'int' of 'value'. while evaling [obj.integer = \"hello\"]");
444+
}).toThrowWith(message:"Eval Error: Caught type 'String' is not a subtype of type 'int' of 'value'. while evaling [obj.integer = \"hello\"]");
445445
});
446446
});
447447

@@ -468,7 +468,7 @@ main() {
468468
for (String reserved in RESERVED_WORDS) {
469469
expect(() {
470470
parser("o.$reserved()").eval({ 'o': new Object() });
471-
}).toThrow('Undefined function $reserved');
471+
}).toThrowWith(message:'Undefined function $reserved');
472472
expect(parser("o.$reserved()").eval({ 'o': { reserved: () => reserved }})).toEqual(reserved);
473473
}
474474
});
@@ -499,7 +499,7 @@ main() {
499499
if ([ "true", "false", "null"].contains(reserved)) continue;
500500
expect(() {
501501
parser("$reserved()").eval(new Object());
502-
}).toThrow('Undefined function $reserved');
502+
}).toThrowWith(message:'Undefined function $reserved');
503503
expect(parser("$reserved()").eval({ reserved: () => reserved })).toEqual(reserved);
504504
}
505505
});
@@ -644,7 +644,7 @@ main() {
644644

645645
it('should catch NoSuchMethod', () {
646646
context = {'a': {'b': 23}};
647-
expect(() => eval('a.b.c.d')).toThrow('NoSuchMethod');
647+
expect(() => eval('a.b.c.d')).toThrowWith(message:'NoSuchMethod');
648648
});
649649

650650

@@ -816,7 +816,7 @@ main() {
816816
it('should throw exception on non-closed bracket', () {
817817
expect(() {
818818
eval('[].count(');
819-
}).toThrow('Unexpected end of expression: [].count(');
819+
}).toThrowWith(message:'Unexpected end of expression: [].count(');
820820
});
821821

822822

@@ -1058,16 +1058,16 @@ main() {
10581058

10591059

10601060
it('should be an error to use the same name twice', () {
1061-
expect(() => parser('foo(a: 0, a: 1)')).toThrow("Duplicate argument named 'a' at column 11");
1062-
expect(() => parser('foo(a: 0, b: 1, a: 2)')).toThrow("Duplicate argument named 'a' at column 17");
1063-
expect(() => parser('foo(0, a: 1, a: 2)')).toThrow("Duplicate argument named 'a' at column 14");
1064-
expect(() => parser('foo(0, a: 1, b: 2, a: 3)')).toThrow("Duplicate argument named 'a' at column 20");
1061+
expect(() => parser('foo(a: 0, a: 1)')).toThrowWith(message:"Duplicate argument named 'a' at column 11");
1062+
expect(() => parser('foo(a: 0, b: 1, a: 2)')).toThrowWith(message:"Duplicate argument named 'a' at column 17");
1063+
expect(() => parser('foo(0, a: 1, a: 2)')).toThrowWith(message:"Duplicate argument named 'a' at column 14");
1064+
expect(() => parser('foo(0, a: 1, b: 2, a: 3)')).toThrowWith(message:"Duplicate argument named 'a' at column 20");
10651065
});
10661066

10671067

10681068
it('should be an error to use Dart reserved words as names', () {
1069-
expect(() => parser('foo(if: 0)')).toThrow("Cannot use Dart reserved word 'if' as named argument at column 5");
1070-
expect(() => parser('foo(a: 0, class: 0)')).toThrow("Cannot use Dart reserved word 'class' as named argument at column 11");
1069+
expect(() => parser('foo(if: 0)')).toThrowWith(message:"Cannot use Dart reserved word 'if' as named argument at column 5");
1070+
expect(() => parser('foo(a: 0, class: 0)')).toThrowWith(message:"Cannot use Dart reserved word 'class' as named argument at column 11");
10711071
});
10721072

10731073

@@ -1129,10 +1129,10 @@ main() {
11291129
it('should parse formatters', () {
11301130
expect(() {
11311131
eval("1|nonexistent");
1132-
}).toThrow('No formatter \'nonexistent\' found!');
1132+
}).toThrowWith(message:'No formatter \'nonexistent\' found!');
11331133
expect(() {
11341134
eval("1|nonexistent", formatters);
1135-
}).toThrow('No formatter \'nonexistent\' found!');
1135+
}).toThrowWith(message:'No formatter \'nonexistent\' found!');
11361136

11371137
context['offset'] = 3;
11381138
expect(eval("'abcd'|substring:1:offset")).toEqual("bc");
@@ -1143,7 +1143,7 @@ main() {
11431143
var expression = parser("'World'|hello");
11441144
expect(() {
11451145
expression.eval({}, formatters);
1146-
}).toThrow('No formatter \'hello\' found!');
1146+
}).toThrowWith(message:'No formatter \'hello\' found!');
11471147

11481148
var module = new Module()
11491149
..bind(FormatterMap)
@@ -1157,10 +1157,10 @@ main() {
11571157
it('should not allow formatters in a chain', () {
11581158
expect(() {
11591159
parser("1;'World'|hello");
1160-
}).toThrow('Cannot have a formatter in a chain the end of the expression [1;\'World\'|hello]');
1160+
}).toThrowWith(message:'Cannot have a formatter in a chain the end of the expression [1;\'World\'|hello]');
11611161
expect(() {
11621162
parser("'World'|hello;1");
1163-
}).toThrow('Cannot have a formatter in a chain at column 15 in [\'World\'|hello;1]');
1163+
}).toThrowWith(message:'Cannot have a formatter in a chain at column 15 in [\'World\'|hello;1]');
11641164
});
11651165
});
11661166
});

0 commit comments

Comments
 (0)