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

Unified 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 side-by-side diff with in-line comments
Download patch
« lib/logging.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/logging_test.dart
diff --git a/test/logging_test.dart b/test/logging_test.dart
index 94696d8dc894e702d9ef5fe5d6313370f354bcae..e27ee2f3b047ae09e678c7ddea85742c96eb792f 100644
--- a/test/logging_test.dart
+++ b/test/logging_test.dart
@@ -520,4 +520,54 @@ void main() {
equals(['INFO: 5', 'INFO: false', 'INFO: [1, 2, 3]', 'INFO: 10',]));
});
});
+
+ group('recordStackTraceAtLevel', () {
+ var root = Logger.root;
+ tearDown(() {
+ recordStackTraceAtLevel = Level.OFF;
+ root.clearListeners();
+ });
+
+ test('no stack trace by default', () {
+ var records = new List<LogRecord>();
+ root.onRecord.listen(records.add);
+ root.severe('hello');
+ root.warning('hello');
+ root.info('hello');
+ expect(records, hasLength(3));
+ expect(records[0].stackTrace, isNull);
+ expect(records[1].stackTrace, isNull);
+ expect(records[2].stackTrace, isNull);
+ });
+
+ test('trace recorded only on requested levels', () {
+ var records = new List<LogRecord>();
+ recordStackTraceAtLevel = Level.WARNING;
+ root.onRecord.listen(records.add);
+ root.severe('hello');
+ root.warning('hello');
+ root.info('hello');
+ expect(records, hasLength(3));
+ expect(records[0].stackTrace, isNotNull);
+ expect(records[1].stackTrace, isNotNull);
+ expect(records[2].stackTrace, isNull);
+ });
+
+ test('provided trace is used if given', () {
+ var trace;
+ try {
+ throw 'trace';
+ } catch(e, t) {
+ trace = t;
+ }
+ var records = new List<LogRecord>();
+ recordStackTraceAtLevel = Level.WARNING;
+ root.onRecord.listen(records.add);
+ root.severe('hello');
+ root.warning('hello', 'a', trace);
+ expect(records, hasLength(2));
+ expect(records[0].stackTrace, isNot(equals(trace)));
+ expect(records[1].stackTrace, trace);
+ });
+ });
}
« lib/logging.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698