mockito icon indicating copy to clipboard operation
mockito copied to clipboard

Captialized import paths do not behave correctly

Open Pante opened this issue 2 years ago • 4 comments

Recently, when using Mockito, I accidentally capitalized the path of an imported type which was used to generate mocks.

import 'package:my_package:/UPPERCASE/foo.dart';

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

The actual path however, is not capitalized. package:my_package:/uppercase/foo.dart:

class Foo {}

This causes Mockito to fail with the following error:

Invalid @GenerateMocks annotation: The GenerateMocks "classes" argument is missing, includes an unknown type, or includes an extension
package:mockito/src/builder.dart 421:7   _MockTargetGatherer._mockTargetsFromGenerateMocks
package:mockito/src/builder.dart 407:23  new _MockTargetGatherer
package:mockito/src/builder.dart 67:9    MockBuilder.build

After some further digging, it seems like the same problem affects AutoRoute as well. It also seems like dart analyze and compilation have no problems with the mismatch between the actual location and the mistakenly capitalized path.

Pante avatar Apr 29 '22 10:04 Pante

I'm not sure correctly is the right word here. I think rejecting the misnamed import is the correct behavior, it's just I would expect it to happen earlier and with a more descriptive error message... So I'd say capitalized import paths don't behave consistently. Anyway, I don't think Mockito is the right place to solve this, we don't do anything with the import paths directly, just work with what the analyzer gives us.

BTW, are you running on Windows by any chance?

yanok avatar Jul 03 '23 08:07 yanok

I honestly can't remember exactly since I frequently switch between a Windows & MacOS machine but it should be Windows.

Pante avatar Jul 03 '23 10:07 Pante

Hm... that makes it harder for me to reproduce, but I'll see what I can do. BTW, could you please try to check if it still behaves the same for you? I'm totally sure we didn't do anything for it on Mockito side, but it could be fixed on the Analyzer side by now.

yanok avatar Jul 03 '23 11:07 yanok

I just tested it on Windows with Dart 3 & it still seems to be failing with the same error.

Pante avatar Jul 04 '23 13:07 Pante