Skip to content

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

Merged
merged 1 commit into from
Jan 27, 2018
Merged

Fix EOL issue with tests #370

merged 1 commit into from
Jan 27, 2018

Conversation

Geobert
Copy link
Contributor

@Geobert Geobert commented Jan 23, 2018

Normalizing everything cobalt read to LF and and outputing LF as well.
excerpts_CRLF test has fixtures as CRLF, and target as LF

Copy link
Member

@epage epage left a 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;
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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()));
Copy link
Member

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?

Copy link
Contributor Author

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 :-/

Copy link
Contributor Author

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 :-/

Copy link
Contributor Author

@Geobert Geobert Jan 25, 2018

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
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

@Geobert Geobert Jan 25, 2018

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

Copy link
Member

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.

@epage
Copy link
Member

epage commented Jan 25, 2018

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

  • Issue is about getting tests to work regardless of someone's local line ending setting in git
  • In the investigation, we found
    • cobalt's output could produce mixed line endings if the user uses Windows line endings because some sections are converting or inserting line endings (markdown, our markdown reference code)
    • cobalt can miss excerpts if the user uses Windows line endings and the default excerpt separator because it specifies a specific line ending policy

There are a mixture of solutions we can apply

  • Normalize line endings in what we output
  • Normalize line endings in our tests (see Normalize EOL before diff #335)
    • There was concern that this just masks behavior
  • Detect the user's line endings and convert the output to match it
  • Use .gitattributes and .editorconfig to encourage certain behavior within cobalt's tests (doesn't impact users)
  • Encourage repos with users in different environments to use a non-default excerpt_separator like <!--more-->.
    • What percent of clients will have users in different environments?
  • Change the default newline separator
    • The one nice thing about our current one is that it is more "natural"

Traits for us to weigh out in evaluating a solution

  • Preserving the user's line endings
  • Consistent line endings
  • Performance
  • UX Simplicity
  • Implementation simplicity

My thoughts over time:

  • Initially concerned about us unintentionally munging the line endings and thinking that needs to be fixed so we can preserve the user's data as-is
    • Can you tell I work in an industry where the number one rule is "don't corrupt data" (people might die)?
    • I'm also concerned about the users pushing cobalt in directions we never originally considered and needing precise control over their output
  • Upon realizing some of it was out of our control (markdown), instead of trying to auto-detect or anything, wondering if we should just leave line endings as-is.
    • Most environments accept mixed line endings
    • It lets the user opt-out of things messing up their line endings, so they can have precise control over their output
  • If we are to have any ambition for wide adoption, we need to "just work" which means we can't just tell windows users "Oh, go change the excerpt separator"

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.

@Geobert Geobert force-pushed the fix#241 branch 2 times, most recently from 3e0a3f9 to 68d6f60 Compare January 26, 2018 20:01
@Geobert
Copy link
Contributor Author

Geobert commented Jan 26, 2018

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

Copy link
Member

@epage epage left a 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
Copy link
Member

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?

Copy link
Contributor Author

@Geobert Geobert Jan 26, 2018

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;
Copy link
Member

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);
Copy link
Member

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?

Copy link
Contributor Author

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()));
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

http://editorconfig.org/

any nested ones shouldn't.

@Geobert
Copy link
Contributor Author

Geobert commented Jan 27, 2018

Once the CI are done, I think this is merge-ready :D

Closes cobalt-org#241
add editorconfig
add gitattributes
@epage epage merged commit 0aedcba into cobalt-org:master Jan 27, 2018
@Geobert Geobert deleted the fix#241 branch January 27, 2018 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants