flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.21k stars 26.64k forks source link

Prevent test folder deletion on running `flutter create --empty` on an existing app project #147160

Open victoreronmosele opened 3 weeks ago

victoreronmosele commented 3 weeks ago

This PR modifies the flutter create --empty command to not delete the test/ folder when run on an existing app project.

Before:

flutter create my_app --empty
mkdir my_app/test
if test -d my_app/test; then echo "test exists"; else echo "test does not exist"; fi # test exists
flutter create my_app --empty  
if test -d my_app/test; then echo "test exists"; else echo "test does not exist"; fi # test does not exist

After:

flutter create my_app --empty
mkdir my_app/test
if test -d my_app/test; then echo "test exists"; else echo "test does not exist"; fi # test exists
flutter create my_app --empty  
if test -d my_app/test; then echo "test exists"; else echo "test does not exist"; fi # test exists

Fixes https://github.com/flutter/flutter/issues/134928

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

gspencergoog commented 1 week ago

When not creating a new project, won't this recreate test/widget_test.dart if it doesn't exist?

Ideally, this should probably just never write a file to test at all, and skip the delete step.

andrewkolos commented 3 days ago

When not creating a new project, won't this recreate test/widget_test.dart if it doesn't exist?

Indeed, this seems to be the case.

Ideally, this should probably just never write a file to test at all, and skip the delete step.

Agreed.