159 Commits

Author SHA1 Message Date
Weihang Lo
973f7410a8
test(build-analysis): feature gate tests 2025-08-16 08:28:37 -04:00
Josh Triplett
a206766e43 Add initial version of hints tests, to show pre-[hints] Cargo behavior
These tests show what prior versions of Cargo will do with hints.
The subsequent addition of support for hints will modify these tests to
reflect the corresponding changes to Cargo.
2025-07-11 16:54:30 -07:00
Ross Sullivan
30b6707135
chore: Moved remaining cargo_exe logic to testsuite 2025-06-25 23:18:08 +09:00
Ross Sullivan
15f755cefd
chore: Created CargoProjectExt extention trait 2025-06-25 23:18:00 +09:00
Ross Sullivan
66fc1055a7
chore: Created testsuite prelude 2025-06-25 22:29:12 +09:00
Ross Sullivan
47312c446d
chore: Moved tools and some cross compiling logic into testsuite 2025-06-24 23:51:39 +09:00
Naman Garg
db8dbaf3ed
Add initial tests for multiple build scripts (not implemented yet) 2025-06-23 19:14:36 +05:30
Shoyu Vanilla
d253d12122 test(compile-time-deps): Add tests for --compile-time-deps 2025-06-19 09:09:32 +09:00
Weihang Lo
781c7ed515
feat(package): add unstable --message-format flag
The behavior is not implemented yet
2025-03-25 23:02:37 -04:00
Ed Page
e2a991caf3 test(tree): Group all cargo-tree tests 2025-02-28 09:18:07 -06:00
Arlo Siemsen
5f833db69b feat: Add SBOM pre-cursor files
Adds a new option `build.sbom` that adds generation of a JSON file
containing dependency information alongside compiled artifacts.
2025-02-26 14:57:14 -06:00
Ross Sullivan
4ce639da9f
Added target-dir tests
These ares are in preparation to split target-dir into artifact-dir and build-dir
2025-02-24 18:19:49 +09:00
Andrew Liu
91e83d70ed test: verify feature unification behavior in workspaces 2025-02-11 12:15:12 +09:00
Weihang Lo
02e25d5608
test(pgo): ensure PGO works
This is a regression test to prevent issues like #7416.

The test only run on Linux,
as other platforms have different requirements for PGO,
or emit different PGO function missing warnings.
2024-11-26 10:20:53 -05:00
Arlo Siemsen
cfa1873d4e Add tests that show existing behavior 2024-11-08 15:27:30 -06:00
Jacob Kiesel
f4ca739073
implement checksum freshness fingerprints for cargo 2024-10-08 16:29:44 -04:00
Ed Page
023f4c66ca test: Remove completion tests
The tests are intended to spot check that shell completions are
registered correctly.  That is a low change, low risk area.  For shell
integration, we're relying on `clap_complete`s tests.
For our own candidates, we should test the candidate generation
directly, rather than end-to-end.

This reverts parts of commit e7ca9bec80ab5c010c1a84690816da7b64008257, reversing
changes made to bd5f32bb1c7ca273b5d86815bf0ae4adba59ddd8.

Fixes #14545
2024-09-24 08:58:57 -05:00
shannmu
f25806c472 test: Add test codebase for shell completions 2024-09-09 23:39:21 +08:00
bors
3293d22f00 Auto merge of #14326 - Ifropc:5707-lock-path, r=weihanglo
Add `--lockfile-path` flag

This change implements a new `--lockfile-path` proposed in #5707 .

