dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.11k stars 1.57k forks source link

[analyzer] `Bad state: Unable to find sdk/pkg/` when running some SDK tests with IntelliJ on Windows #48780

Open asashour opened 2 years ago

asashour commented 2 years ago

Most of analysis_server tests for example are runnable/debuggable, but once the test references package import, there is an error.

The test successfully runs from the command line dart run ......\remove_annotation_test.dart (without test after run), or from Visual Studio Code.

So, I am not sure if this is an IntelliJ issue, a configuration issue to use dart run file.dart somehow from the IDE, or something else.

/// IntelliJ Logs
C:\use\dart-sdk\sdk\out\ReleaseX64\dart-sdk\bin\dart.exe run test -r json C:/use/dart-sdk/sdk/pkg/analysis_server/test/src/services/correction/fix/remove_annotation_test.dart
Testing started at 1:55 PM ...
package:analyzer_utilities/package_root.dart 28:3                  packageRoot
test\src\utilities\mock_packages.dart 13:56                        _cacheFiles
test\src\utilities\mock_packages.dart 87:5                         new MockPackages._
test\src\utilities\mock_packages.dart 81:53                        MockPackages.instance
test\src\utilities\mock_packages.dart                              MockPackages.instance
test\abstract_context.dart 241:36                                  AbstractContextTest.writeTestPackageConfig
test\src\services\correction\fix\remove_annotation_test.dart 25:5  RemoveAnnotationTest.setUp
dart:mirrors                                                       _ClosureMirror.apply
package:test_reflective_loader/test_reflective_loader.dart 239:32  _invokeSymbolIfExists
package:test_reflective_loader/test_reflective_loader.dart 276:10  _runTest
package:test_reflective_loader/test_reflective_loader.dart 131:20  defineReflectiveTests.<fn>.<fn>

Bad state: Unable to find sdk/pkg/ in C:\Users\AHMED_~1\AppData\Local\Temp\dart_test.8d6e25ed\test.dart_1.dill

Example test:

https://github.com/dart-lang/sdk/blob/3d27f5cb79245720363d1b1c44d467b99e8f1d49/pkg/analysis_server/test/src/services/correction/fix/remove_annotation_test.dart#L28-L31

I think I followed the instructions of how to build, and am able to build the SDK.

IntelliJ IDEA 2021.3.3 (Community Edition) with updated dependencies, and with Dart SDK edge.

asashour commented 2 years ago

https://dart-review.googlesource.com/c/sdk/+/241002

The reason is because the difference in Platform.script.

IntelliJ executes dart run test test\a.dart, which would build package executable, in which Platform.script points to something like:

file:///C:/Users/<username>/AppData/Local/Temp/dart_test.b2af0f8/test.dart_1.dill

But Visual Source Code executes dart run test\a.dart, in which Platform.script would be the path in SDK checkout sources.

The mentioned CL fixes the issue.

bwilkerson commented 2 years ago

I'm not sure how you're running the tests from IntelliJ, but when I run them IntelliJ runs

<pathToSdk>/bin/dart --enable-asserts <pathToSdkCheckout>/pkg/analysis_server/test/src/services/correction/fix/remove_annotation_test.dart

I use the Run command on either the editor tab or the Project view's context menu. I never use the test runner.

asashour commented 2 years ago

Interesting.

Using root folder as pkg/analysis_server or (sdk with enabled Dart).

I run it without special configuration from image

or from the menu

image

It seems it is detected as tests

bwilkerson commented 2 years ago

I might have had to create a run configuration manually, or it might not have been detected as tests at the time. It's been years, so I don't remember exactly how I got into the current state.

asashour commented 2 years ago

I guess someone else can also verify the behavior.

For me, the current way is to use the proposed https://dart-review.googlesource.com/c/sdk/+/241002