Commit graph

3483 commits

Author SHA1 Message Date
Ed Page 10196aaee3 test(resolver): Demonstrate existing behavior 2023-08-25 09:59:16 -05:00
bors f797978283 Auto merge of #12553 - epage:version, r=weihanglo
refactor: Pull out cargo-add MSRV code for reuse

### What does this PR try to resolve?

#12078 added MSRV code in `cargo add`. Our assumption when writing it is that we'd need to generalize the code before reusing it in other places, like `cargo install`.  This PR focused purely on that refactor because I'm hopeful it will be useful for other work I'm doing.  Despite not having a user for this yet, I think the `cargo install` case is inevitable and I feel this does a bit to clean up MSRV related code by using a more specific type everywhere.

### How should we test and review this PR?

Each commit gradually progresses things along
2023-08-25 14:56:24 +00:00
Deadbeef 43dccc7535 apply suggestions 2023-08-25 01:43:29 +00:00
Deadbeef b2b34e4ca2 update tests 2023-08-25 01:43:29 +00:00
Ed Page 1701b4e3d8 fix(manifest): Improve rust-version error messages
Since we have tests for a couple of cases, I figured we could
improve the error messages for them.
2023-08-24 20:29:14 -05:00
bors b2c162c067 Auto merge of #12556 - epage:serde, r=arlosi
fix(toml): Improve parse errors

### What does this PR try to resolve?

When we adopted `toml_edit`, we got TOML syntax errors that showed the context for where the error occurred.  However, the work was not done to extend this to semantic errors reported by serde.

This updates `Cargo.toml` and `Cargo.lock` code to provide that context on semantic errors.  `config.toml` is not done because the schema is decentralized.

In theory, this will also improve performance because we aren't having to allocate a lot of intermediate data to then throw away for every `Cargo.toml` we read.

### How should we test and review this PR?

Check by commit to see this change gradually.
- The `package.cargo-features` change was made to drop out dependence on `toml::Table` so we could do the direct deserialization
2023-08-24 23:01:52 +00:00
bors 3b20907926 Auto merge of #12551 - arlosi:asymmetric-token, r=Eh2406
Create dedicated unstable flag for asymmetric-token

Asymmetric tokens are gated by `-Zcredential-process`. Since we're considering stabilizing that soon, this moves asymmetric token support to have its own unstable flag.

It was previously gated by `-Zregistry-auth`, and some of the docs were not updated when it moved.

r? `@Eh2406`
2023-08-24 22:07:16 +00:00
Ed Page 53dcd2f454 fix(manifest): Provide more context on sematic errors 2023-08-24 16:27:53 -05:00
Ed Page 8927ea99d1 refactor(manifest): Process the package.cargo-features error in serde 2023-08-24 16:27:45 -05:00
Ed Page 511c17c961 fix(lock): Render source for serde errors
Before, we'd render the source for TOML syntax errors but not semantic errors.
Now we render for both.

Originally I changed `parse_document` to returned `T: DeserializeOwned`
but that adds an extra "could not parse TOML" which is both redundant
and makes it sound like its a syntax issue.
2023-08-24 16:27:37 -05:00
Ed Page 5cac7aa8c6 fix(toml): Remove redundant error messages 2023-08-24 16:19:48 -05:00
Ed Page 423a334520 refactor: Parse, don't validate, rust_version
By using the `PartialVersion` type with serde, we get the context for
the error automatically.
2023-08-24 14:15:35 -05:00
Arlo Siemsen 8c13e9ae3f Create dedicated unstable flag for asymmetric-token 2023-08-24 00:12:50 -05:00
Ed Page 937932520b refactor(install): Move version parsing to the CLI 2023-08-23 16:22:31 -05:00
Ed Page 28b7c846af refactor(install): Shift crate argument parsing to clap 2023-08-23 15:25:05 -05:00
bors 2cc50bc0b6 Auto merge of #12515 - arlosi:high-pri-last, r=weihanglo
config: merge lists in precedence order

