leancodepl / patrol

Flutter-first UI testing framework. Ready for action!
https://patrol.leancode.co
Apache License 2.0
916 stars 142 forks source link

Compile error when using "main" as test file name #2222

Open rekire opened 5 months ago

rekire commented 5 months ago

Steps to reproduce

  1. Follow your tutorial including the sample test
  2. Rename the test file to main.dart
  3. Set in pubspec.yaml test_file_suffix to .dart
  4. Run patrol test -t integration_test/main.dart

Actual results

The test fails with the error:

• Building apk with entrypoint test_bundle.dart...
        integration_test/test_bundle.dart:12:23: Error: 'main' is already declared in this scope.
        import 'main.dart' as main;
                              ^^^^
        integration_test/test_bundle.dart:15:14: Context: Previous declaration of 'main'.
        Future<void> main() async {
                     ^^^^

It seems that the file name is used as some kind of namespace. I could guess some other file names like default.dart which will cause compile errors.

Logs

Logs ``` ```

Patrol version

patrol: ^3.7.3

Patrol Doctor output

Patrol Doctor output ``` Patrol CLI version: 2.7.0 Flutter command: flutter Flutter 3.22.1 • channel stable Android: • Program adb found in /censored/adb • Env var $ANDROID_HOME set to /censored/ iOS / macOS: • Program xcodebuild found in /usr/bin/xcodebuild • Program ideviceinstaller found in /opt/homebrew/bin/ideviceinstaller ```

Flutter Doctor output

Flutter Doctor output ``` ```
bartekpacia commented 5 months ago

In the generated test bundle file, there's already a function named main.

I could guess some other file names like default.dart which will cause compile errors.

Why would default.dart cause compile errors?

rekire commented 5 months ago

I think that all dart keywords would cause trouble, since I got the impression that the file name get used as prefix or namespace (I'm right now not sure how it is called in dart)

bartekpacia commented 5 months ago

ah yeah, this makes sense

jBorkowska commented 5 months ago

Hi @rekire , thank you for creating this issue. That is a bug, though we're leaving it for now as it has low priority