Thanks to visit codestin.com
Credit goes to github.com

Skip to content

expect() in semantic test producing unhelpful output #110598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pdblasi-google opened this issue Aug 30, 2022 · 2 comments · Fixed by #110613
Closed

expect() in semantic test producing unhelpful output #110598

pdblasi-google opened this issue Aug 30, 2022 · 2 comments · Fixed by #110613
Assignees
Labels
a: tests "flutter test", flutter_test, or one of our tests customer: google Various Google teams

Comments

@pdblasi-google
Copy link
Contributor

pdblasi-google commented Aug 30, 2022

Originally reported @ b/243693776

When writing a semantic test (that is expected to fail), I see an unhelpful error. Previously, the error showed the diff of the expected properties and the actual ones, but I believe an exception is being thrown while calculating this diff.

Steps to Reproduce

  1. Create a test using matchesSemantics or containsSemantics that is expected to fail
  2. Run the test

Expected results: Test fails with error messaging that compares expected and actual output with no errors

Actual results: Test fails with error messaging containing errors

Code sample
      expect(
        tester.getSemantics(find.bySemanticsLabel('title')),
        matchesSemantics(
          hasTapAction: true,
          hasEnabledState: true,
          isEnabled: true,
          hasToggledState: true,
          isToggled: true,
          isFocusable: true,
          isSelected: true,
        ),
      );
Logs
The following TestFailure was thrown running a test:
Expected: has semantics with actions:
[SemanticsAction:SemanticsAction.tap] without actions: [
            SemanticsAction:SemanticsAction.longPress,
            SemanticsAction:SemanticsAction.scrollLeft,
            SemanticsAction:SemanticsAction.scrollRight,
            SemanticsAction:SemanticsAction.scrollUp,
            SemanticsAction:SemanticsAction.scrollDown,
            SemanticsAction:SemanticsAction.increase,
            SemanticsAction:SemanticsAction.decrease,
            SemanticsAction:SemanticsAction.showOnScreen,
            SemanticsAction:SemanticsAction.moveCursorForwardByCharacter,
            SemanticsAction:SemanticsAction.moveCursorBackwardByCharacter,
            SemanticsAction:SemanticsAction.setSelection,
            SemanticsAction:SemanticsAction.copy,
            SemanticsAction:SemanticsAction.cut,
            SemanticsAction:SemanticsAction.paste,
            SemanticsAction:SemanticsAction.didGainAccessibilityFocus,
            SemanticsAction:SemanticsAction.didLoseAccessibilityFocus,
            SemanticsAction:SemanticsAction.dismiss,
            SemanticsAction:SemanticsAction.moveCursorForwardByWord,
            SemanticsAction:SemanticsAction.moveCursorBackwardByWord,
            SemanticsAction:SemanticsAction.setText
          ] with flags: [
            SemanticsFlag:SemanticsFlag.isButton,
            SemanticsFlag:SemanticsFlag.isFocusable,
            SemanticsFlag:SemanticsFlag.hasEnabledState,
            SemanticsFlag:SemanticsFlag.isEnabled,
            SemanticsFlag:SemanticsFlag.isInMutuallyExclusiveGroup
          ] without flags: [
            SemanticsFlag:SemanticsFlag.hasCheckedState,
            SemanticsFlag:SemanticsFlag.isChecked,
            SemanticsFlag:SemanticsFlag.isSelected,
            SemanticsFlag:SemanticsFlag.isSlider,
            SemanticsFlag:SemanticsFlag.isKeyboardKey,
            SemanticsFlag:SemanticsFlag.isLink,
            SemanticsFlag:SemanticsFlag.isTextField,
            SemanticsFlag:SemanticsFlag.isReadOnly,
            SemanticsFlag:SemanticsFlag.isFocused,
            SemanticsFlag:SemanticsFlag.isHeader,
            SemanticsFlag:SemanticsFlag.isObscured,
            SemanticsFlag:SemanticsFlag.isMultiline,
            SemanticsFlag:SemanticsFlag.namesRoute,
            SemanticsFlag:SemanticsFlag.scopesRoute,
            SemanticsFlag:SemanticsFlag.isHidden,
            SemanticsFlag:SemanticsFlag.isImage,
            SemanticsFlag:SemanticsFlag.isLiveRegion,
            SemanticsFlag:SemanticsFlag.hasToggledState,
            SemanticsFlag:SemanticsFlag.isToggled,
            SemanticsFlag:SemanticsFlag.hasImplicitScrolling
          ]
  Actual: SemanticsNode:<SemanticsNode#10(Rect.fromLTRB(0.0, 0.0,
103.0, 64.0), actions: [tap], flags: [isButton, hasEnabledState,
isEnabled, isFocusable], label: "title", textDirection:
ltr)>
   Which: null
'package:flutter/src/foundation/diagnostics.dart': Failed
assertion: line 3057 pos 5: 'indexOfDot != -1 && indexOfDot <
description.length - 1': The provided object "8" is not an enum.
at #0      _AssertionError._doThrowNew
(dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew
(dart:core-patch/errors_patch.dart:40:5)
#2      describeEnum
(package:flutter/src/foundation/diagnostics.dart:3057:5)
#3      _MatchesSemanticsData.matches
(package:flutter_test/src/matchers.dart:2483:45)
#4      _expect (package:test_api/src/expect/expect.dart:123:30)
#5      expect (package:test_api/src/expect/expect.dart:46:3)
#6      expect
(package:flutter_test/src/widget_tester.dart:460:16)
#7      main.<anonymous closure>.<anonymous closure>
...
@pdblasi-google pdblasi-google added a: tests "flutter test", flutter_test, or one of our tests customer: google Various Google teams labels Aug 30, 2022
@pdblasi-google pdblasi-google self-assigned this Aug 30, 2022
@pdblasi-google
Copy link
Contributor Author

It looks like this issue was caused by changing the input to describeEnum in the matchers matches function from the SemanticAction to that SemanticAction's index as part of this PR.

It slipped through compile/analysis checks since the describeEnum method takes an Object, not something more specific. It looks like that non-specificity was needed to support flag (power of 2) enums, so not something we can make compile time safe at the moment.

I'll try to add in a test or two to prevent possible regressions while I'm in there fixing things.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: tests "flutter test", flutter_test, or one of our tests customer: google Various Google teams
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant