Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/doc/man/cargo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ The libtest harness may be disabled by setting `harness = false` in the target
manifest settings, in which case your code will need to provide its own `main`
function to handle running tests.

By default, `cargo test` uses the [`test` profile], which enables
debugging.

[`test` profile]: ../reference/profiles.html#test

### Documentation tests

Documentation tests are also run by default, which is handled by `rustdoc`. It
Expand Down
4 changes: 4 additions & 0 deletions src/doc/man/generated_txt/cargo-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ DESCRIPTION
target manifest settings, in which case your code will need to provide
its own main function to handle running tests.

By default, cargo test uses the test profile
<https://doc.rust-lang.org/cargo/reference/profiles.html#test>, which
enables debugging.

Documentation tests
Documentation tests are also run by default, which is handled by
rustdoc. It extracts code samples from documentation comments of the
Expand Down
5 changes: 5 additions & 0 deletions src/doc/src/commands/cargo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ The libtest harness may be disabled by setting `harness = false` in the target
manifest settings, in which case your code will need to provide its own `main`
function to handle running tests.

By default, `cargo test` uses the [`test` profile], which enables
debugging.

[`test` profile]: ../reference/profiles.html#test

### Documentation tests

Documentation tests are also run by default, which is handled by `rustdoc`. It
Expand Down
16 changes: 14 additions & 2 deletions src/doc/src/reference/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,24 @@ rpath = false
### test

The `test` profile is the default profile used by [`cargo test`].
The `test` profile inherits the settings from the [`dev`](#dev) profile.

The default settings for the `test` profile are:

```toml
[profile.test]
inherits = "dev"
```

### bench

The `bench` profile is the default profile used by [`cargo bench`].
The `bench` profile inherits the settings from the [`release`](#release) profile.

The default settings for the `bench` profile are:

```toml
[profile.bench]
inherits = "release"
```

### Build Dependencies

Expand Down
3 changes: 3 additions & 0 deletions src/etc/man/cargo-test.1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ special executable as aforementioned, and then is run serially.
The libtest harness may be disabled by setting \fBharness = false\fR in the target
manifest settings, in which case your code will need to provide its own \fBmain\fR
function to handle running tests.
.sp
By default, \fBcargo test\fR uses the \fI\f(BItest\fI profile\fR <https://doc.rust\-lang.org/cargo/reference/profiles.html#test>, which enables
debugging.
.SS "Documentation tests"
Documentation tests are also run by default, which is handled by \fBrustdoc\fR\&. It
extracts code samples from documentation comments of the library target, and
Expand Down
22 changes: 21 additions & 1 deletion tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2813,7 +2813,7 @@ fn ambiguous_registry_vs_local_package() {
}

#[cargo_test]
fn install_with_redundant_default_mode() {
fn install_with_redundant_default_profile() {
pkg("foo", "0.0.1");

cargo_process("install foo --release")
Expand All @@ -2831,6 +2831,26 @@ For more information, try '--help'.
.run();
}

#[cargo_test]
fn install_with_debug_profile() {
pkg("foo", "0.0.1");

cargo_process("install foo --debug")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
[INSTALLING] foo v0.0.1
[COMPILING] foo v0.0.1
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries

"#]])
.run();
}

#[cargo_test]
fn install_incompat_msrv() {
Package::new("foo", "0.1.0")
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ mod profile_config;
mod profile_custom;
mod profile_overrides;
mod profile_panic_immediate_abort;
mod profile_settings;
mod profile_targets;
mod profile_trim_paths;
mod profiles;
mod progress;
mod pub_priv;
mod publish;
Expand Down
40 changes: 0 additions & 40 deletions tests/testsuite/profile_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Tests for profiles defined in config files.

use crate::prelude::*;
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_lib_manifest, paths, project, str};
use cargo_util_schemas::manifest::TomlDebugInfo;

Expand Down Expand Up @@ -484,42 +483,3 @@ fn named_env_profile() {
"#]])
.run();
}

#[cargo_test]
fn test_with_dev_profile() {
// The `test` profile inherits from `dev` for both local crates and
// dependencies.
Package::new("somedep", "1.0.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"

[dependencies]
somedep = "1.0"
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("test --lib --no-run -v")
.env("CARGO_PROFILE_DEV_DEBUG", "0")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] somedep v1.0.0 (registry `dummy-registry`)
[COMPILING] somedep v1.0.0
[RUNNING] `rustc --crate-name somedep [..]`
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..]`
[FINISHED] `test` profile [unoptimized] target(s) in [ELAPSED]s
[EXECUTABLE] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]`

"#]])
.with_stdout_does_not_contain("[..] -C debuginfo=0[..]")
.run();
}
96 changes: 96 additions & 0 deletions tests/testsuite/profile_custom.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Tests for named profiles.

use crate::prelude::*;
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_lib_manifest, project, str};

#[cargo_test]
Expand Down Expand Up @@ -696,3 +697,98 @@ fn legacy_rustc() {
"#]])
.run();
}

#[cargo_test]
fn test_inherits_dev() {
// The `test` profile inherits from `dev` for both local crates and
// dependencies.
Package::new("somedep", "1.0.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"

[dependencies]
somedep = "1.0"

[profile.dev]
debug = 0

[profile.test]
opt-level = 3
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("test --lib --no-run -v")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] somedep v1.0.0 (registry `dummy-registry`)
[COMPILING] somedep v1.0.0
[RUNNING] `rustc --crate-name somedep [..]`
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..]`
[FINISHED] `test` profile [optimized] target(s) in [ELAPSED]s
[EXECUTABLE] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]`

"#]])
.with_stdout_does_not_contain("[..] -C debuginfo=0[..]")
.with_stdout_does_not_contain("[..] -C opt-level=0[..]")
.run();
}

#[cargo_test]
fn change_test_inheritance() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"

[profile.test]
inherits = "release"
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("test --lib --no-run")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `test` profile [optimized] target(s) in [ELAPSED]s
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])

"#]])
.run();
}

#[cargo_test]
fn request_test_profile() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("check --profile test")
.with_stderr_data(str![[r#"
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run();
}
File renamed without changes.