File tree Expand file tree Collapse file tree 3 files changed +27
-13
lines changed Expand file tree Collapse file tree 3 files changed +27
-13
lines changed Original file line number Diff line number Diff line change @@ -574,7 +574,7 @@ class YamlEditor {
574
574
_yaml);
575
575
}
576
576
577
- final actualTree = loadYamlNode (_yaml);
577
+ final actualTree = withYamlWarningCallback (() => loadYamlNode (_yaml) );
578
578
if (! deepEquals (actualTree, expectedTree)) {
579
579
throw createAssertionError (
580
580
'Modification did not result in expected result.' ,
Original file line number Diff line number Diff line change @@ -8,14 +8,34 @@ import 'package:yaml/yaml.dart';
8
8
import 'editor.dart' ;
9
9
import 'wrap.dart' ;
10
10
11
+ /// Invoke [fn] while setting [yamlWarningCallback] to [warn] , and restore
12
+ /// [YamlWarningCallback] after [fn] returns.
13
+ ///
14
+ /// Defaults to a [warn] function that ignores all warnings.
15
+ T withYamlWarningCallback <T >(
16
+ T Function () fn, {
17
+ YamlWarningCallback warn = _ignoreWarning,
18
+ }) {
19
+ final original = yamlWarningCallback;
20
+ try {
21
+ yamlWarningCallback = warn;
22
+ return fn ();
23
+ } finally {
24
+ yamlWarningCallback = original;
25
+ }
26
+ }
27
+
28
+ void _ignoreWarning (String warning, [SourceSpan ? span]) {/* ignore warning */ }
29
+
11
30
/// Determines if [string] is dangerous by checking if parsing the plain string
12
31
/// can return a result different from [string] .
13
32
///
14
33
/// This function is also capable of detecting if non-printable characters are
15
34
/// in [string] .
16
35
bool isDangerousString (String string) {
17
36
try {
18
- if (loadYamlNode (string).value != string) {
37
+ final node = withYamlWarningCallback (() => loadYamlNode (string));
38
+ if (node.value != string) {
19
39
return true ;
20
40
}
21
41
Original file line number Diff line number Diff line change 2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- import 'dart:async' ;
6
- import 'dart:math' ;
5
+ import 'dart:math' show Random;
7
6
8
7
import 'package:test/test.dart' ;
9
8
import 'package:yaml/yaml.dart' ;
@@ -44,15 +43,10 @@ dev_dependencies:
44
43
''' );
45
44
46
45
for (var j = 0 ; j < modificationsPerRound; j++ ) {
47
- /// Using [runZoned] to hide `package:yaml` 's warnings.
48
- /// Test failures and errors will still be shown.
49
- runZoned (() {
50
- expect (
51
- () => generator.performNextModification (editor), returnsNormally);
52
- },
53
- zoneSpecification: ZoneSpecification (
54
- print: (Zone self, ZoneDelegate parent, Zone zone,
55
- String message) {}));
46
+ expect (
47
+ () => generator.performNextModification (editor),
48
+ returnsNormally,
49
+ );
56
50
}
57
51
});
58
52
}
You can’t perform that action at this time.
0 commit comments