Remove semantics_tester cross-imports from material tests#185736
Remove semantics_tester cross-imports from material tests#185736Sanaullah49 wants to merge 6 commits into
Conversation
Duplicates `packages/flutter/test/widgets/semantics_tester.dart` into `packages/flutter/test/material/` so that material tests no longer reach into the widgets test directory for shared utilities. This unblocks the planned move of Material to flutter/packages. The local copy is verbatim. Four importing tests are rewired to use it: card_test.dart, elevated_button_test.dart, material_button_test.dart, and data_table_test.dart. Part of flutter#182636.
There was a problem hiding this comment.
Code Review
This pull request moves semantics_tester.dart to the material test directory and updates corresponding imports. Feedback identifies several logic errors in the new file, including a tautology in the controlsNodes validation, flawed locale comparison logic, and a syntax error in an assertion within the _IncludesNodeWith constructor. Additionally, an error message for text selection mismatches was found to be inconsistent.
| if (textSelection?.baseOffset != nodeData.textSelection?.baseOffset || | ||
| textSelection?.extentOffset != nodeData.textSelection?.extentOffset) { | ||
| return fail( | ||
| 'expected node id $id to have textSelection [${textSelection?.baseOffset}, ${textSelection?.end}] but found: [${nodeData.textSelection?.baseOffset}, ${nodeData.textSelection?.extentOffset}].', |
There was a problem hiding this comment.
The error message is inconsistent. It uses textSelection?.end for the expected value but nodeData.textSelection?.extentOffset for the actual value. Since the comparison on lines 461-462 uses baseOffset and extentOffset, the error message should consistently use these properties to accurately reflect why the match failed.
| 'expected node id $id to have textSelection [${textSelection?.baseOffset}, ${textSelection?.end}] but found: [${nodeData.textSelection?.baseOffset}, ${nodeData.textSelection?.extentOffset}].', | |
| 'expected node id $id to have textSelection [${textSelection?.baseOffset}, ${textSelection?.extentOffset}] but found: [${nodeData.textSelection?.baseOffset}, ${nodeData.textSelection?.extentOffset}].', |
| ); | ||
| } | ||
|
|
||
| if (controlsNodes != controlsNodes && !setEquals(controlsNodes, node.controlsNodes)) { |
There was a problem hiding this comment.
The condition controlsNodes != controlsNodes is a tautology that always evaluates to false, which means the setEquals check and the subsequent failure message will never be reached. This effectively disables the validation for controlsNodes.
| if (controlsNodes != controlsNodes && !setEquals(controlsNodes, node.controlsNodes)) { | |
| if (controlsNodes != null && !setEquals(controlsNodes, node.controlsNodes)) { |
| (second[i] as LocaleStringAttribute).locale != | ||
| (second[i] as LocaleStringAttribute).locale)) { |
There was a problem hiding this comment.
The locale comparison logic is flawed as it compares second[i].locale to itself. It should compare the locale from first[i] with the locale from second[i].
| (second[i] as LocaleStringAttribute).locale != | |
| (second[i] as LocaleStringAttribute).locale)) { | |
| (first[i] as LocaleStringAttribute).locale != | |
| (second[i] as LocaleStringAttribute).locale)) { |
There was a problem hiding this comment.
Good bot, this looks like a bug indeed. Probably not something to fix in this PR though since it occurs in multiple places now. I've created an issue: #185900
| inputType != null, | ||
| minValue != null || maxValue != null, |
There was a problem hiding this comment.
The assert statement in the _IncludesNodeWith constructor incorrectly uses a comma after inputType != null, making the subsequent expression (minValue != null || maxValue != null) the second argument to assert (the error message) rather than part of the boolean condition. This causes the assertion to fail if only minValue or maxValue are provided.
inputType != null ||
minValue != null ||
maxValue != null,|
The Requesting the The four other PRs in this cluster — #184517, #184519, #184282, #184193 — were all merged before the freeze cutoff. The remaining cross-import work (this PR + #185250 and others) needs the override or it can't land before the migration window opens. cc @justinmc (umbrella issue owner) |
4a682d5 to
7a7c1a3
Compare
| (second[i] as LocaleStringAttribute).locale != | ||
| (second[i] as LocaleStringAttribute).locale)) { |
There was a problem hiding this comment.
Good bot, this looks like a bug indeed. Probably not something to fix in this PR though since it occurs in multiple places now. I've created an issue: #185900
| inputType != null, | ||
| minValue != null || maxValue != null, |
| ); | ||
| } | ||
|
|
||
| if (controlsNodes != controlsNodes && !setEquals(controlsNodes, node.controlsNodes)) { |
|
I agree about the code freeze override, added. Thanks again for your work on these! |
|
Hi @justinmc — CI is now all green after a rerun of the flaky |
|
autosubmit label was removed for flutter/flutter/185736, because - The status or check suite Linux analyze has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Hi @justinmc @victorsanni — CI is green again (Linux analyze passed on the latest run, |
Three bugs in TestSemantics that caused assertions/comparisons to never work correctly: 1. `controlsNodes != controlsNodes` always evaluates to false (self- comparison); fixed to `controlsNodes != null` so the setEquals check actually runs. 2. Locale comparison compared `second[i]` to itself instead of to `first[i]`, making the check a no-op. 3. A stray comma after `inputType != null` split the assert condition, making `minValue != null || maxValue != null` the error message instead of part of the condition. All three bugs existed identically in both test/widgets/semantics_tester.dart and test/material/semantics_tester.dart (the latter is a copy introduced in flutter#185736). Fixes flutter#185900
|
Linux analyzer_benchmark failed before the benchmark ran: |
victorsanni
left a comment
There was a problem hiding this comment.
I did a grep of import '../widgets/semantics_tester.dart'; and found many more instances, why are there only 2 in this PR?
|
This PR is ready to be ported over to flutter/packages in the new cupertino_ui package! This PR is also necessary for pre-release of the cupertino_ui package. If you are unable to work on this right now, no worries! We’ll go ahead and port it over to get it landed. Your contribution is greatly appreciated. 💙 |
Remove cross-directory test imports of
semantics_tester.dartfrom material tests.Duplicates
packages/flutter/test/widgets/semantics_tester.dartverbatim intopackages/flutter/test/material/, and rewires the four importing tests (card_test.dart,elevated_button_test.dart,material_button_test.dart,data_table_test.dart) to use the local copy.This follows the duplication pattern used in the merged #184517 (live_text_utils), #184519 (editable_text_utils), and #184282 (navigator_utils).
Part of #182636.
Pre-launch Checklist
///).