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 {
574574 _yaml);
575575 }
576576
577- final actualTree = loadYamlNode (_yaml);
577+ final actualTree = withYamlWarningCallback (() => loadYamlNode (_yaml) );
578578 if (! deepEquals (actualTree, expectedTree)) {
579579 throw createAssertionError (
580580 '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';
88import 'editor.dart' ;
99import 'wrap.dart' ;
1010
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+
1130/// Determines if [string] is dangerous by checking if parsing the plain string
1231/// can return a result different from [string] .
1332///
1433/// This function is also capable of detecting if non-printable characters are
1534/// in [string] .
1635bool isDangerousString (String string) {
1736 try {
18- if (loadYamlNode (string).value != string) {
37+ final node = withYamlWarningCallback (() => loadYamlNode (string));
38+ if (node.value != string) {
1939 return true ;
2040 }
2141
Original file line number Diff line number Diff line change 22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- import 'dart:async' ;
6- import 'dart:math' ;
5+ import 'dart:math' show Random;
76
87import 'package:test/test.dart' ;
98import 'package:yaml/yaml.dart' ;
@@ -44,15 +43,10 @@ dev_dependencies:
4443''' );
4544
4645 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+ );
5650 }
5751 });
5852 }
You can’t perform that action at this time.
0 commit comments