When merging configuration lists, the current order does not match the expected precedence. This makes merged lists follow precedence order, with higher precedence items merged later in lists.

When a list in configuration exists in multiple places, Cargo merges the lists together. The ordering of this merging is unexpected and does not follow the precedence rules that non-list configuration uses.

The current merging order appears to be:
* project-specific `config.toml`
* global `config.toml`
* command-line (`--config`)
* environment variable (`CARGO_*`)

This PR changes the order to follow the precedence rules with higher precedence configuration merging later in the lists.
* global `config.toml`
* project-specific `config.toml`
* environment variable (`CARGO_*`)
* command-line (`--config`)

This aligns with config such as `build.rustflags` where later flags take precedence over earlier ones.

Since `--config` is relatively new, it's unlikely to cause too much breakage by making it come after environment variables.

Switching global and project-specific ordering is more likely to cause breakage, since it's been around longer (reported as an issue in #8128). Projects relying on global configuration flags (in `$CARGO_HOME\config.toml` or in `.cargo/config.toml` further from the project) being merged first in lists will be broken.

For most uses of merged lists (such as `build.rustflags`), if the flags do not conflict with each other, there will be no impact.

Fixes #12506
Fixes #8128
2023-08-22 22:43:08 +00:00
Weihang Lo 77da514529
test: move --keep-going suggestion match tests to UI tests
We don't want to overly match to suggestion help from clap.
2023-08-22 19:21:09 +01:00
Weihang Lo 4d0958587b
refactor(arg): use UnknownArgumentValueParser to suggest arg for unknown args 2023-08-22 17:24:40 +01:00
Arlo Siemsen 687ace1ddc Merge higher precedence config lists later
When merging configuration lists, the current order does not match
the expected precedence. This makes merged lists follow precedence
order, with higher precedence items merged later in lists.
2023-08-16 11:21:38 -05:00
bors 7c3904d6c3 Auto merge of #12501 - epage:rustdoc, r=weihanglo
fix(lints): Doctest extraction should respect `[lints]`

Note the first commit shows the bug and the second commit fixes it

Fixes #12497
2023-08-14 20:11:43 +00:00
Ed Page 9984855904 fix(lints): Doctest extraction should respect [lints]
Fixes #12497
2023-08-14 14:23:59 -05:00
Ed Page a80dfae761 test(lints): Demo doctest bug 2023-08-14 14:21:25 -05:00
Weihang Lo 689defd4ba
test: relax assertions of panic message (again) 2023-08-14 19:32:39 +01:00
Weihang Lo b567a67d5c
test: bypass rustc --test impl details for -Zfuture-incompat-test
Switch to an empty `lib.rs` from `main.rs`.

See https://github.com/rust-lang/rust/issues/114804#issuecomment-1677233355
2023-08-14 13:40:47 +01:00
Weihang Lo 5ae529b24e
feat: remove --keep-going from cargo test/bench
It confuses people that both `--no-fail-fast` and `--keep-going` exist
on `cargo test` and `cargo bench` but with slightly different behavior.
The intended use cases for `--keep-going` involve build commands like
`build`/`check`/`clippy` but never `test`/`bench`.

Hence, this commit removes `--keep-going` from `test`/`bench` and
provides guidance of `--no-fail-fast` instead.

If people really want to build as many tests as possible, they can also
do it in two steps:

    cargo build --tests --keep-going
    cargo test --test --no-fail-fast
2023-08-11 14:29:02 +01:00
bors 7da103076e Auto merge of #12463 - stupendoussuperpowers:nocapture_test_msg, r=epage
prompt the use of `--nocapture` flag if `cargo test` process is terminated via a signal.

Fixes #10855

As per the discussion on this issue, we want to prompt the user to use `--nocapture` if a test is terminated abnormally. The motivation for this change is described in the issue.

We check for 3 things before we display this flag. -
- `!is_simple` (if the test ended with a non 101 status code)
- `harness` (if the standard test harness was used), and
- `!nocapture` (whether or not the `--nocapture` flag was already passed to the test)

