-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
8198317: Enhance JavacTool.getTask for flexibility #1896
Conversation
👋 Welcome back lgxbslgx! A progress list of the required criteria for merging this PR into |
Webrevs
|
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.
As a general rule, all changes should have an accompanying regression test, unless there is a good reason why not. The set of good reasons has a corresponding list of JBS labels, shown here: http://openjdk.java.net/guide/#noreg
The closest match here would be noreg-trivial
but I don't think it is close enough to claim that. In other words, I think this change needs a corresponding new test. It is also not uncommon for small changes like this to more effort to write the test than fixing the underlying issue.
--
- Unit test: insurance against having to writing a regression test later on
- Regression test: the penalty for not writing a unit test in the first place
I submit a test case. But I don't satisfy with it, because it can't meet all the situations.
The error information is shown below.
A better test case would be appreciated. |
While it is acceptable practice for file manager tests to access the file manager internals, and more generally for javac tests to access the javac internals, it is less good to access the internals of other parts of the system (like PrintWriter in java.base), since future changes to those components could break this test as an unwelcome side effect. How easy would it be to observe/verify the desired behavior by monitoring the output to the resulting PrintWriter object, e.g. by triggering some known diagnostic? |
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.
Any time that tests split a string into lines it is really important to ensure that it works on Windows as well as Linux/Mac platforms, because of the different line endings.
The code looks OK. Alternatively, if you are not concerned to check for the exact line ending sequence, you can use split("\\R")
to split on any line ending sequence. Either way, it's worth checking the test runs on platforms with both kinds of typical line ending.
ToolProvider.getSystemJavaCompiler() | ||
.getTask(null, null, null, Arrays.asList("-XDrawDiagnostics", "-Xlint:serial"), null, files) | ||
.call(); | ||
tb.checkEqual(expected, Arrays.asList(bais.toString().split(lineSeparator))); | ||
System.setErr(prev); |
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.
Although not strictly necessary in this case, it is good practice to use try ... finally
to reset values back to some previous value. In other words, the System.setErr(prev);
should be in the finally
clause.
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.
Fixed.
List<? extends JavaFileObject> files = Arrays.asList(new MemFile("Test.java", code)); | ||
|
||
// Situation: out is null and the value is not set in the context. | ||
ByteArrayOutputStream bais = new ByteArrayOutputStream(); |
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.
The variable name bais
is "surprising". Is it a cut-n-paste from elsewhere? I was expecting to see baos
as an acronym for "byte array output stream", bais
suggests "byte array input stream".
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.
Fixed. I used ByteArrayInputStream bais = new ByteArrayInputStream();
at the beginning. Then I identified the ByteArrayInputStream
is not right and changed to use ByteArrayOutputStream
. But I forgot to revise the variable name bais
. Sorry for wasting the time at this careless detail.
Given that the |
@jonathan-gibbons I updated the code according to your comments. Thank you for taking the time to review. |
@lgxbslgx This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@lgxbslgx This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! |
@lgxbslgx, could you please re-open this PR? Thanks! |
@lahodaj sorry for the delay. I will assist you to completing the new PR. |
Hi all,
This little patch enhances the setting of
Log
inJavacTool.getTask
.Thank you for taking the time to review.
Best Regards.
Progress
Issue
Download
$ git fetch https://git.openjdk.java.net/jdk pull/1896/head:pull/1896
$ git checkout pull/1896