Commit graph

37 commits

Author SHA1 Message Date
Danil Hendra Suryawan a9c47cc3ab feat(cli): emit error when add is given a toolchain name instead of a crate name 2023-06-03 20:50:24 +07:00
bors 8f49b5556b Auto merge of #12191 - epage:mut, r=weihanglo
fix(add): Reduce the chance we re-format the user's `[features]` table

### What does this PR try to resolve?

#11743 pointed out that we re-format the users `[features]` table when running `cargo add`  which was a bug introduced in #11099.

This reduces the chance people will run into this problem
- Reducing the scope of the `fmt` call
- Preserving formatting in a simple case

Actually removing the `fmt` case can make some common formatting cases more complex to do "right", so I'm punting on that for now.

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

Look at the individual commits as I show how each change improves the behavior of `cargo add`.
2023-05-27 10:33:39 +00:00
Ed Page 0da6997ccc test(add): Remove expensive test
This is a carry-over from cargo-edit where we had to worry about the UX
of all of the behavior while now we are just relying on built-in cargo
behavior and don't need to test it specifically for `cargo add`.

On my machine, this test takes 11s.
2023-05-26 19:24:13 -05:00
Ed Page dbf9134d57 fix(add): Preserve formatting 2023-05-26 16:49:59 -05:00
Ed Page 6d8f35f729 fix(add): Reduce the chance of breaking the user's formatting 2023-05-26 16:49:59 -05:00
Ed Page b903527f28 test(add): Show features table fmt bug 2023-05-26 16:49:14 -05:00
Ed Page 29dc47fa9a refactor(tests): Reduce cargo-add setup load
This just gets rid of irrelevant packages in the registry.  Looking into
which versions aren't needed would require a deeper pass, so I held off
on that for now.

Before, the tests were in the 300-500ms range and now they take
100-300ms.

This did call to my attention that `unrelated` is misspelled as
`unrelateed` but holding off on fixing that to reduce conflicts.
2023-05-26 09:24:45 -05:00
cassaundra 30a445b9a4
Add tests for cargo add's rust-version behavior 2023-05-23 11:06:08 -07:00
hi-rustin e0276cae19 Update error message to not start with capital letters
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-04-20 09:16:45 +08:00
hi-rustin 4d401bd0b9 Add test for empty dep table error
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-04-20 08:49:30 +08:00
Ed Page 6feea34f8a chore: Upgrade to clap v4.2
Tests in `master` are currently failing because its building with clap
v4.2 but the tests have snapshots from v4.1
2023-03-28 05:00:49 -05:00
jofas feef14e9d7 breaking endless loop on cyclic features in cargo-add 2023-03-06 13:04:38 +01:00
Scott Schafer 08c6bb8446 refactor: Rename test names to case for cargo_add 2023-02-20 11:25:14 -06:00
Ed Page 6007f05a85 chore: Update to toml v0.6, toml_edit v0.18
`toml` replaces `toml_edit::easy`, using `toml_edit` as its parser.
2023-01-19 15:26:28 -06:00
bors 04519ad831 Auto merge of #11612 - hi-rustin:rustin-patch-cargo-add, r=epage
`cargo add` check `[dependencies]` order without considering the dotted item

### What does this PR try to resolve?

Try to close https://github.com/rust-lang/cargo/issues/11584

`cargo check` check `[dependencies]` order without considering the dotted item.

### How should we test and review this PR?
See the unit test.
2023-01-25 15:44:23 +00:00
Ed Page 8fb9effcae test: Update for clap 4.1.3
The latest clap release fixed a bug with the algorithm for providing
suggestions, leading this suggestion to change.
2023-01-23 21:19:48 -06:00
hi-rustin ea5ade3426 cargo check check [dependencies] order without considering the dotted item
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-01-22 22:55:07 +08:00
Weihang Lo c51c6bb6ac
chore: reflect to clap updates 2023-01-14 09:23:39 +00:00
Philpax 249683b456
fix(tests): update to match add change 2022-12-15 09:34:23 +01:00
hi-rustin 6b24d5c761 Rename infer_package to infer_package_for_git_source
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-10-10 22:19:32 +08:00
hi-rustin 6ae292100b Update cargo add test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-10-07 19:00:14 +08:00
Ed Page 96948f7a24 refactor(cli): Upgrade to clap v4 2022-09-28 13:32:14 -05:00
Emil Gardström 1cc21b65d1
make unknown features on cargo add more discoverable 2022-09-21 08:07:16 +02:00
Ed Page be257b8b25 fix(add): Remove redundant version in build metadata cases 2022-09-12 09:51:38 -05:00
Ed Page 7ce2b7d42a fix(add): Limit 'Features as of vX.Y.Z' to when relevant
This will only show the messaeg if we didn't already show a version req
with full precision specified ... mostly.  We'll also skip it if its a
local or git dependency but we never show the version in those cases
because it doesn't matter.