Functionality added:
- Add `--lockfile-path <PATH>` to all commands that support `manifest-path` with exception of:
   - `locate-project` (doesn't use lock file)
   - `verify-project` (is deprecated)
   - `read-manifest` (doesn't use lock file)
- Behind -Zunstable-options and docs
   - The flag's docs / `--help` has (unstable) in them
- `<PATH>` must end with `Cargo.lock`. If specified path doesn't exist (or parent director(ies), create all the parent directories and the lockfile itself

Implementation TLDR: add `requested_lockfile_path` into `Workspace` and set it on `workspace(gctx)` call (setting from the context)
Update `lockfile.lock_root()` to respect `requested_lockfile_path` (if set)
Add test cases covering all affected commands. Tested creating lockfile, reading lockfile, overriding default (`./Cargo.lock`) lockfile, symlink tests. Extra tests for package to make sure pinned versions from path's lockfile are respected (i.e. double check correct lockfile is used)
I doubt this flag will be used for any command that's not read-only, but I tried to cover all the commands.
2024-08-16 14:38:39 +00:00
Rustin170506
9d164aa23e test: migrate all test from cargo-information 2024-08-10 14:10:59 +08:00
Ifropc
dc1519d0d7
feat: add new lockfile-path for metadata
- Also add necessary tests for the new flag
2024-07-17 04:56:51 -07: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
Joe Neeman
ba9dd1ea2e Adds tests for source overlays. 2024-06-10 18:32:22 -05:00
valadaptive
4b309bc47a Rename out-dir to artifact-dir
Per discussion in https://github.com/rust-lang/cargo/issues/6790. The
--out-dir CLI option and out-dir config option are often confused with
the OUT_DIR environment variable, when the two serve very different
purposes (the former tells Cargo where to copy build artifacts to,
whereas the OUT_DIR environment variable is set *by* Cargo to tell
build scripts where to place their generated intermediate artifacts).
Renaming the option to something less confusing is a prerequisite to
stabilizing it.
2024-06-07 03:01:26 -04:00
Scott Schafer
307c7f825c
feat: Add a basic linting system 2024-03-23 10:26:02 -06:00
Scott Schafer
31c3052524
refactor(testsuite): Rename lints to lints_table 2024-03-22 11:33:58 -06:00
Ed Page
489dde1114 test: Show open-namespaces behavior 2024-03-15 12:53:55 -05:00
Ed Page
f2a4a3e88b test(diagnostic): Show panic 2024-01-31 08:48:53 -06:00
Ethan Brierley
c8ec94c765 Introduce -Zprecise-pre-release unstable flag
This change introduces the feature but does not yet attempt an implementation.
The actual implementation will happen in future PRs

r? @epage
2024-01-14 18:52:33 +00:00
Eric Huss
8ffd9cd86f Add tests validating the sequence for cargo fix.
This adds a set of tests which validates various edge cases around how
`cargo fix` works in terms of calling `rustc` multiple times. This uses
a replacement of `rustc` so it doesn't depend on the behavior of rustc
itself which is not always stable.
2024-01-02 14:54:41 -08:00
Weihang Lo
7a4754a1d3
lint: allow print_stdout and print_stderr 2023-11-16 11:35:21 -05:00
Weihang Lo
870f9ea7b3
lint: allow disallow_methods 2023-11-16 11:35:21 -05:00
Weihang Lo
1539b3dfc1
lint: dogfood ourselves lints table in manifest
These lint rules are from src/lib.rs. We aim to remove
them in the source code once `Zlints` hit stable.
2023-11-16 11:35:21 -05:00
Eric Huss
da3ca05677 Add a global cache garbage collector.
This adds a garbage collector which will remove old files from cargo's
global cache.

A general overview of the changes here:

- `cargo::core::global_cache_tracker` contains the `GlobalCacheTracker`
  which handles the interface to a sqlite database which stores
  timestamps of the last time a file was used.
- `DeferredGlobalLastUse` is a type that implements an optimization for
  collecting last-use timestamps so that they can be flushed to disk all
  at once.
- `cargo::core::gc` contains the `Gc` type which is the interface for
  performing garbage collection. It coordinates with the
  `GlobalCacheTracker` for determining what to delete.
- Garbage collection can either be automatic or manual. The automatic
  garbage collection supports some config options for defining when
  it runs and how much it deletes.
- Manual garbage collection can be performed via options to `cargo
  clean`.
- `cargo clean` uses the new package cache locking system to coordinate
  access to the package cache to prevent interference with other cargo
  commands running concurrently.
2023-11-11 10:56:58 -08:00
Ed Page
c12c4c3f8d tests: Remove plugin tests
Compiler plugins were removed in rust-lang/rust#116412, so we don't need
these tests.

As for the `plugin` field on build-targets, it appears to be
[stable-but-deprecated](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-plugin-field),
so I left it alone
2023-11-06 09:55:31 -06:00
Weihang Lo
08c5e35f60
test(trim-paths): parsing in mainfest and config 2023-10-30 16:38:55 -04:00
Eric Huss
b4982adfd9 Add a new package cache locking system.
This introduces a new `CacheLocker` which manages locks on the package
cache. Instead of either being "locked" or "not locked", the new locker
supports multiple modes:

- Shared lock: Cargo can read from the package sources, along with any
  other cargos reading at the same time.
- Download exclusive lock: Only one cargo can perform downloads.
  Download locks do not interfere with Shared locks, since it is
  expected that downloading does not modify existing files (only adds
  new ones).
- Mutate exclusive lock: Only one cargo can have this lock, and it also
  prevents shared locks. This is so that the cargo can modify the
  package cache (such as deleting files) without breaking concurrent
  processes.
2023-10-08 14:16:51 -07:00
Ed Page
5101372312 test(cli): Track --help output
This makes it easier to evaluate the usability of PRs, like #11905
2023-07-24 17:12:20 -05:00
Ed Page
79469f3019 refactor(tests): Name init ui tests more consistently
Currently, the UI tests are
- `cargo add`
- `cargo new`
- `cargo remove`
- `init`

One of these is not like the others. This change renames `init` to
`cargo_init` to suggest it is the UI tests for the `cargo init` command,
rather than `init` functionality.
2023-07-24 13:39:37 -05:00
Ed Page
21736eda0c feat(cli): Interpret some subcommands as manifest-commands 2023-06-08 20:17:03 -05:00
hi-rustin
5265b1d0ec Add tests for inherit_workspace_package_table
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-05-23 10:36:08 +08:00
Ed Page
8de25292fd feat(lints): Parse [lints] table on nightly 2023-05-22 09:52:03 -05:00
Eric Huss
52317aa8f8 Add some tests for simulating behavior under rustup. 2023-05-03 13:45:54 -07:00
Sebastian Thiel
8b3508cad7
Move all tests for shallow fetching into their own module
Note that those which test both with and without shallow still go
into the shallow module.
2023-04-29 09:52:08 +02:00
Weihang Lo
f3778f9193
Revert "#11738" - Use test name for dir when running tests
This reverts commit 64b0e793cea8542b34504a881f9cfd9444ab5138, reversing
changes made to 958078633ee9ae1af053fbab32ac70ae475b0e7f.
2023-03-08 15:17:48 +00:00
bors
80f1a5d0f7 Auto merge of #11688 - epage:minimal, r=Eh2406
feat(resolver): `-Zdirect-minimal-versions`

This is an alternative to `-Zminimal-versions` as discussed in #5657.

Problems with `-Zminimal-versions` includes
- Requires the root most dependencies to verify it and we then percolate that up the stack.  This requires a massive level of cooperation to accomplish and so far there have been mixed results with it to the point that cargo's unstable
 documentation discourages its use.
- Users expect `cargo check -Zminimal-versions` to force resolving to minimal but it doesn't as the default maximal resolve is compatible and requires `cargo update -Zminimal-versions`
- Different compatible versions might be selected, breaking interop between crates, changing feature unification, and breaking `-sys` crates without bad `links`

`-Zdirect-minimal-versions` instead only applies this rule to your
direct dependencies, allowing anyone in the stack to immediately adopt
it, independent of everyone else.

Special notes
- Living up to the name and the existing design, this ignores yanked
  crates.  This makes sense for `^1.1` version requirements but might
  look weird for `^1.1.1` version requirements as it could select
  `1.1.2`.
- This will error if an indirect dependency requires a newer version.
  Your version requirement will need to capture what you use **and** all
  of you dependencies.  An alternative design would have tried to merge
  the result of minimum versions for direct dependencies and maximum
  versions for indirect dependencies.  This would have been complex and
  led to weird corner cases, making it harder to predict.  I also suspect
  the value gained would be relatively low as you can't verify that
  version requirement in any other way.
  - This also means discrepancies between `dependencies` and `dev-dependencies` are errors
  - The error could be improved to call out that this was from minimal
    versions but I felt getting this out now and starting to collect
    feedback was more important.

One advantage of this approach over `-Zminimal-versions` is that it removes most of the problems that [cargo-minimal-versions](https://github.com/taiki-e/cargo-minimal-versions) tried to workaround.

As for the implementation, this might not be the most elegant solution but it works and we can always iterate and improve on it in the future.
- We keep the state as a `bool` throughout but compensate for that by explicitly creating a variable to abstract away constants
- The name changes depending on the context, from `direct_minimal_version` when dealing with the unstable flag to `first_minimal_version` when the concept of "direct" is lost to `first_version` when we split off the ordering concept into a separate variable
- Packages that respect `direct_minimal_versions` are determined by whether they are the top-level `summaries` that get past into `resolve`

### What does this PR try to resolve?

The primary use case is verifying version requirements to avoid depending on something newer than might be available in a dependent

For this to help the MSRV use case, the crate author must directly depend on all indirect dependencies where their latest release has too new of an MSRV but at least they can do so with the `^` operator, rather than `<` and breaking the ecosystem.

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

The first two commits add tests using `-Zminimal-versions`.  The commit that adds `-Zdirect-minimal-versions` updates the tests, highlighting the differences in behavior.

### Additional information

Potential areas of conversation for stablization
- Flag name
- Handling of yanked (pick first non-yanked, pick yanked, error)
- Quality of error message
- Should the package have a "memory" of this flag being set by writing it to the lockfile?

Potential future work
- Stablize this
- Remove `-Zminimal-versions`
- Update `cargo publish`s `--verify` step to use this.
  - The challenge is this won't be using the packaged `Cargo.lock` which probably should also be verified.
2023-03-01 19:26:59 +00:00
Scott Schafer
019aeedeb4 feat: Use test name for dir when running tests 2023-03-01 11:38:58 -06:00
Ed Page
12000a9273 test(resolver): Create baseline for `-Zdirect-minimal-versions 2023-02-14 15:43:38 -06:00
Ed Page
d52f29897a chore: Deny warnings across entire cargo repo 2023-02-10 16:17:33 -06:00
Eric Huss
4cb9ac35bf Add network container tests 2023-01-14 15:10:16 -08:00