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

Portably escape pipe characters in diff --ignore-matching-lines regexes #111171

Closed
wants to merge 2 commits into from

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented May 4, 2023

#110942 was supposed to fix the regexes used by diff --ignore-matching-lines in the instrument-coverage tests.

But based on my investigations in #111116, it turns out that that change successfully fixed the tests on Mac, while silently breaking them on Linux (which is where they actually get run in CI).

The underlying cause is that GNU diff and Apple/FreeBSD diff use slightly different regex dialects, with a crucial difference:

  • GNU diff treats | as a literal pipe character, and treats \| as a regex OR operator
  • Apple/FreeBSD diff treats | as a regex OR operator, and treats \| as a literal pipe character.

This is very frustrating, and ideally I would rip out all of this code and replace it with something written in Rust or Python. But for now, my focus is on making a small fix that will restore the tests to proper working order on both Linux and Mac.

Fortunately, there is a way to portably match a literal pipe character in both diff implementations: wrap it in a character class [|]. So that's what this PR does.

Zalathar added 2 commits May 4, 2023 12:59
This snapshot fell out of sync while the `diff --ignore-matching-lines` regexes
were silently broken on Linux.
@rustbot
Copy link
Collaborator

rustbot commented May 4, 2023

r? @Mark-Simulacrum

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 4, 2023
@Zalathar
Copy link
Contributor Author

Zalathar commented May 4, 2023

Over in Zulip I mentioned that I was going to add some extra checks as well, to ensure that diff interprets regexes as intended

I did try writing some checks, but they ended up being so complex and fragile that they ultimately didn't seem to be a net improvement, so I've left them out for now. make/dash is unfortunately not a very pleasant programming environment.

@Zalathar
Copy link
Contributor Author

Zalathar commented May 4, 2023

I might have a go at implementing instantiation-sorting by piping the output through a Python script, so I can get rid of all this --ignore-matching-lines gunk.

@Zalathar
Copy link
Contributor Author

Zalathar commented May 4, 2023

Closing this in favour of the Python-based sort filter that I've written.

@Zalathar Zalathar closed this May 4, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 6, 2023
…acrum

Fix instrument-coverage tests by using Python to sort instantiation groups

rust-lang#110942 was intended to fix a set of `-Cinstrument-coverage` tests, but it ended up silently *breaking* those tests on Linux, for annoying reasons detailed at rust-lang#111171.

Dealing with `diff --ignore-matching-lines` across multiple platforms has been such a hassle that I've instead written a simple Python script that can detect instantiation groups in the output of `llvm-cov show`, and sort them in a predictable order so that they can be used as snapshots for an ordinary invocation of `diff`.

This approach should be much less error-prone, because it can't accidentally ignore the wrong lines, and any unforeseen problems will tend to result in a Python exception or a failing diff.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 6, 2023
…acrum

Fix instrument-coverage tests by using Python to sort instantiation groups

rust-lang#110942 was intended to fix a set of `-Cinstrument-coverage` tests, but it ended up silently *breaking* those tests on Linux, for annoying reasons detailed at rust-lang#111171.

Dealing with `diff --ignore-matching-lines` across multiple platforms has been such a hassle that I've instead written a simple Python script that can detect instantiation groups in the output of `llvm-cov show`, and sort them in a predictable order so that they can be used as snapshots for an ordinary invocation of `diff`.

This approach should be much less error-prone, because it can't accidentally ignore the wrong lines, and any unforeseen problems will tend to result in a Python exception or a failing diff.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 12, 2023
…acrum

Fix instrument-coverage tests by using Python to sort instantiation groups

rust-lang#110942 was intended to fix a set of `-Cinstrument-coverage` tests, but it ended up silently *breaking* those tests on Linux, for annoying reasons detailed at rust-lang#111171.

Dealing with `diff --ignore-matching-lines` across multiple platforms has been such a hassle that I've instead written a simple Python script that can detect instantiation groups in the output of `llvm-cov show`, and sort them in a predictable order so that they can be used as snapshots for an ordinary invocation of `diff`.

This approach should be much less error-prone, because it can't accidentally ignore the wrong lines, and any unforeseen problems will tend to result in a Python exception or a failing diff.
@Zalathar Zalathar deleted the pipe-escape branch May 31, 2023 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants