Commit graph

146 commits

Author SHA1 Message Date
Wim Looman
255914696a
Apply -Zpanic-abort-tests to doctests too 2024-02-02 19:45:15 +01:00
Wim Looman
4ebbda15e1
Ensure nonzero_exit_code test isn't affected by developers RUST_BACKTRACE setting 2024-02-02 16:04:21 +01:00
Ed Page
675224b3a0 test(config): Shift to config.toml 2024-01-26 13:40:46 -06:00
Weihang Lo
f9fd4ff4ee
fix(json-msg): use pkgid spec in in JSON messages
In 12914 we stabilized pkgid spec as unique package identifier for
`cargo metadata`. However, we forgot to make the same change to
JSON message format[^1]. This PR does so.

Note that the `package_id` field in JSON message is not clearly stated
as "opaque", so it might be considered as a breaking change to some extent.

[^1]: https://doc.rust-lang.org/nightly/cargo/reference/external-tools.html#compiler-messages
2024-01-17 11:31:19 -05:00
hi-rustin
6739c7e95e fix: set OUT_DIR for all units with build scripts
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-08 20:59:18 +08:00
hi-rustin
8bba4f48c4 test: include a case for setting OUT_DIR
Signed-off-by: hi-rustin <rustin.liu@gmail.com>

test: remove the env set by Cargo

Signed-off-by: hi-rustin <rustin.liu@gmail.com>

Fix

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-08 20:58:52 +08:00
Eric Huss
0afd943dad Fix some test output validation. 2023-11-15 15:10:18 -08:00
Jacob Finkelman
d19273c04d If the only path is a loop then counted as the shortest path. 2023-11-14 20:18:43 +00:00
Jacob Finkelman
cd2e4e3912 add a test 2023-11-14 20:18:43 +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
bors
7b61184ad1 Auto merge of #12498 - Kobzol:run-verbose-print-env, r=arlosi
Print environment variables for `cargo run` in extra verbose mode
2023-08-17 05:32:16 +00:00
Jakub Beránek
9267277048
Print environment variables for cargo test in extra verbose mode 2023-08-16 13:41:54 +02:00
Weihang Lo
689defd4ba
test: relax assertions of panic message (again) 2023-08-14 19:32:39 +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
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
Weihang Lo
b9e70ec0a2
test: relax assertions of panic handler message format 2023-07-29 17:12:46 +01:00
Dinu Blanovschi
0beb5fe93d Simple explanations for why cargo rebuilds crates 2022-12-28 16:27:50 +01: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
3dd8413f77 fix(test): Distinguish 'testname' from escaped arguments
When working on clap v4, it appeared that `last` and `trailing_var_arg`
are mutually exclusive, so I called that out in the debug asserts in
clap-rs/clap#4187.  Unfortunately, I didn't document my research on this
as my focus was elsewhere.

When updating cargo to use clap v4 in #11159, I found `last` and
`trailing_var_arg` were used together.  I figured this was what I was
trying to catch with above and I went off of my intuitive sense of these
commands and assumed `trailing_var_arg` was intended, not knowing about
the `testname` positional that is mostly just a forward to `libtest`,
there for documentation purposes, except for a small optimization.

So it looks like we just need the `last` call and not the
`trailing_var_arg` call.

This restores us to behavior from 531ce1321 which is what I originally
wrote the tests against.
2022-10-07 10:23:55 -05:00
Ed Page
dd6228ebdb test(test): Verify escaping behavior 2022-10-07 10:08:26 -05:00
Scott Schafer
ab18bd40d5 refactor(testsuite): Replace [project] with [package] 2022-09-26 09:51:16 -06:00
jiangying
260620e755
Update test.rs 2022-09-26 15:28:16 +08:00
Eric Huss
23735d4c09 Rework test error handling 2022-08-27 19:23:30 -07:00
hi-rustin
99b3564d0d Update old tests
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-19 10:56:29 +08:00
Eric Huss
1c3640e05c Add requirements to cargo_test. 2022-07-30 19:36:58 -07:00
Scott Schafer
c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05:00
Danil Hendra Suryawan
7952680d8d No printing executable names when running tests with json message format 2022-05-21 23:18:46 +07:00
Loïc BRANSTETT
2d0ca84b0e Move check cfg tests to their own module 2022-05-06 22:42:28 +02:00
Loïc BRANSTETT
6a9f094c8c Convert the testsuite to use the new -Zcheck-cfg flag and syntax 2022-05-06 22:40:08 +02:00
Loïc BRANSTETT
02cd9442c7 Add support for rustc --check-cfg well known names and values 2022-03-18 22:14:39 +01:00
Loïc BRANSTETT
e828e85ee7 Add -Z check-cfg-features support for rustdoc 2022-02-26 14:10:17 +01:00
Loïc BRANSTETT
a864c81549 Disable -Z check-cfg-features tests on windows due to weird normalization issues
See https://github.com/rust-lang/cargo/runs/5290789288?check_suite_focus=true
Where the expected is: --check-cfg 'values(feature, "f_a", "f_b")'
But we got: --check-cfg "values(feature, /"f_a/", /"f_b/")"
2022-02-22 18:33:03 +01:00
Loïc BRANSTETT
03fbb2eda8 Add -Z check-cfg-features to enable compile-time checking of features 2022-02-22 16:47:52 +01:00
bors
46c9b51957 Auto merge of #10346 - yerke:yerke/no-run-test-executable-path, r=ehuss
Print executable name on cargo test --no-run #2

