Add expectations for emitted warnings#2366
Conversation
Pulled from #2362 and refactored to test for exactly 1 warning. Add a test utility to check for warnings emitted while parsing and use it in two test cases that emit warnings.
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
PR HealthChangelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with Coverage ✔️
This check for test coverage is informational (issues shown here will not fail the PR). This check can be disabled by tagging the PR with Unused Dependencies ✔️
For details on how to fix these, see dependency_validator. This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with
API leaks
|
| Package | Leaked API symbol | Leaking sources |
|---|---|---|
| yaml | ErrorListener | yaml/yaml.dart::loadYaml::errorListener yaml/yaml.dart::loadYamlNode::errorListener yaml/yaml.dart::loadYamlDocument::errorListener |
| yaml | ScalarEvent | yaml_node.dart::YamlScalar::internal::scalar |
| yaml | EventType | event.dart::Event::type event.dart::EventType::streamStart event.dart::EventType::streamEnd event.dart::EventType::documentStart event.dart::EventType::documentEnd event.dart::EventType::alias event.dart::EventType::scalar event.dart::EventType::sequenceStart event.dart::EventType::sequenceEnd event.dart::EventType::mappingStart event.dart::EventType::mappingEnd event.dart::EventType::values event.dart::Event::new::type event.dart::ScalarEvent::type |
This check can be disabled by tagging the PR with skip-leaking-check.
License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
| Files |
|---|
| no missing headers |
All source files should start with a license header.
Unrelated files missing license headers
| Files |
|---|
| pkgs/bazel_worker/benchmark/benchmark.dart |
| pkgs/coverage/lib/src/coverage_options.dart |
| pkgs/html/example/main.dart |
| pkgs/html/lib/dom.dart |
| pkgs/html/lib/dom_parsing.dart |
| pkgs/html/lib/html_escape.dart |
| pkgs/html/lib/parser.dart |
| pkgs/html/lib/src/constants.dart |
| pkgs/html/lib/src/encoding_parser.dart |
| pkgs/html/lib/src/html_input_stream.dart |
| pkgs/html/lib/src/list_proxy.dart |
| pkgs/html/lib/src/query_selector.dart |
| pkgs/html/lib/src/token.dart |
| pkgs/html/lib/src/tokenizer.dart |
| pkgs/html/lib/src/treebuilder.dart |
| pkgs/html/lib/src/utils.dart |
| pkgs/html/test/dom_test.dart |
| pkgs/html/test/parser_feature_test.dart |
| pkgs/html/test/parser_test.dart |
| pkgs/html/test/query_selector_test.dart |
| pkgs/html/test/selectors/level1_baseline_test.dart |
| pkgs/html/test/selectors/level1_lib.dart |
| pkgs/html/test/selectors/selectors.dart |
| pkgs/html/test/support.dart |
| pkgs/html/test/tokenizer_test.dart |
| pkgs/html/test/trie_test.dart |
| pkgs/html/tool/generate_trie.dart |
| pkgs/pubspec_parse/test/git_uri_test.dart |
| pkgs/watcher/test/custom_watcher_factory_test.dart |
This check can be disabled by tagging the PR with skip-license-check.
There was a problem hiding this comment.
Code Review
This pull request replaces TODO comments in the YAML directive tests with functional verification of emitted warnings. It introduces a helper function, expectYamlLoadsWithWarning, to capture and assert on warnings during YAML loading. Feedback suggests moving this helper function to a higher scope or a utility file to enhance reusability across other test groups.
| void expectYamlLoadsWithWarning( | ||
| Object? expected, String source, String expectedWarning) { | ||
| final warnings = <String>[]; | ||
| final oldCallback = yamlWarningCallback; | ||
| yamlWarningCallback = (message, [_]) { | ||
| warnings.add(message); | ||
| }; | ||
| try { | ||
| expectYamlLoads(expected, source); | ||
| expect(warnings, ['Warning: $expectedWarning']); | ||
| } finally { | ||
| yamlWarningCallback = oldCallback; | ||
| } | ||
| } |
There was a problem hiding this comment.
The helper function expectYamlLoadsWithWarning is currently defined inside the '6.8: Directives' group. Since verifying emitted warnings is a general utility that could be useful for other test groups (or even other test files), consider moving this function to the top level of the file or to test/utils.dart to improve reusability and maintainability.
It's only used in these 2 tests, but it matches the other shared utilities.
Pulled from #2362 and refactored to test for exactly 1 warning.
Add a test utility to check for warnings emitted while parsing and use
it in two test cases that emit warnings.