93 Commits

Author SHA1 Message Date
Ross Sullivan
30b6707135
chore: Moved remaining cargo_exe logic to testsuite 2025-06-25 23:18:08 +09:00
Ross Sullivan
92d9a94d02
chore: Migrated testsuite to testsuite::prelude 2025-06-25 22:37:24 +09:00
Ross Sullivan
47312c446d
chore: Moved tools and some cross compiling logic into testsuite 2025-06-24 23:51:39 +09:00
Chris Denton
d82b596962
Don't canonicalize in cargo_exe 2025-03-26 23:47:08 +00:00
Weihang Lo
21af60a6a8
test: redact host target when comparing CARGO_ENV path
This was found when updating git submodule in rust-lang/rust

```
---- cargo_command::overwrite_cargo_environment_variable stdout ----
running `/projects/rust/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/cargo run`

thread 'cargo_command::overwrite_cargo_environment_variable' panicked at src/tools/cargo/tests/testsuite/cargo_command.rs:636:58:

test failed running `/projects/rust/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/cargo run`
error: expected to find:
/projects/rust/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/cargo

did not find in output:
[COMPILING] foo v1.0.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo`
```
2025-03-07 19:34:41 -05:00
Samuel Moelius
a6fdc01cea Move test to cargo_command.rs 2025-02-23 17:37:39 -05:00
Samuel Moelius
44970a825d Fix #15099
Overwrite `$CARGO` when the current exe is detected to be a cargo
binary.

See: https://github.com/rust-lang/cargo/issues/15099#issuecomment-2666737150
2025-02-21 15:33:20 -05:00
Ed Page
e78a8a19db fix: Align new help messages with their error 2025-02-04 10:46:09 -06:00
Ed Page
5408bd9f52 fix: Update generic 'did you meann' reports to not say that 2025-02-03 13:07:47 -06:00
Ed Page
759178e42b fix(cli): Don't use 'did you mean' for +toolchain errors 2025-02-03 10:37:53 -06:00
Ed Page
55350fc670 test: Switch from 'exec_with_output' to 'run'
This is a follow up to #14846 which changed `run` to return the
`RawOutput`.

Reasons I didn't "update" some code to the new `run` return value
- We were actually using `ProcessBuilder::exec_with_output` and I didn't
  want to disentangle what it would take to switch to `Execs`
- We did processing on the `Result` and I didn't want to check how that
  could be updated
2024-11-21 13:48:27 -06:00
Ed Page
af3cfd5abe fix(test): Un-deprecate contains assertions 2024-11-07 15:55:35 -06:00
Weihang Lo
886e55b572
fix: make deprecated cmds more obvious in help and --list 2024-10-28 14:19:22 -04:00
Ed Page
e72ef0b10f test: Migrate remaining with_stdout/with_stderr calls 2024-09-23 20:44:14 -05:00
Ed Page
a6cf1be655 test: Switch from allow to expect deprecated
This caught a couple of lingering items.
2024-09-23 20:44:06 -05:00
Ed Page
3a615ca9c8 feat(test): Add CargoPathExt to prelude 2024-07-18 15:22:29 -05:00
Ed Page
5b9799c6f4 refactor: Migrate from extern crate to test-support prelude
We now include the prelude in so many places, this simplifies how we can
present how `cargo-test-support` works.

Yes, this included some `use` clean ups but its already painful enough
walking through every test file, I didn't want to do it twice.
2024-07-12 15:57:00 -05:00
Ed Page
42eb88395f test: Ensure --list test works with cargo-bloat
This is a follow up to #14113
2024-07-08 16:46:16 -05:00
heisen-li
a32be92404 test: migrate cargo_command to snapbox 2024-07-03 10:17:04 +08:00
Ed Page
dc5ac62cab fix(test): Deprecate non-snapbox assertions
While this is noisy and hides other deprecations, I figured deprecations would
make it easier for people to discover what tasks remain and allow us to
divide and conquer this work rather than doing a heroic PR.
In theory, this will be short lived and we'll go back to seeing
deprecations in our tests.
2024-06-10 10:20:52 -05:00
Ed Page
ec3ed20d2a fix(cli): Suggest cargo-search on bad commands
This is a low-tech solution alternative to the options proposed in #4682
- Search `[[bin]]`s within all packages in the registry (which aren't
  tracked atm), suggesting to `cargo install` what is found
- Check if `cargo-<cmd>` is in the registry, suggesting `cargo install
  if it is

By suggesting `cargo search`, we are giving them a tool so they can
verify if the package is what they want (a `cargo info` would help as a
next step).

Is is needed?
- New users might not know of `cargo search` but they can search on
  crates.io