There's further tests added to `test::nonzero_exit_status` that check that the `stderr` is correct for the various combinations possible when a test ends with a non-101 status code.

The new expected behavior is -
- Display `--nocapture` note for only non-zero exit statuses, when the `--nocapture` flag is not passed.
- Only display the note if we use a standard test harness since custom test harnesses do not implement the `--nocapture` flag.

To implement the check for the `--nocapture` flag, the function definition for `report_test_errors` was changed to add the `test_args: &[&str]` parameter. This parameter is passed from the immediate calling function. This private function is only called twice change and is not causing regression after making the appropriate changes to both the places it's called in.
2023-08-10 21:20:25 +00:00
bors af431e1bb7 Auto merge of #12454 - alcolmenar:alcolmenar/fix-invalid-rm, r=epage
Fix cargo remove incorrectly removing used patches

### What does this PR try to resolve?

Fixes an issue where patches are being removed when member dependencies don't explicitly contain the patched crate.

Fixes #12419

### How should we test and review this PR?

- Created a test for the failing use case
- Verify passing test

<!--
### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.

-->
2023-08-10 18:00:32 +00:00
alcolmenar 72e66fb645
fix: add quiet verbosity around resolve and fix tests 2023-08-10 09:51:36 -07:00
alcolmenar a64ed3976f
fix: add gc unused patches logic and fix tests 2023-08-10 07:27:36 -07:00
alcolmenar 7ad774a3ff
chore: add passing test 2023-08-10 07:27:24 -07:00
alcolmenar dde256fb93
fix: ensure patches are different dependencies to enable unused 2023-08-09 13:09:41 -07:00
sanchit dd8cd9c9a9 add nocapture message to report_test_err 2023-08-10 01:16:27 +05:30
sanchit dde17cf0cf add --nocapture tests 2023-08-10 01:16:00 +05:30
bors 2b3554f773 Auto merge of #11905 - epage:help_heading, r=weihanglo
fix(cli): Make `--help` easier to browse

