-
Notifications
You must be signed in to change notification settings - Fork 105
Fix EOL issue with tests #370
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
Conversation
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 wanted to get these comments down before I forgot but I don't recommend working on them yet. Going to start a separate conversation about the goal and approach.
src/document.rs
Outdated
@@ -2,6 +2,7 @@ use std::collections::HashMap; | |||
use std::collections::hash_map::Entry; | |||
use std::default::Default; | |||
use std::path::{Path, PathBuf}; | |||
use std::iter::FromIterator; |
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.
(arbitrary place)
Fix EOL issue with tests
Normalizing everything cobalt read to LF and and outputing LF as well.
excerpts_CRLF test has fixtures as CRLF, and target as LF
typo
Could you get this to conform to conventional changelist format, including calling out Fixes #241
?
I didn't point it out in the other PRs because they were purely internal and unrelated to Issues.
.gitattributes
Outdated
@@ -0,0 +1,2 @@ | |||
* text eol=lf | |||
**/tests/fixtures/*_CRLF/** text eol=crlf |
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 be better to have a separate .gitattributes
file right there in the test?
Having it local like that seems like it'd help in terms of moving the code around, etc.
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 didn't know we can have multiple .gitattributes
, good idea!
tests/mod.rs
Outdated
@@ -50,6 +53,8 @@ fn assert_dirs_eq(expected: &Path, actual: &Path) { | |||
.read_to_string(&mut created) | |||
.expect("Could not read to string"); | |||
|
|||
let created = String::from_iter(normalized(created.chars())); |
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 .gitattributes
is saying lf
for everything, and the test should be generating lf
based output, why is normalization needed here?
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.
uh, good point, I… don't know, and without, it does not work so it seems I failed here… need more work :-/
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 forgot one normalization when reading the layout, it makes the situation better but my test still not pass :-/
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.
Found multiples occurrences of read_file
some might need normalization as well, I'll see that later
@@ -0,0 +1,2 @@ | |||
* text eol=lf |
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.
Forgot to ask, why is this needed? Is it just for the tests? If so, should it just live in in tests
and target the targets
and fixtures
folders?
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.
Also, should we be added an editorconfig file(s) to specify our line ending policies?
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 is to make sure that the project is checked out with Linux EOL in source code and test (with exception of the *_CRLF folders) so cargo fmt
won't messed up the files being different and having the tests using LF and only some using CRLF to make sure the normalizing is working
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.
Oh right, the problem of aligning rustfmt with git.
This seems less obvious enough that it might deserve a comment in the file.
tl;dr I'm fine with this going in once we work through the issues So let me see if I can summarize our long conversation from #241
There are a mixture of solutions we can apply
Traits for us to weigh out in evaluating a solution
My thoughts over time:
So while I'm still concerned about giving advanced users the power to do what they want, I think it is reasonable for this to go in now. In the future, we can either re-evaluate and pull this out or add a config flag for people to opt-out. Neither should be done at this moment though. |
3e0a3f9
to
68d6f60
Compare
The route I choose is to normalize the EOL when reading files. 3 normalizations are needed (see diffs) and it make the tests pass :D |
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.
Almost there
@@ -0,0 +1,2 @@ | |||
# force tests to keep their Windows EOL | |||
* text eol=crlf |
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.
Should there be a non-root editorconfig here?
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.
we can have multiple editorconfig as well? I'll add it tomorrow :D
tests/mod.rs
Outdated
@@ -5,6 +5,7 @@ extern crate cobalt; | |||
extern crate error_chain; | |||
extern crate tempdir; | |||
extern crate walkdir; | |||
extern crate normalize_line_endings; |
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.
Unused?
tests/mod.rs
Outdated
.expect("Comparison error"); | ||
let src_file = Path::new(actual).join(&extra_file); | ||
let extra_file = entry.path().strip_prefix(result).expect("Comparison error"); | ||
let src_file = Path::new(expected).join(&extra_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.
What was the intent of changing these variables around?
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 found the original name confusing, I forgot to rollback them, it was for me reasoning, I'll rollback this ^^' sorry
src/document.rs
Outdated
@@ -194,6 +196,7 @@ impl Document { | |||
-> Result<Document> { | |||
trace!("Parsing {:?}", rel_path); | |||
let content = files::read_file(src_path)?; | |||
let content = String::from_iter(normalized(content.chars())); |
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'm sorry I didn't notice this before but ... what do you think of doing the normalization in read_file
?
I could see it being nice that read_file
is a general abstraction for loading data throughout cobalt. If there are cases where we shouldn't normalize (like maybe cobalt migrate
), then we just don't use 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 didn't notice read_file was ours… ^^'
@@ -0,0 +1,3 @@ | |||
[*] | |||
end_of_line = lf | |||
insert_final_newline = true |
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 file should specify root
root: special property that should be specified at the top of the file outside of any sections. Set to "true" to stop .editorconfig files search on current file.
any nested ones shouldn't.
Once the CI are done, I think this is merge-ready :D |
Closes cobalt-org#241 add editorconfig add gitattributes
Normalizing everything cobalt read to LF and and outputing LF as well.
excerpts_CRLF test has fixtures as CRLF, and target as LF