Skip to content
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

golden: Add a var to disable normalization of crlf #149

Merged
merged 1 commit into from Apr 4, 2020

Conversation

dnephin
Copy link
Member

@dnephin dnephin commented Mar 20, 2019

Possible fix for #146

I'm not sure if this is the best option yet, but from what I have read the autocrlf config seems to default to true on windows. If this behaviour is likely to conflict with git defaults we should at least have a way to turn it off.

@codecov
Copy link

codecov bot commented Mar 20, 2019

Codecov Report

Merging #149 into master will decrease coverage by 0.76%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #149      +/-   ##
==========================================
- Coverage   83.91%   83.15%   -0.77%     
==========================================
  Files          29       29              
  Lines        2058     2030      -28     
==========================================
- Hits         1727     1688      -39     
- Misses        225      234       +9     
- Partials      106      108       +2
Impacted Files Coverage Δ
golden/golden.go 85.96% <0%> (-7.69%) ⬇️
fs/file.go 82.85% <0%> (-11.09%) ⬇️
env/env.go 89.65% <0%> (-10.35%) ⬇️
assert/cmp/compare.go 88.77% <0%> (-5.62%) ⬇️
assert/assert.go 81.44% <0%> (-0.91%) ⬇️
icmd/command.go 85.18% <0%> (-0.11%) ⬇️
icmd/ops.go 0% <0%> (ø) ⬆️
x/subtest/context.go 91.3% <0%> (ø) ⬆️
assert/cmp/result.go 71.42% <0%> (ø) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8dac165...f13b253. Read the comment docs.

golden/golden.go Outdated
// you will need to set this to false.
//
// The default value may change in a future major release.
var NormalizeCRLFToLF = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding another flag like test.update-golden ? You can then control the CRLF from command line (or Makefile) depending you are on windows or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not responding for a year, I must have missed this comment and just noticed it now.

I don't think a flag is a good option in this case because you can't pass flags to the entire test suite. Any package that doesn't import golden will fail with "unexpected flag" error. So using a flag makes it impossible to run go test ./....

A flag is ok for the update-golden case because in general we expect to only update a single test , or package at a time. Having to run only 1 package to set the flag is fine in this case, maybe even desirable to prevent accidentally running it against the entire test suite.

I expect anyone setting NormalizeCRLFToLF would want it off for the entire package, so a global seems more correct. I just changed the default to read from an env var, which might be a better way of setting the value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks that makes sense 👍

Copy link
Member Author

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since this PR was opened, so I'm going to restate my thinking here to see if it makes sense.

Desired outcome:

  1. all golden files use \n line endings so that contributors on any platform can update them to the same value.
  2. when the actual value from the unit-under-test contains \r\n line endings we normalize them to \n so that they match the expected.

The original normalize feature solved this problem as long as git did not try to convert \n to \r\n on checkout.

When running on windows, and git has core.autocrlf enabled the golden files will be un-normalized on checkout and contain \r\n.

When core.autocrlf is enabled git has solved the normalization problem for us. It ensures that files are committed with \n line endings, but converts them to \r\n so that even though the actual values from a test contain \r\n, so does the expected golden file.

Had I known about this setting earlier, I think I would have suggested that we not add the normalize and rely on git to handle it. Now that we have it, I think we should add this option to disable the behaviour for repos which use the git option to handle it.

I think the normalization options we have in fs are correct because those files may not come from files in git, so git will not normalize those.

cc @vdemeester @silvin-lubecki

golden/golden.go Outdated
// you will need to set this to false.
//
// The default value may change in a future major release.
var NormalizeCRLFToLF = true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not responding for a year, I must have missed this comment and just noticed it now.

I don't think a flag is a good option in this case because you can't pass flags to the entire test suite. Any package that doesn't import golden will fail with "unexpected flag" error. So using a flag makes it impossible to run go test ./....

A flag is ok for the update-golden case because in general we expect to only update a single test , or package at a time. Having to run only 1 package to set the flag is fine in this case, maybe even desirable to prevent accidentally running it against the entire test suite.

I expect anyone setting NormalizeCRLFToLF would want it off for the entire package, so a global seems more correct. I just changed the default to read from an env var, which might be a better way of setting the value.

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@dnephin dnephin merged commit 4299c6d into gotestyourself:master Apr 4, 2020
@dnephin dnephin deleted the golden-normalize branch April 4, 2020 22:28
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.

None yet

2 participants