• Michael Goderbauer's avatar
    Fail tests on exceptions raised after test completed (#144706) · 91cccc8e
    Michael Goderbauer authored
    A test was failing silently because of this (see
    https://github.com/flutter/flutter/issues/144353 and fixed in
    https://github.com/flutter/flutter/pull/144709). The failure went
    undetected for months. Ideally, this should have been a regular
    non-silent failure. This change makes that so. `package:test` can
    properly handle reported exceptions outside of test cases. With this
    change, the test fails as follows:
    
    ```
    00:03 +82: Smoke test material/color_scheme/dynamic_content_color.0.dart
    ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
    The following assertion was thrown running a test (but after the test had completed):
    setState() called after dispose(): _DynamicColorExampleState#1cd37(lifecycle state: defunct, not
    mounted)
    This error happens if you call setState() on a State object for a widget that no longer appears in
    the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error
    can occur when code calls setState() from a timer or an animation callback.
    The preferred solution is to cancel the timer or stop listening to the animation in the dispose()
    callback. Another solution is to check the "mounted" property of this object before calling
    setState() to ensure the object is still in the tree.
    This error might indicate a memory leak if setState() is being called because another object is
    retaining a reference to this State object after it has been removed from the tree. To avoid memory
    leaks, consider breaking the reference to this object during dispose().
    
    When the exception was thrown, this was the stack:
    #0      State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1167:9)
    #1      State.setState (package:flutter/src/widgets/framework.dart:1202:6)
    #2      _DynamicColorExampleState._updateImage (package:flutter_api_samples/material/color_scheme/dynamic_content_color.0.dart:191:5)
    <asynchronous suspension>
    ════════════════════════════════════════════════════════════════════════════════════════════════════
    00:03 +81 -1: Smoke test material/context_menu/context_menu_controller.0.dart
    00:03 +81 -1: Smoke test material/color_scheme/dynamic_content_color.0.dart [E]
      Test failed. See exception logs above.
      The test description was: Smoke test material/color_scheme/dynamic_content_color.0.dart
      
      This test failed after it had already completed.
      Make sure to use a matching library which informs the test runner
      of pending async work.
    ```
    91cccc8e
Name
Last commit
Last update
.github Loading commit data...
.vscode Loading commit data...
bin Loading commit data...
dev Loading commit data...
examples Loading commit data...
packages Loading commit data...
.ci.yaml Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CODEOWNERS Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
CONTRIBUTING.md Loading commit data...
LICENSE Loading commit data...
PATENT_GRANT Loading commit data...
README.md Loading commit data...
TESTOWNERS Loading commit data...
analysis_options.yaml Loading commit data...
dartdoc_options.yaml Loading commit data...
flutter_console.bat Loading commit data...