The `precise_version` logic came from cargo-upgrade.
2022-09-12 09:46:22 -05:00
Ed Page 73906aeaf8 fix(add): Clarify which version the features are added for
This gives a hint to users that we might not be showing the feature list
for the latest version but the earliest version.

Also when using a workspace dependency or re-using an existing
dependency, this is a good reminder of what the version requirement is
that was selected.

However, when the user or add (the common case) selected a full
precision requirement, this is redundant.

I'm also mixed on whether the meta version should show up.

Fixes #11073
2022-09-12 09:39:47 -05:00
Ed Page 5789c12e45 fix(add): Update the lock file
This is done in the command, rather than in the op,
- To consistently construct the `Workspace`
- It is more composable as an API

A downside is we update the git dependencies a second time.

We are not rolling back on error.
- For some errors, the user might want to debug what went wrong
- Rollback adds its own complications and risks, including since its
  non-atomic

Fixes #10901
2022-07-26 14:59:07 -05:00
Ed Page 323c7bc306 test(add): Make test data valid
Resolving the manifests will fail due to inconsistencies.  This
addresses those.
2022-07-25 11:06:12 -05:00
Ed Page b5c4a765ef fix(add): Respect --locked
This is prep for #10901 to avoid the most common failure case for the
lock file.  We are assuming if the users action caused a change in the
manifes, then it will cause a change in the lock file.  This isn't
entirely true but close enough and I think these semantics can make
sense.
2022-07-25 09:52:00 -05:00
Scott Schafer 2c810afda9 Stabilize workspace inheritance 2022-07-23 09:36:49 -05:00
Scott Schafer c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05:00
Ed Page b78f91831e test(add): Ensure comments are preserved
A comment on killercup/cargo-edit#15 had me worried that `cargo add` was
deleting comments now.  It appears that isn't the case for inline
tables.

Standard tables however do delete comments.  The work to make sure they
don't conflicts with another need.  When changing the source, we delete
the old source fields and append the new which can cause some formatting
to be carried over unnecessarily.

For example, what would normally look like
```toml
cargo-list-test-fixture-dependency = { optional = true, path = "../dependency", version = "0.0.0" }
```
When fixed to preserve comments with my naive solution looks like
```toml
cargo-list-test-fixture-dependency = { optional = true , path = "../dependency", version = "0.0.0" }
```
Note that `optional = true` used to be last, so space separating it and
`}` was kept, now separating it and `,`.

More work will be needed to get this into an ideal state but we can at
least have confidence with inline tables for now.
2022-07-13 13:38:10 -05:00
Ed Page 18f7dfe0f5 fix(add): Don't panic with --offline
For some reason, I defined my own `--offline` flag and it didn't get
updated with the global `--offline` flag, so it started failing.

Fixes #10814
2022-07-02 23:04:00 -05:00
Ed Page cbd4edb266 refactor(test): Clarify asserts are for UI
In writing the contrib documentation for functional vs ui tests, I
realized that as we work to make snapbox work for the functional tests,
we'll need distinct `Assert` objects since we'll want to elide a lot
more content in functional tests.  I'm making room for this by
qualifying the existing asserts as being for "ui".
2022-06-21 14:59:54 -05:00
Ed Page 6f475f090e chore: Upgrade to clap 3.2 2022-06-13 10:02:23 -05:00
Scott Schafer 92fbc4e344 move all snapshot/cargo_add/ tests to testsuite/cargo_add/ 2022-05-06 20:51:29 -05:00
Scott Schafer ea312988fb move a snapshot/add/ test into testsuite/cargo_add directory 2022-05-06 10:31:58 -05:00