Closes #9957

This is a continuation of https://github.com/rust-lang/cargo/pull/9959.
2022-02-20 15:47:58 +00:00
Yerkebulan Tulibergenov
ed579b66e2 add short path name for executables 2022-01-31 10:37:02 -08:00
Yerkebulan Tulibergenov
a6c1459f37 fix tests 2022-01-30 23:59:54 -08:00
Weihang Lo
bee3534f27
test: do not compile test for bins flagged as test = false 2022-01-19 03:36:53 +08:00
Weihang Lo
f07dcd13a0
test: compile all bins when TESTNAME arg exists
This behavior is not correct should be fixed.
Update this test only for pointing out the current behavior.
2022-01-19 02:47:30 +08:00
Vaibhav
bef4d79ff2 Print executable name on cargo test --no-run.
Closes #9957

Signed-off-by: Vaibhav <vrongmeal@gmail.com>
2021-10-05 23:47:38 +05:30
hi-rustin
8ee5433c3a doc test supports silent output
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-07-27 15:49:59 +08:00
Simonas Kazlauskas
548300b20f Add the path to the manifest in json output
This allows consumers of the json messages to avoid guessing where
exactly the package root is. Having access to the package root is
difficult by virtue of requiring logic to guess its location by e.g.
walking filesystem from the source file.

This guessing logic becomes further complicated in presence of
workspaces and nigh impossible to implement correctly in instances where
artifacts end up produced from paths above the package root (e.g.
`../foo.rs`).

Since Cargo has access to this data in the first place, there doesn't
seem to be much reason to force consumers to invent their own, possibly
flawed, logic.
2021-03-04 20:09:51 +02:00
bors
9a7fe2c23b Auto merge of #9195 - guswynn:test_name, r=ehuss
Make it more clear which module is being tested when running cargo test

I recently asked in zulip if this is a good idea, as I find it hard to find the module thats being tested from the complex path with the hash.

Output of `cargo test`:
```
2021-02-21 13:29:33 I > ~/repos/cargo/target/debug/cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.42s
     Running unittests (target/debug/deps/test_tests-759130ea61f71571)

running 1 test
test tests::unit_test ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in
0.00s

     Running tests2/lib.rs (target/debug/deps/integration_tests-6b7f9fcd1721f083)

running 2 tests
test tests2_lib ... ok
test second_test::tests2_second ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in
0.00s

     Running tests/lib.rs (target/debug/deps/lib-d2be6d29597c2790)

running 2 tests
test second_test::tests_i_am_run_twice ... ok
test tests_lib ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in
0.00s
...
```
2021-02-24 03:59:28 +00:00
Arpad Borsos
b4c4028f76
Run rustdoc doctests relative to the workspace
By doing so, rustdoc will also emit workspace-relative filenames for the doctests.

This was first landed in #8954 but later backed out in #8996 because it changed the CWD of rustdoc test invocations.

The second try relies on the new `--test-run-directory` rustdoc option which was added in https://github.com/rust-lang/rust/pull/81264 to explicitly control the rustdoc test cwd.

fixes #8993
2021-02-22 20:33:31 +01:00
Gus Wynn
04c8372217 fix test suite 2021-02-21 14:37:42 -08:00
Arpad Borsos
7137e32447 Assert that tests are run in the crate directory
To avoid regressions to the test runtime directory, this asserts that
all test types (unit, integration, doctest) are executed in the crate
(manifest) directory, no matter where that crate is in relation to the
workspace root.

See #8992 / #8993
2021-01-02 14:34:21 +01:00
bors
774c64cfea Auto merge of #8869 - ayazhafiz:e/metadata-doc, r=ehuss
Publish target's "doc" setting when emitting metadata

Prior to this commit `cargo metadata` would not emit the value of a
target's "doc" setting, used by `cargo doc` to determine whether
documentation should be generated. However, this information is useful
for machine programs interested in such targets, and the information is
already made available on the internal representation of a target, so
this commit just exposes that during target serialization for emit.

cf https://github.com/deadlinks/cargo-deadlinks/issues/99
2020-11-24 00:27:46 +00:00
Jakob Schikowski
62ddaf343e Relaxes expectation of cargo test tests to accept test execution time 2020-11-23 00:25:46 +01:00
ayazhafiz
e831dd12a8 Publish target's "doc" setting when emitting metadata
Prior to this commit `cargo metadata` would not emit the value of a
target's "doc" setting, used by `cargo doc` to determine whether
documentation should be generated. However, this information is useful
for machine programs interested in such targets, and the information is
already made available on the internal representation of a target, so
this commit just exposes that during target serialization for emit.

cf https://github.com/deadlinks/cargo-deadlinks/issues/99
2020-11-17 19:54:17 -06:00