-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Reenable more tests #2371
Reenable more tests #2371
Conversation
@lenhard You can probably comment a little bit on the test that were previously inside the parser. |
I tend to either fix the ignored tests or remove them. For some of them I don't even know what they should do... |
1ab9cbb
to
bd80523
Compare
@JabRef/developers I need help from all of you that have expertise in at least one of these topics! |
The tests for the file field are a bit strange. I'm not sure why tabs and newlines are bad there. But, anyways, the parser shouldn't remove whitespace; this should be done in a separate cleanup. The result of the author parsing also looks good to me (although one could argue that the Jr part is unimportant and should be deleted in an abbreviated representation...). |
XMP: This is JabRef's implemenation to store BibTeX data inside PDFs to ease sharing of BibTeX data along with the PDF. Refs #938 #1096 (comment). Think, we have to switch to Dublin Core or to biblatexml. This takes more than a few hours. Since I am fan of this way of sharing, I'd like to keep the tests to be able to think of backward compatibility. |
My 2 cents:
|
@lenhard Thanks for your input. So I just need to change the first tests to another field right now, e.g. title?! |
Or: Rewrite the tests to check that the content of the file field is NOT changed. @stefan-kolb You should check whether tests for these two aspects are already in place - if so, you can just delete the |
@stefan-kolb @matthiasgeiger If you invert the tests, then use either |
78ee026
to
57226fe
Compare
6ba6b62
to
2563fe2
Compare
Ok, I fixed or removed all tests now. Only one ignored test is remianing in logic, which will be fixed by @matthiasgeiger in his custom entries PR?! The GUI tests still remain ignored. |
…rips duplicated whitespaces
8731bbb
to
05af767
Compare
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.
One minor thing (formatting) and one request for clarification.
public void testCommandLineByKey() throws IOException, TransformerException { | ||
|
||
File tempBib = File.createTempFile("JabRef", ".bib"); | ||
try (BufferedWriter fileWriter = Files.newBufferedWriter(tempBib.toPath(), StandardCharsets.UTF_8)) { | ||
fileWriter.write(t1BibtexString()); | ||
fileWriter.write(t2BibtexString()); | ||
fileWriter.close(); |
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.
Why do you need the close statement here? fileWrite
is opened in a try-with-resources, so it will be closed at the end.
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 test fails if I do not close the current fileWriter. Maybe it would be betetr to extract the code below from the try statement...
public void testCommandLineByKey() throws IOException, TransformerException { | ||
|
||
File tempBib = File.createTempFile("JabRef", ".bib"); | ||
try (BufferedWriter fileWriter = Files.newBufferedWriter(tempBib.toPath(), StandardCharsets.UTF_8)) { | ||
fileWriter.write(t1BibtexString()); | ||
fileWriter.write(t2BibtexString()); | ||
fileWriter.close(); | ||
|
||
{ // First try canh05 |
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.
Not your change, but why is this bracket opening in a new line? Can you fix the formatting in this method?
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 bracket below? This is some old stuff. I already forgot what this does in Java...creates a new isolated scope or so...
@lenhard Thanks for the review, some good input here! |
this.prefs = Objects.requireNonNull(prefs); | ||
this.encoding = StandardCharsets.UTF_8; | ||
setDefaultProperties(); | ||
initialize(OOBibStyle.class.getResource(resourcePath).openStream()); | ||
initialize(OOBibStyle.class.getResourceAsStream(resourcePath)); |
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.
be aware that the inputstream is null if the resource cannot be found, resulting in a NPE.
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.
Is this any different than before?
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.
Maybe we can wrap it inside Objects.requireNonNull()
and also add some Objects.requireNonNull
for resourcePath
and prefs
before lin 153
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.
Added some requireNonNulls.
try { | ||
XMPUtilMain.main(new String[]{"OezbekC06", tempBib.getAbsolutePath(), pdfFile.getAbsolutePath()}); | ||
} finally { | ||
System.setOut(sysOut); | ||
} | ||
} |
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.
For something like this, I would prefer to create a utility method that can be called. Should be useful on other occasions as well. You can pass in a lambda function which will be called from the utility method, and the method could simply return the value of the sysout as a String.
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.
To be honest, I didn't want to refactor the tests but just get them running again.
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.
OK for leave as is - I copied @simonharrer's comment to JabRef#6.
if (!tempBib.delete()) { | ||
// TODO: file is still locked | ||
System.err.println("Cannot delete temporary file"); | ||
} |
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.
This should be either an assertion or deleted.
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.
For some reason the file cannot be deleted and is still locked but I dunno where yet (and don't really care).
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.
Why not just calling deleteOnExit()
? This would prevent these kind of issues.
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.
A better way to use a TemporaryFolder rule and create the file there. Then junit keeps track of deleting it
public void parseRemovesNewlineInFileField() throws IOException { | ||
ParserResult result = BibtexParser.parse(new StringReader("@article{canh05,file = {ups \n\tsala}}"), | ||
public void parsePreservesNewlineInAbstractField() throws IOException { | ||
ParserResult result = BibtexParser.parse(new StringReader("@article{canh05,abstract = {ups \nsala}}"), | ||
importFormatPreferences); |
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.
Would it make sense to create a BibtexParser.parse(string, prefs) method?
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.
I dunno, amybe @lenhard knows.
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.
Well, it is what the BibtexParser.parse
method does internally. If you parse multiple times subsequently, there might be a little performance impact, if you parse only once then it does not matter.
importFormatPreferences); | ||
|
||
Collection<BibEntry> c = result.getDatabase().getEntries(); | ||
BibEntry e = c.iterator().next(); | ||
assertEquals(Optional.of("ups sala"), e.getField("file")); | ||
assertEquals(Optional.of("ups " + OS.NEWLINE + "sala"), e.getField("abstract")); |
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.
Do we have a constant for the abstract field somewhere?
// PDF should be annotated: | ||
List<BibEntry> l = XMPUtil.readXMP(pdfFile, xmpPreferences); | ||
Assert.assertEquals(1, l.size()); | ||
assertEqualsBibtexEntry(t1BibtexEntry(), l.get(0)); |
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.
I do not like to assert the size of a list, because the result would simply say that the count mismatches, not which elements are in the list. Why not use the assertEqualsBibtexEntryList method if there is some which compares a list containing t1BibtexEntry with l?
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 far as I know there is no such method or maybe @tobiasdiez knows.
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.
Assert.assertEquals(Collections.singleton(tlBibtexEntry()), l) should work (and please rename l
to something better :-)
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.
Uhh... as this relies on the equals implemenation of BibEntry I'm not sure whether this really works. 😉
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.
Yeah, we wanted to use a canonical string representation for the bib entries.
The current implementation of BibEntryAssert also relies on equals
so it is very much OK to use the code @tobiasdiez proposed.
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.
Does not work right now author is not normailzed or so:
Expected
[@article{canh05,
author = {Crowston, K. and Annabi, H. and Howison, J. and Masango, C.},
booktitle = {Hawaii International Conference On System Sciences (HICSS)},
owner = {oezbek},
timestamp = {2006.05.29},
title = {Effective work practices for floss development: A model and propositions},
url = {http://james.howison.name/publications.html},
year = {2005}
}]
Actual
[@article{canh05,
author = {K. Crowston and H. Annabi and J. Howison and C. Masango},
booktitle = {Hawaii International Conference On System Sciences (HICSS)},
owner = {oezbek},
timestamp = {2006.05.29},
title = {Effective work practices for floss development: A model and propositions},
url = {http://james.howison.name/publications.html},
year = {2005}
}]
I would skip this for now.
// PDF should be annotated: | ||
l = XMPUtil.readXMP(pdfFile, xmpPreferences); | ||
Assert.assertEquals(1, l.size()); | ||
assertEqualsBibtexEntry(t2BibtexEntry(), l.get(0)); |
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.
See above.
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.
In general: LGTM
As usual, I vote for keeping and adapting tests. 😇 Find the comments inside. ☁️
@@ -176,7 +176,7 @@ private static void usage() { | |||
System.out.println(" xmpUtil <bib> <pdf>"); | |||
System.out.println(""); | |||
System.out | |||
.println("To report bugs visit http://jabref.sourceforge.net"); | |||
.println("To report bugs visit https://github.com/JabRef/jabref/issues"); |
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.
https://issues.jabref.org
, pleae
this.prefs = Objects.requireNonNull(prefs); | ||
this.encoding = StandardCharsets.UTF_8; | ||
setDefaultProperties(); | ||
initialize(OOBibStyle.class.getResource(resourcePath).openStream()); | ||
initialize(OOBibStyle.class.getResourceAsStream(resourcePath)); |
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.
Maybe we can wrap it inside Objects.requireNonNull()
and also add some Objects.requireNonNull
for resourcePath
and prefs
before lin 153
@@ -786,19 +786,6 @@ public void parseWarnsAboutUnmatchedContentInEntry() throws IOException { | |||
} | |||
|
|||
@Test | |||
@Ignore("Ignoring because this is an edge case") |
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.
I would like to know, what's happening here. Can the test be adapted to the current behavior and possibly commented, what should happen?
I would need that if someone comes over and wants to replace our parser 😇
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.
It just doesn't work right now as @lenhard says. So there is no sense to test it at the moment.
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.
JabRef returns one entry, which pretty good. I would like to have this checked in tests if we adress it.
The test has to be adapted accordingly.
Result is
@article{test, author = {author bracket #too##much#} }
Would it be OK if you include this as expected case, even if the }
gets lost...
This documents the drawback of JabRef.
OK, additional documentation at https://help.jabref.org/en/Bibtex would be better, but none of us has time for that.
@@ -86,15 +82,6 @@ public void testHTMLChar() throws IOException { | |||
} | |||
|
|||
@Test | |||
@Ignore |
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.
Why not adapting it to the current behavior? I think, we drop <br>
now, which is fine. Why not leaving the additional test?
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.
?
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.
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.
If that's really what we want to achieve here \n\n -> ' '
I'm not sure about this that's why I removed the test.
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.
In other words: That is the current behavior, yes. But should it really be the correct behavior? In my opinion we should only test correct behavior not as is behavior. As the correct behavior for example
is not working right now I cannot really test it.
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.
I think, we decided to remove newlines in non-multiline fields. Is it #357?
Even if that is not the desired behavior, I would add // TODO: The correct behavior is
to indicate that someone should work on it.
Alternative: open an issue on GitHub. - I am currently optimizing (i) to keep the number of opened issues low and (ii) to have documentation close to the code and not spread around.
// PDF should be annotated: | ||
List<BibEntry> l = XMPUtil.readXMP(pdfFile, xmpPreferences); | ||
Assert.assertEquals(1, l.size()); | ||
assertEqualsBibtexEntry(t1BibtexEntry(), l.get(0)); |
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.
Yeah, we wanted to use a canonical string representation for the bib entries.
The current implementation of BibEntryAssert also relies on equals
so it is very much OK to use the code @tobiasdiez proposed.
if (!tempBib.delete()) { | ||
// TODO: file is still locked | ||
System.err.println("Cannot delete temporary file"); | ||
} |
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.
Why not just calling deleteOnExit()
? This would prevent these kind of issues.
try { | ||
XMPUtilMain.main(new String[]{"OezbekC06", tempBib.getAbsolutePath(), pdfFile.getAbsolutePath()}); | ||
} finally { | ||
System.setOut(sysOut); | ||
} | ||
} |
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.
OK for leave as is - I copied @simonharrer's comment to JabRef#6.
# Conflicts: # src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java
The result is:
Expected :Other, A. N.; Actual :Other, Jr., A. N.
We decided that this is expected behavior for now.\n\n
to<br>
conversion. Cannot be handled anymore as the BibTeX parser strips duplicated whitespaces by default!