- New users might not be aware of the `cargo-<cmd>` naming pattern

Seems like this can still offer some benefit

Fixes #4682
2023-10-17 14:46:30 -05:00
Kyle Matsuda
8353396132 add unit test for config and integration test with cargo --list 2023-03-09 16:54:01 -07:00
Scott Schafer
1744d35e80 chore: Remove unneeded #[test] 2023-02-20 11:09:05 -06:00
Ed Page
ed8b85f10e chore: Fix typos 2023-01-10 20:03:11 -06:00
Jon Gjengset
724a1977ce Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.

This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.

One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.

Fixes #10119.
Fixes #10113.
2022-10-25 13:51:27 -07:00
Ed Page
96948f7a24 refactor(cli): Upgrade to clap v4 2022-09-28 13:32:14 -05:00
Dawid Ciężarkiewicz
c712f08862 Do not add home bin path to PATH if it's already there
This is to allow users to control the order via PATH if they so desire.

Fix #11020
2022-09-08 09:37:41 -07:00
akabinds
222d90b78e test checking full stderr output, with new message, resulting from a "did you mean" 2022-08-03 11:38:41 -05:00
akabinds
8f5f2ed2a2 implement test checking if stderr, after using +toolchain, contains message stating that the directive is not handled by Cargo 2022-08-03 11:07:17 -05:00
akabinds
5f3ded124f stop mixing of newlines and \n in tests 2022-08-02 19:43:16 -05:00
akabinds
42df87409b fix formatting 2022-08-02 18:27:36 -05:00
akabinds
b2f44de83d implemented requested changes; tests pass 2022-08-02 18:23:55 -05:00
akabinds
b55e8d47a9 implemented requested changes; fixed one failing test (need to fix other) 2022-08-02 13:01:32 -05:00
cuishuang
6f13c466d2 fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-05-08 01:07:28 +08:00
Midas Lambrichts
42528799e2 Make levenshtein distance case insensitive.
When typing in a single character shortcut as a capital, it always
returns `b` as the suggestion as every one-letter abbreviation
is a lev distance 1 away from the capitalized one.
By making the levenshtein distance case insensitive, the case-mismatched
one-letter abbriviation (e.g. `C` to `c`) will be suggested, rather
than `b`
2021-12-21 12:56:28 +01:00
Eric Huss
910569aac3 Explicitly mark aliases in cargo list. 2021-12-06 14:02:21 -08:00
Nipunn Koorapati
1edd8630c9 Show desc of well known subcommands (fmt, clippy) in cargo --list 2021-08-27 12:28:30 -07:00
Nipunn Koorapati
5a56cf2e5b Refactor echo cargo subcommand test helper into cargo-test-support 2021-08-14 22:37:54 -07:00
Nipunn Koorapati
0ab79d7aaf Deduplicate entries in cargo --list
Fixes #6088
2021-08-09 10:29:21 -07:00
Dustin J. Mitchell
1c5e68b4f3 Include aliases with other commands
The principal result is that they are now automatically included in the
`cargo --list` output.  Fixes #8486.
2021-08-07 13:52:12 +00:00
Nipunn Koorapati
dde290e6ff Refactor fake_file() away from cargo_command tests
There are already similar preexisting test helpers which
also work on windows. Port over the executable-creation
helper into the file() helper and things appear to pass.
2021-08-05 19:09:58 -07:00
Eric Huss
aea5ca3ca0 Remove the double-backslash escape for matching.
Using `with_json` is safer since it knows what JSON escaping is.
2021-06-16 09:44:29 -07:00
Jade
b09988649a Restore the tests that could be reused 2021-03-22 13:39:18 -07:00
lf-
47347de87e Delete redundant broken tests 2021-03-22 13:39:18 -07:00
bjorn3
f5a3d55983 Fix warnings of the new non_fmt_panic lint 2021-02-06 19:10:42 +01:00
Eric Huss
6f8c7d5a87 Normalize raw string indentation. 2020-09-26 17:59:58 -07:00
Eric Huss
9138d65e4c Create a dedicated module for help tests. 2020-08-03 12:17:58 -07:00
CPerezz
7b16c7c130 Add test for listing builtin aliases
Added a test that checks that the aliases that currently
are builtin with cargo are indeed being printed with the rest
of the commands when `cargo --list` is called.

Closes #8486
2020-07-24 23:40:49 +02:00
Eric Huss
7274307af4 Ignore broken console output in some situations. 2020-05-13 16:22:24 -07:00
Eric Huss
4ae79d2ffd Use fs helpers instead of File functions. 2020-04-17 07:56:16 -07:00