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

Side by Side Diff: test/logging_test.dart

Issue 1132533003: Add option to automatically record stack trace in logging (fixes #2) (Closed) Base URL: https://github.com/dart-lang/logging@master
Patch Set: Created 5 years, 7 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
« lib/logging.dart ('K') | « pubspec.yaml ('k') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library logging_test; 5 library logging_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:logging/logging.dart'; 9 import 'package:logging/logging.dart';
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 513
514 root.info(5); 514 root.info(5);
515 root.info(false); 515 root.info(false);
516 root.info([1, 2, 3]); 516 root.info([1, 2, 3]);
517 root.info(() => 10); 517 root.info(() => 10);
518 518
519 expect(messages, 519 expect(messages,
520 equals(['INFO: 5', 'INFO: false', 'INFO: [1, 2, 3]', 'INFO: 10',])); 520 equals(['INFO: 5', 'INFO: false', 'INFO: [1, 2, 3]', 'INFO: 10',]));
521 }); 521 });
522 }); 522 });
523
524 group('recordStackTraceAtLevel', () {
525 var root = Logger.root;
526 tearDown(() {
527 recordStackTraceAtLevel = Level.OFF;
528 root.clearListeners();
529 });
530
531 test('no stack trace by default', () {
532 var records = new List<LogRecord>();
533 root.onRecord.listen(records.add);
534 root.severe('hello');
535 root.warning('hello');
536 root.info('hello');
537 expect(records, hasLength(3));
538 expect(records[0].stackTrace, isNull);
539 expect(records[1].stackTrace, isNull);
540 expect(records[2].stackTrace, isNull);
541 });
542
543 test('trace recorded only on requested levels', () {
544 var records = new List<LogRecord>();
545 recordStackTraceAtLevel = Level.WARNING;
546 root.onRecord.listen(records.add);
547 root.severe('hello');
548 root.warning('hello');
549 root.info('hello');
550 expect(records, hasLength(3));
551 expect(records[0].stackTrace, isNotNull);
552 expect(records[1].stackTrace, isNotNull);
553 expect(records[2].stackTrace, isNull);
554 });
555
556 test('provided trace is used if given', () {
557 var trace;
558 try {
559 throw 'trace';
560 } catch(e, t) {
561 trace = t;
562 }
563 var records = new List<LogRecord>();
564 recordStackTraceAtLevel = Level.WARNING;
565 root.onRecord.listen(records.add);
566 root.severe('hello');
567 root.warning('hello', 'a', trace);
568 expect(records, hasLength(2));
569 expect(records[0].stackTrace, isNot(equals(trace)));
570 expect(records[1].stackTrace, trace);
571 });
572 });
523 } 573 }
OLDNEW
« lib/logging.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698