|
| 1 | +import 'package:test/test.dart'; |
| 2 | +import 'package:logger/logger.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + LogEvent event = LogEvent( |
| 6 | + Level.debug, |
| 7 | + "some message", |
| 8 | + "some error", |
| 9 | + StackTrace.current, |
| 10 | + ); |
| 11 | + |
| 12 | + test('represent event on a single line (ignoring stacktrace)', () { |
| 13 | + var outputs = SimplePrinter().log(event); |
| 14 | + |
| 15 | + expect(outputs, hasLength(1)); |
| 16 | + expect(outputs[0], '[D] some message ERROR: some error'); |
| 17 | + }); |
| 18 | + |
| 19 | + test('print time', () { |
| 20 | + var printer = SimplePrinter(printTime: true); |
| 21 | + |
| 22 | + expect(printer.log(event)[0], contains('TIME')); |
| 23 | + }); |
| 24 | + |
| 25 | + test('omits error when null', () { |
| 26 | + LogEvent withoutError = LogEvent( |
| 27 | + Level.debug, |
| 28 | + "some message", |
| 29 | + null, |
| 30 | + StackTrace.current, |
| 31 | + ); |
| 32 | + var outputs = SimplePrinter().log(withoutError); |
| 33 | + |
| 34 | + expect(outputs[0], isNot(contains('ERROR'))); |
| 35 | + }); |
| 36 | + |
| 37 | + test('deal with Map type message', () { |
| 38 | + var withMap = LogEvent( |
| 39 | + Level.debug, |
| 40 | + {"foo": 123}, |
| 41 | + "some error", |
| 42 | + StackTrace.current, |
| 43 | + ); |
| 44 | + |
| 45 | + expect( |
| 46 | + SimplePrinter().log(withMap)[0], |
| 47 | + '[D] {"foo":123} ERROR: some error', |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + test('deal with Iterable type message', () { |
| 52 | + var withIterable = LogEvent( |
| 53 | + Level.debug, |
| 54 | + [1, 2, 3, 4], |
| 55 | + "some error", |
| 56 | + StackTrace.current, |
| 57 | + ); |
| 58 | + |
| 59 | + expect( |
| 60 | + SimplePrinter().log(withIterable)[0], |
| 61 | + '[D] [1,2,3,4] ERROR: some error', |
| 62 | + ); |
| 63 | + }); |
| 64 | +} |
0 commit comments