This mirrors some of the categories from `cargo help` (the man pages) using [`clap::Arg::help_heading`](https://docs.rs/clap/latest/clap/struct.Arg.html#method.help_heading).
There are fewer categories to avoid extra vertical space.  Instead, they
are left int the `Options` category but put first.

The goal is to try to make it easier to scan `--help` output as the list of flags can get quite long and its easy to miss what features are there.
2023-08-08 20:35:52 +00:00
Ed Page 853102f7de fix(cli): Make --help easier to browse
This mirrors some of the categories from `cargo help` (the man pages).
There are fewer categories to avoid extra vertical space.  Instead, they
are left int the `Options` category but put first.
2023-08-08 13:50:05 -05:00
bors d432dec355 Auto merge of #12332 - hi-rustin:rustin-patch-syntax, r=arlosi
Bail out an error when using cargo:: in custom build script
2023-08-07 16:58:15 +00:00
bors abc115972e Auto merge of #12439 - arlosi:registry-multiple-warning, r=ehuss
Fix printing multiple warning messages for unused fields in [registries] table

Cargo currently prints the same warning message multiple times for unexpected fields in the `[registries.<registry>]` or `[registry]` tables. This is because Cargo warns each time that the structure is deserialized from `Config`. Depending on which code path is taken I've seen the warning printed up to 6 times.

* A cache of deserialized registry configurations is added to the `Config` struct.
* Registry authentication is changed to directly read the config when searching for a registry name, rather than deserializing each registry configuration.

A test is added to ensure both `[registries]` and `[registry]` only warn once for unexpected fields.
2023-08-06 18:29:22 +00:00
Eric Huss 1df0f1d734 Add allow(internal_features) 2023-08-05 12:11:07 -07:00
Weihang Lo c60c06585c
fix: clear cache for old .cargo-ok format
In 1.71, `.cargo-ok` changed to contain a JSON `{ v: 1 }` to indicate
the version of it. A failure of parsing will result in a heavy-hammer
approach that unpacks the `.crate` file again. This is in response to a
security issue that the unpacking didn't respect umask on Unix systems.
2023-08-03 13:42:54 +01:00
Weihang Lo 4fafa69a4d
fix: respect umask when unpacking .crate files
Without this, an attacker can leverage globally writable files buried
in the `.crate` file. After a user downloaded and unpacked the file,
the attacker can then write malicous code to the downloaded sources.
2023-08-03 13:41:08 +01:00
Weihang Lo 789a2fb4bf
test: verify permissions bits are preserved when unpacking
This is not secure and will be fixed in the next commit.
2023-08-03 13:39:48 +01:00
Arlo Siemsen 65ec65fe1e Fix printing multiple warning messages for unused fields in [registries] table 2023-08-02 18:20:46 -05:00
bors 6dc1deaddf Auto merge of #12429 - Nilstrieb:we-love-internal-features, r=weihanglo
`#[allow(internal_features)]` in RUSTC_BOOTSTRAP test

This will be required in the future (where "the future" is rust-lang/rust#108955 which fails CI because of cargo here).

This does emit the unknown lints lint right now but that doesn't matter as it's just warn-by-default - internal_features is deny-by-default though, so it causes errors.
2023-08-02 00:23:54 +00:00
Nilstrieb b2720536b0 #[allow(internal_features)] in RUSTC_BOOTSTRAP test
This will be required in the future (where "the future" is my PR
which fails CI because of cargo here).
2023-08-01 18:18:29 +02:00
bors baebd2bfb6 Auto merge of #12428 - epage:update, r=weihanglo
fix(update): Tweak CLI behavior

### What does this PR try to resolve?

When looking at `cargo update` for #12425, I noticed that the two flags related to `--package` were not next to it or each other.  I figured grouping them like that would make things easier to browse.

When looking into that, I noticed that the two flags conflict and figured we'd provide a better error message if we did that through clap.

### How should we test and review this PR?

Looking per commit will help show the behavior changes.

### Additional information

I wanted to scope this to being simple, non-controversial, low effort, incremental improvements with this change so I did not look into the history of `--aggressive` not requiring  `--package` like `--precise` does and figure out if there is any consistency we can be working towards.
2023-08-01 15:20:25 +00:00
Ed Page 4fd0c3c46c fix(update): Group -p related flags 2023-07-31 21:21:02 -05:00
Ed Page 57762917fb fix(update): Perform error check in clap 2023-07-31 21:18:31 -05:00
Ed Page e290ed7a02 test(update): Add a --aggressive --precise error test 2023-07-31 21:16:54 -05:00
bors 29a6f2fab2 Auto merge of #12424 - arlosi:credential-thiserror, r=arlosi
Use thiserror for credential provider errors

### What does this PR try to resolve?
Errors from credential providers currently must a single string. This leads to a lot of `.map_err(|e|cargo_credential::Error::Other(e.to_string())`, which loses the `source()` of these errors.

This changes the `cargo_credential::Error` to use `thiserror` and adds a custom serialization for `std::error::Error` that preserves the source error chain across serialization / deserialization.

A unit test is added to verify serialization / deserialization.
2023-07-31 22:00:41 +00:00
Predrag Gruevski 2f59b20df6 Mention that cargo test --all-targets excludes doctests
Per my proposal here: https://github.com/rust-lang/cargo/issues/6669#issuecomment-1658593167

I tried to keep the edit minimalistic to match the surrounding style.

If the maintainers are amenable to it, I think it could also be useful to do one or more of:
- Offer concrete guidance on what to do to run actually-all tests (`--all-targets` then separately `--doc`).
- Link to the issue at: https://github.com/rust-lang/cargo/issues/6669
- Mention that `cargo test` without `--all-targets` runs doctests by default, which seems not immediately obvious.

I'd be happy to attempt to add any of the above that the maintainers feel would be a good fit here.
2023-07-31 20:09:24 +00:00