New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
properly pass on gradle exit code (#71484) #71582
properly pass on gradle exit code (#71484) #71582
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
I believe there is a similar bug at
should I include a fix as well in the PR or create a separate issue/PR ? |
oh, awesome find! Thanks for your PR. For tests, generally look for usages of the public method or of the top level command being used in existing tests are use them as inspiration :) For instance, you can add one test method in https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/general.shard/android/gradle_test.dart#L1635. Assemble together a skeleton project and make the dart file bogus, assert that the status code is sad. Then in https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/commands.shard/permeable/build_aar_test.dart (which tests at a higher level), use the same helpers to create a project, break the dart file, then invoke the build like the other tests and assert the throw or exit code. |
good catch. For the test, you could look at this line
|
thanks for the tips! i will have a look next week |
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
@mx1up are you still interested in working on this? If so, you'll need to pull in the latest master to get the tests working again |
@jonahwilliams yes, I will have a look at it next week. I have just returned from a month long holiday, that explains the lack of follow-up. |
aeaca8d
to
bcd94b9
Compare
I had a look at the code, but have a few questions.
did you reference a random line in that file, or do you really mean I should add an override there (for my new test then). or do you simply mean, add a test next to (at the same level as) Also, is my test atypical in the sense that it really needs to build and not mock everything out? I did not find any similar test in that file? Is that correct? If so, it makes it really hard to get started..
here I did find tests that create a sample project like this: I did try adapting a test here like this (obviously it is only a minor change to try out, just overwriting the main.dart file):
but it failed in another way:
I'm afraid I'm kinda stuck, any extra info/explanation much appreciated |
This PR will also fix #74479. Can anyone also metion it in OP so that it will be fixed once this is merged? |
Any update on this? |
@mx1up Copy and paste the test that @blasten referenced. The one starting here:
Change the second parameter to Change the test to expect a tool exit from the call to |
Hello @mx1up testUsingContext("doesn't indicate how to consume an AAR when flutter build failure", () async {
final File manifestFile = fileSystem.file('pubspec.yaml');
manifestFile.createSync(recursive: true);
manifestFile.writeAsStringSync('''
flutter:
module:
androidPackage: com.example.test
'''
);
fileSystem.file('.android/gradlew').createSync(recursive: true);
fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant');
fileSystem.file('.android/build.gradle')
.createSync(recursive: true);
// Let any process start. Assert after.
when(mockProcessManager.run(
any,
environment: anyNamed('environment'),
workingDirectory: anyNamed('workingDirectory'),
)).thenAnswer((_) async => ProcessResult(1, 1, '', ''));
fileSystem.directory('build/outputs/repo').createSync(recursive: true);
await expectLater(() async {
await buildGradleAar(
androidBuildInfo: const AndroidBuildInfo(BuildInfo(BuildMode.release, null, treeShakeIcons: false)),
project: FlutterProject.current(),
outputDirectory: fileSystem.directory('build/'),
target: '',
buildNumber: '1.0',
);
},
throwsToolExit(
exitCode: 1,
message: 'Gradle task assembleAarRelease failed with exit code 1.'),
);
expect(
testLogger.statusText.contains('Consuming the Module'),
isFalse,
);
}, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio,
Cache: () => cache,
Platform: () => android,
FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager,
}); Can you please try to copy the test case, and see the CI passed or not? Hope this PR can be merged ASAP. |
the gradle process's exit code variable was not properly referenced
8530743
to
22ad861
Compare
@zanderso thank you very much for the pointers. I think I managed to do it and afterwards I could compare my results with @littleGnAl (also thanks :) ). The only thing I was not sure about in @littleGnAl 's solution, if it is really necessary to include the "consuming the module" test? If the expection is thrown, the test succeeds, is that not sufficient? I included it anyway because i assume @littleGnAl has more experience than me ;) @xster mentioned another test to be added in build_aar_test.dart . I'll have another look if I can produce a test there. I am currently looking to adapt this test: flutter/packages/flutter_tools/test/commands.shard/permeable/build_aar_test.dart Line 259 in 021311e
Would that be a good starting point? I will continue tomorrow. |
packages/flutter_tools/test/general.shard/android/gradle_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/android/gradle_test.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM + nit suggestion
Co-authored-by: Emmanuel Garcia <egarciad@google.com>
fddb812
to
c7cb43c
Compare
if another more high level test is needed, I gave it a try in another branch in order not to unnecessarily pollute this PR: In another attempt (not committed), I tried failing the build doing a real build and damaging the main.dart like @xster suggested but then I got an error message like this:
the code looked something like this:
|
thanks for merging. btw, i believe passing the exitcode (with same bug, should be result.exitCode) on this line is useless:
as the exitCode at that point will always be 0. However, that means the build command should have succeeded and the directory should exist.. |
Description
the gradle process's exit code variable was not properly referenced. That way, when the flutter build failed, it did not fail the gradle task. see #71484 for more info
Related Issues
fix #71484
fix #74479
Tests
I added the following tests:
I have not written any test yet as I don't have any clue where to start. Please provide some pointer/example?
Checklist
Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.
I ran all tests using dev channel and master channel flutter, but a lot of tests failed. The errors don't seem related to my change though. How to properly run the tests?
flutter analyze --flutter-repo also reports lots of errors like this: