Skip to content

@GenerateMocks fails with NavigatorState #438

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
Pante opened this issue Jun 26, 2021 · 1 comment
Closed

@GenerateMocks fails with NavigatorState #438

Pante opened this issue Jun 26, 2021 · 1 comment
Assignees
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@Pante
Copy link
Contributor

Pante commented Jun 26, 2021

An error is thrown when generating a mock for Flutter's NavigatorState.

import 'package:flutter/widgets.dart';

@GenerateMocks([NavigatorState])
void main() {}

Running flutter pub build_runner build -v with the above code snippet leads to the following error:

[  +66 ms] executing: [C:\Users\Matthias\Documents\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +408 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +1 ms] d79295af24c3ed621c33713ecda14ad196fd9c31
[   +1 ms] executing: [C:\Users\Matthias\Documents\flutter/] git tag --points-at d79295af24c3ed621c33713ecda14ad196fd9c31
[  +52 ms] Exit code 0 from: git tag --points-at d79295af24c3ed621c33713ecda14ad196fd9c31
[        ] 2.2.2
[   +5 ms] executing: [C:\Users\Matthias\Documents\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +48 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [C:\Users\Matthias\Documents\flutter/] git ls-remote --get-url origin
[  +44 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[ +119 ms] executing: [C:\Users\Matthias\Documents\flutter/] git rev-parse --abbrev-ref HEAD
[  +52 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[  +72 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +50 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +26 ms] Using C:\Users\Matthias\Documents\flutter\.pub-cache for the pub cache.
[        ] executing: C:\Users\Matthias\Documents\flutter\bin\cache\dart-sdk\bin\pub run build_runner build -v
[INFO] Entrypoint:Generating build script...
[INFO] Entrypoint:Generating build script completed, took 456ms

[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Reading cached asset graph...
[INFO] BuildDefinition:Reading cached asset graph completed, took 53ms

[INFO] BuildDefinition:Checking for updates since last build...
[INFO] BuildDefinition:Checking for updates since last build completed, took 598ms

[INFO] Build:Running build...
[INFO] Build:Running build completed, took 10ms

[INFO] Build:Caching finalized dependency graph...
[INFO] Build:Caching finalized dependency graph completed, took 37ms

[SEVERE] mockito:mockBuilder on test/keyed_test.dart (cached):

Null check operator used on a null value
package:mockito/src/builder.dart 1464:30                     _MockLibraryInfo._typeImport
package:mockito/src/builder.dart 1403:19                     _MockLibraryInfo._typeReference.<fn>
package:code_builder/src/specs/type_reference.g.dart 160:33  _$TypeReferenceBuilder.update
package:code_builder/src/specs/type_reference.g.dart 22:36   new _$TypeReference
package:mockito/src/builder.dart 1399:14                     _MockLibraryInfo._typeReference
package:mockito/src/builder.dart 1214:18                     _MockLibraryInfo._matchingParameter.<fn>
package:code_builder/src/specs/method.g.dart 641:33          _$ParameterBuilder.update
package:code_builder/src/specs/method.g.dart 403:32          new _$Parameter
package:mockito/src/builder.dart 1211:12                     _MockLibraryInfo._matchingParameter
package:mockito/src/builder.dart 967:18                      _MockLibraryInfo._buildOverridingMethod
package:mockito/src/builder.dart 1190:27                     _MockLibraryInfo._addFakeClass.<fn>.<fn>
package:code_builder/src/specs/method.g.dart 332:33          _$MethodBuilder.update
package:code_builder/src/specs/method.g.dart 38:29           new _$Method
package:mockito/src/builder.dart 1189:30                     _MockLibraryInfo._addFakeClass.<fn>
package:code_builder/src/specs/class.g.dart 292:33           _$ClassBuilder.update
package:code_builder/src/specs/class.g.dart 34:28            new _$Class
package:mockito/src/builder.dart 1163:21                     _MockLibraryInfo._addFakeClass
package:mockito/src/builder.dart 1150:9                      _MockLibraryInfo._dummyValueImplementing
package:mockito/src/builder.dart 1097:12                     _MockLibraryInfo._dummyValue
package:mockito/src/builder.dart 1000:24                     _MockLibraryInfo._buildOverridingMethod
package:mockito/src/builder.dart 887:36                      _MockLibraryInfo.methodOverrides.<fn>
package:code_builder/src/specs/method.g.dart 332:33          _$MethodBuilder.update
package:code_builder/src/specs/method.g.dart 38:29           new _$Method
package:mockito/src/builder.dart 887:15                      _MockLibraryInfo.methodOverrides
dart:core                                                    List.addAll
package:built_collection/src/list/list_builder.dart 98:14    ListBuilder.addAll
package:mockito/src/builder.dart 807:24                      _MockLibraryInfo._buildMockClass.<fn>
package:code_builder/src/specs/class.g.dart 292:33           _$ClassBuilder.update
package:code_builder/src/specs/class.g.dart 34:28            new _$Class
package:mockito/src/builder.dart 753:12                      _MockLibraryInfo._buildMockClass
package:mockito/src/builder.dart 743:23                      new _MockLibraryInfo
package:mockito/src/builder.dart 65:29                       MockBuilder.build

[SEVERE] Build:
Failed after 85ms
[+2861 ms] "flutter run" took 2,964ms.
[   +8 ms] pub finished with exit code 1
[   +3 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      _DefaultPub.interactively (package:flutter_tools/src/dart/pub.dart:368:7)
           <asynchronous suspension>
           #2      PackagesForwardCommand.runCommand (package:flutter_tools/src/commands/packages.dart:241:5)
           <asynchronous suspension>
           #3      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1043:27)
           <asynchronous suspension>
           #4      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #5      CommandRunner.runCommand (package:args/command_runner.dart:196:13)
           <asynchronous suspension>
           #6      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:284:9)
           <asynchronous suspension>
           #7      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #8      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:232:5)
           <asynchronous suspension>
           #9      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #11     main (package:flutter_tools/executable.dart:91:3)
           <asynchronous suspension>
           
           
[  +69 ms] ensureAnalyticsSent: 65ms
[   +2 ms] Running shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 1
@srawlins srawlins added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jun 29, 2021
@srawlins
Copy link
Member

Thanks for the report! I've figured out that this is because:

  • NavigatorState implements State
  • State has toDiagnosticsNode which returns a non-nullable DiagnosticsNode, so we need to make a _FakeDiagnosticsNode,
  • DiagnosticsNode overrides toString with an optional named parameter with type TextTreeConfiguration, so we need to refer to that class, but miss it.

@srawlins srawlins self-assigned this Jul 20, 2021
srawlins added a commit that referenced this issue Jul 20, 2021
* Properly reference types in overridden `toString` implementations.
  Fixes #438
* Override `toString` in a Fake implementation when the class-to-be-faked has
  a superclass which overrides `toString` with additional parameters.
  Fixes #371

PiperOrigin-RevId: 385852381
mosuem pushed a commit to dart-lang/test that referenced this issue Oct 17, 2024
* Properly reference types in overridden `toString` implementations.
  Fixes dart-lang/mockito#438
* Override `toString` in a Fake implementation when the class-to-be-faked has
  a superclass which overrides `toString` with additional parameters.
  Fixes dart-lang/mockito#371

PiperOrigin-RevId: 385852381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants