-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Differ disregards trailing newlines. #70
Comments
So it was a conscious decision to not diff single line strings, so this behaviour probably reflects that, I'm unsure what we should do with trailing newlines, it does feel wrong to ignore them. |
👋 Hi @JonRowe. I'm interested in investigating this issue. I'll be working with @CoralineAda! 🌸 |
Sure, feel free! |
This was referenced Jul 7, 2016
jeffmccune
added a commit
to jeffmccune/sensu-puppet
that referenced
this issue
Jul 25, 2017
Without this patch there are no spec tests for the sensu_check JSON provider. This is problem because a reference is needed to specify the expected behavior of all providers. This patch implements a pattern of stubbing out the filesystem. All reads and writes in the provider itself are routed through the `read_file` and `write_json_object` methods. The RSpec tests then use rspec-mocks to stub out the reads and set expectations on the output. This reference may be applied to any provider using the `flush` method. The setter methods in the provider for each property are expected to update state in an instance variable, conventionally named @property_flush but named @conf in the sensu_check provider. The flush method is responsible for writing out @property_flush (@conf), which we intercept and set expectations on the data provided. N.B. There is a bug with Rspec where the expected and actual values of multi-line strings will not have a nice diff output if the two strings disagree on the presence of the trailing newline. See rspec/rspec-support#70 for more information. Because of this issue in combination with the use of IO#puts in the write_output class method, care should be taken with the examples to make sure the expected and actual values agree on the trailing newline. In this patch, the fixture data for the expected output is chomp()'ed to match the string passed to write_output(). Resolves sensu#759
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Differ currently disregards any trailing newlines when making a diff of two strings. This has two main consequences I can find.
This isn't necessarily a bug, but it could make the output harder to interpret.
The protocol Differ follows is to either output a diff for diffable arguments, or an empty string for non-diffable arguments. Thus two single-line strings get no diff:
One multi-line string and one single-line string get a diff:
Identical strings get no diff:
If two strings differ only in one having a trailing newline, Differ returns a newline:
This screws up the usage of Differ in rspec-expectations because it expects the return value of Differ to follow the "empty or diff" pattern. When I attempt to compare two strings that only differ by one newline, I get output that indicates there should be a diff but without a diff:
Trimmed output:
I'm not sure how to fix this. It looks like HunkGenerator's preprocessing of strings is getting rid of newlines so I don't know if this can be fixed without mucking with that, potentially breaking other things.
FWIW, I played around with GNU diff in these scenarios and it indicates a trailing new line in diffs:
The text was updated successfully, but these errors were encountered: