Skip to content

Conversation

@jiahaog
Copy link
Member

@jiahaog jiahaog commented Jan 25, 2021

Fixes #20907. This makes Directory.current in tests always return the root of the flutter project, irregardless of whether the test command is flutter test (run all tests in $project/test), or flutter test test/foo_test.dart (run a specific test file).

Context: I was trying to initialize an application package as a follow up to #74236 (to run integration tests with flutter test). I got it to work for a single test, but running multiple tests did not work, because the FlutterProject.current() used in creating an application package works differently depending on the current working directory.

Not sure if this is alright though, it seems a bit breaking for users depending on the incorrect behavior. This is somewhat mitigated because users probably use flutter test to run all tests on CI, and the cases where I had to fix in this PR are probably less common (invoking flutter test in a subprocess from the test script). I also patched this and ran a global presubmit internally and there are no failures.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jan 25, 2021
@google-cla google-cla bot added the cla: yes label Jan 25, 2021
@jiahaog jiahaog force-pushed the test-flutter-project-cwd branch 2 times, most recently from 00deb12 to a161c02 Compare January 25, 2021 11:55
@flutter-dashboard flutter-dashboard bot added the c: contributor-productivity Team-specific productivity, code health, technical debt. label Jan 25, 2021
@jiahaog jiahaog force-pushed the test-flutter-project-cwd branch from a161c02 to 147b8ff Compare January 25, 2021 13:23
@jiahaog jiahaog changed the title [flutter_tools] Remove changing of CWD for flutter test [flutter_tools] Consistently set the working directory for Flutter Test Jan 25, 2021
@jiahaog jiahaog force-pushed the test-flutter-project-cwd branch from 147b8ff to 8a10bb1 Compare January 25, 2021 13:56
@jiahaog jiahaog force-pushed the test-flutter-project-cwd branch from 8a10bb1 to c9f5cf3 Compare January 25, 2021 14:51
@flutter-dashboard flutter-dashboard bot added a: internationalization Supporting other languages or locales. (aka i18n) f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. labels Jan 25, 2021
@jiahaog
Copy link
Member Author

jiahaog commented Jan 25, 2021

CI seems to have stalled, but the tool tests pass locally, so marking it as ready for review first.

@jiahaog jiahaog marked this pull request as ready for review January 25, 2021 15:58
@jiahaog jiahaog requested a review from jonahwilliams January 25, 2021 15:58
@jonahwilliams
Copy link
Contributor

I think IDEs may be already compensating for this in some way. I would double check with @devoncarew and @DanTup that this is safe to change

@jonahwilliams
Copy link
Contributor

(Otherwise I'm all for the idea)

@DanTup
Copy link
Contributor

DanTup commented Jan 25, 2021

Not doing anything to handle this in VS Code (the inconsistency occurs there unless there's a workaround in the user code), so fixing this here would be beneficial for VS Code users :-)

@devoncarew
Copy link
Contributor

For IntelliJ, when launching flutter test, we do set the cwd to the directory containing the pubspec file.

@devoncarew
Copy link
Contributor

It should be pretty easy to validate that flutter test still works in IntelliJ and VS Code though.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jonahwilliams
Copy link
Contributor

(but please verify in AS/Intellij too)

@jiahaog
Copy link
Member Author

jiahaog commented Jan 26, 2021

Yup, verified locally with the IntelliJ and VSCode plugins, we still can run individual tests via the UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: internationalization Supporting other languages or locales. (aka i18n) c: contributor-productivity Team-specific productivity, code health, technical debt. f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter test sets current directory differently depending on how test was executed

5 participants