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

Rewrite the no-input-file.stderr test in Rust and support diff #124257

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

JoverZhang
Copy link
Contributor

Rewrite the no-input-file.stderr test from #121876.
Use the similar lib to replace the diff command.

@rustbot
Copy link
Collaborator

rustbot commented Apr 22, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jieyouxu (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 22, 2024
src/tools/run-make-support/src/diff/mod.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,38 @@
#[cfg(test)]
mod tests {
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 think the tests here will not be executed in CI for now (I don't know how to configure it).

Copy link
Member

Choose a reason for hiding this comment

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

I think that is fine for now, but if you want to add support for running the unit tests in run-make-support, you'll need to do something like CompiletestTest:

impl Step for CompiletestTest {

Modulo the unstable test feature part because run-make-support is stable-only and does not use any unstable (cargo or rustc) features.

Copy link
Member

Choose a reason for hiding this comment

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

I filed issue #124267 to track this.

src/tools/run-make-support/src/diff/tests.rs Outdated Show resolved Hide resolved
@JoverZhang JoverZhang marked this pull request as ready for review April 22, 2024 13:33
@rustbot
Copy link
Collaborator

rustbot commented Apr 22, 2024

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

The run-make-support library was changed

cc @jieyouxu

Some changes occurred in run-make tests.

cc @jieyouxu

@klensy
Copy link
Contributor

klensy commented Apr 22, 2024

dissimilar already in tree, maybe use it?

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

If we have dissimilar in tree already, we should use dissimilar as suggested to avoid introducing another similar (heh) dependency.

src/tools/run-make-support/src/diff/mod.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,38 @@
#[cfg(test)]
mod tests {
Copy link
Member

Choose a reason for hiding this comment

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

I think that is fine for now, but if you want to add support for running the unit tests in run-make-support, you'll need to do something like CompiletestTest:

impl Step for CompiletestTest {

Modulo the unstable test feature part because run-make-support is stable-only and does not use any unstable (cargo or rustc) features.

@@ -0,0 +1,38 @@
#[cfg(test)]
mod tests {
Copy link
Member

Choose a reason for hiding this comment

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

I filed issue #124267 to track this.

src/tools/run-make-support/src/diff/tests.rs Outdated Show resolved Hide resolved
src/tools/run-make-support/src/diff/mod.rs Outdated Show resolved Hide resolved
src/tools/run-make-support/src/diff/mod.rs Outdated Show resolved Hide resolved
tests/run-make/no-input-file/rmake.rs Outdated Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 22, 2024
@JoverZhang
Copy link
Contributor Author

dissimilar already in tree, maybe use it?

@klensy @jieyouxu Thank you for your suggestion. I value your advice and took the time to explore how to use dissimilar to output the diff format. However, it seems this approach may not work. I found that dissimilar only allows comparison based on char tokens, whereas diff should ideally perform comparisons starting with lines as tokens.

For example, when we use dissimilar::diff("bar", "baz"), we get:

  ba
- r
+ z

But what we expect is:

- bar
+ baz

I also thought about encoding all lines first (into a different Unicode char) and then calling dissimilar::diff(). But I don't think that's very elegant. :(

If you have any better suggestions, please let me know at your earliest convenience.

@jieyouxu
Copy link
Member

I found that dissimilar only allows comparison based on char tokens, whereas diff should ideally perform comparisons starting with lines as tokens.

If that's the case, then I think using similiar is fine because otherwise you'd be basically reimplementing it on top of dissimiliar (I had a brief look, and it looks like dissimiliar didn't port over google's Diff Match Patch's line mode).

@klensy
Copy link
Contributor

klensy commented Apr 23, 2024

Well, i guess diff won't work too?

@jieyouxu

This comment was marked as resolved.

@JoverZhang JoverZhang requested a review from jieyouxu April 24, 2024 14:42
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 24, 2024
@@ -3343,6 +3343,7 @@ version = "0.0.0"
dependencies = [
"object 0.34.0",
"regex",
"similar",
Copy link
Member

@jieyouxu jieyouxu Apr 24, 2024

Choose a reason for hiding this comment

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

Could you check if you can just use the diff from the environment? As in, I think we already assume diff exists:

# diff with common flags for multi-platform diffs against text output
DIFF := diff -u --strip-trailing-cr

If that's not available, then I'm open to adding similar.

EDIT: Now that I think about it, the easier to run the test the better. For example, I think grep isn't by default available on Windows? Would be nice to not have to rely on those external dependencies if possible/reasonable especially if they can have platform-specific differences and what not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be nice to not have to rely on those external dependencies if possible/reasonable especially if they can have platform-specific differences and what not.

I think so too.

use run_make_support::{diff, rustc};

fn main() {
let output = rustc().arg("--print").arg("crate-name").run_fail_assert_exit_code(1);
Copy link
Member

Choose a reason for hiding this comment

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

One last nit: can you add a print helper method to Rustc? So the callsite becomes something like

rustc().print("crate-name")

This PR looks good to me otherwise.

@jieyouxu
Copy link
Member

Thanks for the PR!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 25, 2024

📌 Commit f3530cf has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 25, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 25, 2024
Rewrite the `no-input-file.stderr` test in Rust and support diff

Rewrite the `no-input-file.stderr` test from rust-lang#121876.
Use the `similar` lib to replace the `diff` command.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 25, 2024
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#124257 (Rewrite the `no-input-file.stderr` test in Rust and support diff)
 - rust-lang#124324 (Minor AST cleanups)
 - rust-lang#124327 (CI: implement job skipping in Python matrix calculation)
 - rust-lang#124345 (Enable `--check-cfg` by default in UI tests)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 25, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#124257 (Rewrite the `no-input-file.stderr` test in Rust and support diff)
 - rust-lang#124324 (Minor AST cleanups)
 - rust-lang#124327 (CI: implement job skipping in Python matrix calculation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a2d6b1b into rust-lang:master Apr 25, 2024
10 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 25, 2024
Rollup merge of rust-lang#124257 - JoverZhang:rmake-diff, r=jieyouxu

Rewrite the `no-input-file.stderr` test in Rust and support diff

Rewrite the `no-input-file.stderr` test from rust-lang#121876.
Use the `similar` lib to replace the `diff` command.
@JoverZhang JoverZhang deleted the rmake-diff branch April 26, 2024 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants