File tree Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change
1
+ import 'package:flutter/foundation.dart' ;
1
2
2
3
/// Whether [debugLog] should do anything.
3
4
///
4
5
/// This has an effect only in a debug build.
5
6
bool debugLogEnabled = false ;
6
7
8
+ /// Used for log inspection in tests.
9
+ @visibleForTesting
10
+ List <String >? debugLogHistory;
11
+
7
12
/// Print a log message, if debug logging is enabled.
8
13
///
9
14
/// In a debug build, if [debugLogEnabled] is true, this prints the given
@@ -26,6 +31,7 @@ bool debugLog(String message) {
26
31
if (debugLogEnabled) {
27
32
print (message); // ignore: avoid_print
28
33
}
34
+ debugLogHistory? .add (message);
29
35
return true ;
30
36
}());
31
37
return true ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import '../api/model/model_checks.dart';
12
12
import '../api/model/submessage_checks.dart' ;
13
13
import '../example_data.dart' as eg;
14
14
import '../stdlib_checks.dart' ;
15
+ import '../test_log.dart' ;
15
16
import 'message_list_test.dart' ;
16
17
import 'store_checks.dart' ;
17
18
import 'test_store.dart' ;
@@ -606,12 +607,15 @@ void main() {
606
607
607
608
test ('ignore submessage event with malformed content' , () async {
608
609
final message = await preparePollMessage (question: 'Old question' );
609
- await store.handleEvent (eg.submessageEvent (message.id, eg.selfUser.userId,
610
- content: {
611
- 'type' : 'question' ,
612
- // Invalid type for question
613
- 'question' : 123 ,
614
- }));
610
+ await checkLogs (() async {
611
+ await store.handleEvent (eg.submessageEvent (message.id, eg.selfUser.userId,
612
+ content: {
613
+ 'type' : 'question' ,
614
+ // Invalid type for question
615
+ 'question' : 123 ,
616
+ }));
617
+ })..length.equals (2 )
618
+ ..last.contains ('Malformed submessage event data for poll' );
615
619
checkNotifiedOnce ();
616
620
checkPoll (message).question.equals ('Old question' );
617
621
});
Original file line number Diff line number Diff line change
1
+ import 'dart:async' ;
2
+
3
+ import 'package:checks/checks.dart' ;
4
+ import 'package:zulip/log.dart' ;
5
+
6
+ Future <Subject <List <String >>> checkLogs (FutureOr <void > Function () callback) async {
7
+ assert (debugLogHistory == null );
8
+ debugLogHistory = [];
9
+ try {
10
+ await callback ();
11
+ return check (debugLogHistory! );
12
+ } finally {
13
+ debugLogHistory = null ;
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments