Skip to content

Remove whitespaces on rust-env directives from some test codes #133148

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

Closed

Conversation

Shunpoco
Copy link
Contributor

This PR is a part of #132990.

{unset-,}{rustc,exec}-env directive shouldn't have whitespace.

NOTE: It looks that those whitespaces don't affect tests because I think those are parsed then added as temporary env vars on command line. Those are parsed by Rust properly.
For example, SOME_ENV=1 ⌴RUST_TRACEBACK=0 rustdoc src/lib.rs is equivalent with SOME_ENV=1 RUST_TRACEBACK=0 rustdoc src/lib.rs. (Of course for code's consistency, we should use the directives without any whitespaces.)

@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @fmease (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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 17, 2024
@Shunpoco Shunpoco changed the title [WIP] Remove whitespaces on rust-env directives from some test codes Remove whitespaces on rust-env directives from some test codes Nov 17, 2024
@Shunpoco Shunpoco marked this pull request as ready for review November 17, 2024 23:22
@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2024

The Miri subtree was changed

cc @rust-lang/miri

@Shunpoco
Copy link
Contributor Author

r? @jieyouxu

@rustbot rustbot assigned jieyouxu and unassigned fmease Nov 17, 2024
@saethlin
Copy link
Member

saethlin commented Nov 18, 2024

Miri uses a different test runner that does not have this problem (I've linked its parsing code for this directive below). Can you revert the changes in src/tools/miri?

https://github.com/oli-obk/ui_test/blob/a2a7d13b0394767f5770eb563fc7fc30a3b780e5/src/parser.rs#L744-L745

            "rustc-env" => (this, args, _span){
                for env in args.split_whitespace() {

@RalfJung
Copy link
Member

If this is important for a test's correctness, the runner should complain about the whitespace. Otherwise, we'll soon get new tests with such whitespace. Fixing this just on the tests we currently have is not sustainable.

Or, alternatively, we could just adjust the runner to work fine despite whitespace?

@jieyouxu
Copy link
Member

If this is important for a test's correctness, the runner should complain about the whitespace. Otherwise, we'll soon get new tests with such whitespace. Fixing this just on the tests we currently have is not sustainable.

Or, alternatively, we could just adjust the runner to work fine despite whitespace?

I'm inclined to adjust the env directives so that they strip leading whitespaces, i.e. between whatever-env: ENV_NAME=.... In fact, I'll send that as a follow-up ~today. In theory a test might want "special" env vars, but I think those are better served as something like a run-make test, or we could add some kind of quoting mechanism to escape it. In that case, we shouldn't need to adjust these tests anyway.

@Shunpoco thanks for the PR, but I think I'm going to address the underlying directive parsing problem instead.

@jieyouxu jieyouxu closed this Nov 18, 2024
@Shunpoco
Copy link
Contributor Author

Sure, I will continue to track the issue for my curiosity 😄

@Shunpoco Shunpoco deleted the issue-132990-remove-whitespaces branch November 18, 2024 08:31
@jieyouxu
Copy link
Member

(Also to make it more complicated, compiletest is responsible for test suites under tests/, but miri uses ui_test as the test runner which isn't compiletest, and rustdoc tests might have slightly different handling that I haven't dug into yet. I only ran into this for a particular ui test.)

Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 8, 2025
compiletest: Trim whitespace from environment variable names

When a test contains a directive like `//@ exec-env: FOO=bar`, compiletest currently includes that leading space in the name of the environment variable, so it is defined as ` FOO` instead of `FOO`.

This is an annoying footgun that is pretty much never intended, especially since most other directives *do* trim whitespace. So let's get rid of it by trimming the environment variable name.

Values remain untrimmed, since there could conceivably be a use-case for values with leading space, but perhaps we'll end up trimming values too in the future.

Recently observed in rust-lang#138603 (comment).

Fixes rust-lang#132990.
Supersedes rust-lang#133148.

r? jieyouxu
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 8, 2025
compiletest: Trim whitespace from environment variable names

When a test contains a directive like `//@ exec-env: FOO=bar`, compiletest currently includes that leading space in the name of the environment variable, so it is defined as ` FOO` instead of `FOO`.

This is an annoying footgun that is pretty much never intended, especially since most other directives *do* trim whitespace. So let's get rid of it by trimming the environment variable name.

Values remain untrimmed, since there could conceivably be a use-case for values with leading space, but perhaps we'll end up trimming values too in the future.

Recently observed in rust-lang#138603 (comment).

Fixes rust-lang#132990.
Supersedes rust-lang#133148.

---

try-job: test-various
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 10, 2025
compiletest: Trim whitespace from environment variable names

When a test contains a directive like `//@ exec-env: FOO=bar`, compiletest currently includes that leading space in the name of the environment variable, so it is defined as ` FOO` instead of `FOO`.

This is an annoying footgun that is pretty much never intended, especially since most other directives *do* trim whitespace. So let's get rid of it by trimming the environment variable name.

Values remain untrimmed, since there could conceivably be a use-case for values with leading space, but perhaps we'll end up trimming values too in the future.

Recently observed in rust-lang#138603 (comment).

Fixes rust-lang#132990.
Supersedes rust-lang#133148.

---

try-job: test-various
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 10, 2025
compiletest: Trim whitespace from environment variable names

When a test contains a directive like `//@ exec-env: FOO=bar`, compiletest currently includes that leading space in the name of the environment variable, so it is defined as ` FOO` instead of `FOO`.

This is an annoying footgun that is pretty much never intended, especially since most other directives *do* trim whitespace. So let's get rid of it by trimming the environment variable name.

Values remain untrimmed, since there could conceivably be a use-case for values with leading space, but perhaps we'll end up trimming values too in the future.

Recently observed in rust-lang#138603 (comment).

Fixes rust-lang#132990.
Supersedes rust-lang#133148.

---

try-job: test-various
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 10, 2025
compiletest: Trim whitespace from environment variable names

When a test contains a directive like `//@ exec-env: FOO=bar`, compiletest currently includes that leading space in the name of the environment variable, so it is defined as ` FOO` instead of `FOO`.

This is an annoying footgun that is pretty much never intended, especially since most other directives *do* trim whitespace. So let's get rid of it by trimming the environment variable name.

Values remain untrimmed, since there could conceivably be a use-case for values with leading space, but perhaps we'll end up trimming values too in the future.

Recently observed in rust-lang#138603 (comment).

Fixes rust-lang#132990.
Supersedes rust-lang#133148.

---

try-job: test-various
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 10, 2025
Rollup merge of rust-lang#139507 - Zalathar:trim-env-name, r=jieyouxu

compiletest: Trim whitespace from environment variable names

When a test contains a directive like `//@ exec-env: FOO=bar`, compiletest currently includes that leading space in the name of the environment variable, so it is defined as ` FOO` instead of `FOO`.

This is an annoying footgun that is pretty much never intended, especially since most other directives *do* trim whitespace. So let's get rid of it by trimming the environment variable name.

Values remain untrimmed, since there could conceivably be a use-case for values with leading space, but perhaps we'll end up trimming values too in the future.

Recently observed in rust-lang#138603 (comment).

Fixes rust-lang#132990.
Supersedes rust-lang#133148.

---

try-job: test-various
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants