diff --git a/src/bin/cargo/commands/run.rs b/src/bin/cargo/commands/run.rs index ce9f6d0d87bb..45521b5f05f6 100644 --- a/src/bin/cargo/commands/run.rs +++ b/src/bin/cargo/commands/run.rs @@ -5,6 +5,7 @@ use std::path::Path; use crate::command_prelude::*; use crate::util::restricted_names::is_glob_pattern; use cargo::core::Verbosity; +use cargo::core::Workspace; use cargo::ops::{self, CompileFilter, Packages}; use cargo_util::ProcessError; @@ -101,8 +102,10 @@ pub fn exec_manifest_command(config: &Config, cmd: &str, args: &[OsString]) -> C ); } let manifest_path = crate::util::try_canonicalize(manifest_path)?; - let script = cargo::util::toml::embedded::parse_from(&manifest_path)?; - let ws = cargo::util::toml::embedded::to_workspace(&script, config)?; + let mut ws = Workspace::new(&manifest_path, config)?; + if config.cli_unstable().avoid_dev_deps { + ws.set_require_optional_deps(false); + } let mut compile_opts = cargo::ops::CompileOptions::new(config, cargo::core::compiler::CompileMode::Build)?; diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 98498ead8844..5d46a7e06fac 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -64,6 +64,7 @@ pub struct Manifest { metabuild: Option>, resolve_behavior: Option, lint_rustflags: Vec, + embedded: bool, } /// When parsing `Cargo.toml`, some warnings should silenced @@ -407,6 +408,7 @@ impl Manifest { metabuild: Option>, resolve_behavior: Option, lint_rustflags: Vec, + embedded: bool, ) -> Manifest { Manifest { summary, @@ -433,6 +435,7 @@ impl Manifest { metabuild, resolve_behavior, lint_rustflags, + embedded, } } @@ -500,6 +503,9 @@ impl Manifest { pub fn links(&self) -> Option<&str> { self.links.as_deref() } + pub fn is_embedded(&self) -> bool { + self.embedded + } pub fn workspace_config(&self) -> &WorkspaceConfig { &self.workspace diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 702c1929a692..7f7114131fe1 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -726,6 +726,10 @@ impl<'cfg> Workspace<'cfg> { if self.members.contains(&manifest_path) { return Ok(()); } + if is_path_dep && self.root_maybe().is_embedded() { + // Embedded manifests cannot have workspace members + return Ok(()); + } if is_path_dep && !manifest_path.parent().unwrap().starts_with(self.root()) && self.find_root(&manifest_path)? != self.root_manifest @@ -1580,6 +1584,13 @@ impl MaybePackage { MaybePackage::Virtual(ref vm) => vm.workspace_config(), } } + + fn is_embedded(&self) -> bool { + match self { + MaybePackage::Package(p) => p.manifest().is_embedded(), + MaybePackage::Virtual(_) => false, + } + } } impl WorkspaceRootConfig { diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index fdd43d2ced42..a322afbb341d 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -393,7 +393,7 @@ fn build_lock(ws: &Workspace<'_>, orig_pkg: &Package) -> CargoResult { let package_root = orig_pkg.root(); let source_id = orig_pkg.package_id().source_id(); let (manifest, _nested_paths) = - TomlManifest::to_real_manifest(&toml_manifest, source_id, package_root, config)?; + TomlManifest::to_real_manifest(&toml_manifest, false, source_id, package_root, config)?; let new_pkg = Package::new(manifest, orig_pkg.manifest_path()); // Regenerate Cargo.lock using the old one as a guide. diff --git a/src/cargo/util/toml/embedded.rs b/src/cargo/util/toml/embedded.rs index 435d980cb619..943dc9cd4153 100644 --- a/src/cargo/util/toml/embedded.rs +++ b/src/cargo/util/toml/embedded.rs @@ -1,6 +1,5 @@ use anyhow::Context as _; -use crate::core::Workspace; use crate::CargoResult; use crate::Config; @@ -9,21 +8,13 @@ const DEFAULT_EDITION: crate::core::features::Edition = const DEFAULT_VERSION: &str = "0.0.0"; const DEFAULT_PUBLISH: bool = false; -pub struct RawScript { - manifest: String, - body: String, - path: std::path::PathBuf, -} - -pub fn parse_from(path: &std::path::Path) -> CargoResult { - let body = std::fs::read_to_string(path) - .with_context(|| format!("failed to script at {}", path.display()))?; - parse(&body, path) -} - -fn parse(body: &str, path: &std::path::Path) -> CargoResult { - let comment = match extract_comment(body) { - Ok(manifest) => Some(manifest), +pub fn expand_manifest( + content: &str, + path: &std::path::Path, + config: &Config, +) -> CargoResult { + let comment = match extract_comment(content) { + Ok(comment) => Some(comment), Err(err) => { log::trace!("failed to extract doc comment: {err}"); None @@ -38,83 +29,19 @@ fn parse(body: &str, path: &std::path::Path) -> CargoResult { } } .unwrap_or_default(); - let body = body.to_owned(); - let path = path.to_owned(); - Ok(RawScript { - manifest, - body, - path, - }) -} - -pub fn to_workspace<'cfg>( - script: &RawScript, - config: &'cfg Config, -) -> CargoResult> { - let target_dir = config - .target_dir() - .transpose() - .unwrap_or_else(|| default_target_dir().map(crate::util::Filesystem::new))?; - // HACK: without cargo knowing about embedded manifests, the only way to create a - // `Workspace` is either - // - Create a temporary one on disk - // - Create an "ephemeral" workspace **but** compilation re-loads ephemeral workspaces - // from the registry rather than what we already have on memory, causing it to fail - // because the registry doesn't know about embedded manifests. - let manifest_path = write(script, config, target_dir.as_path_unlocked())?; - let workspace = Workspace::new(&manifest_path, config)?; - Ok(workspace) -} - -fn write( - script: &RawScript, - config: &Config, - target_dir: &std::path::Path, -) -> CargoResult { - let hash = hash(script).to_string(); - assert_eq!(hash.len(), 64); - - let file_name = script - .path - .file_stem() - .ok_or_else(|| anyhow::format_err!("no file name"))? - .to_string_lossy(); - let separator = '_'; - let name = sanitize_package_name(file_name.as_ref(), separator); - - let mut workspace_root = target_dir.to_owned(); - workspace_root.push("eval"); - workspace_root.push(&hash[0..2]); - workspace_root.push(&hash[2..4]); - workspace_root.push(&hash[4..]); - workspace_root.push(name); - std::fs::create_dir_all(&workspace_root).with_context(|| { - format!( - "failed to create temporary workspace at {}", - workspace_root.display() - ) - })?; - let manifest_path = workspace_root.join("Cargo.toml"); - let manifest = expand_manifest(script, config)?; - write_if_changed(&manifest_path, &manifest)?; - Ok(manifest_path) -} - -fn expand_manifest(script: &RawScript, config: &Config) -> CargoResult { - let manifest = expand_manifest_(script, config) - .with_context(|| format!("failed to parse manifest at {}", script.path.display()))?; - let manifest = remap_paths( - manifest, - script.path.parent().ok_or_else(|| { - anyhow::format_err!("no parent directory for {}", script.path.display()) - })?, - )?; + let manifest = expand_manifest_(content, &manifest, path, config) + .with_context(|| format!("failed to parse manifest at {}", path.display()))?; let manifest = toml::to_string_pretty(&manifest)?; Ok(manifest) } -fn expand_manifest_(script: &RawScript, config: &Config) -> CargoResult { - let mut manifest: toml::Table = toml::from_str(&script.manifest)?; +fn expand_manifest_( + content: &str, + manifest: &str, + path: &std::path::Path, + config: &Config, +) -> CargoResult { + let mut manifest: toml::Table = toml::from_str(&manifest)?; for key in ["workspace", "lib", "bin", "example", "test", "bench"] { if manifest.contains_key(key) { @@ -135,14 +62,13 @@ fn expand_manifest_(script: &RawScript, config: &Config) -> CargoResult CargoResult String { slug } -fn hash(script: &RawScript) -> blake3::Hash { - blake3::hash(script.body.as_bytes()) -} - -fn default_target_dir() -> CargoResult { - let mut cargo_home = home::cargo_home()?; - cargo_home.push("eval"); - cargo_home.push("target"); - Ok(cargo_home) -} - -fn write_if_changed(path: &std::path::Path, new: &str) -> CargoResult<()> { - let write_needed = match std::fs::read_to_string(path) { - Ok(current) => current != new, - Err(_) => true, - }; - if write_needed { - std::fs::write(path, new).with_context(|| format!("failed to write {}", path.display()))?; - } - Ok(()) +fn hash(content: &str) -> blake3::Hash { + blake3::hash(content.as_bytes()) } /// Locates a "code block manifest" in Rust source. @@ -438,10 +344,12 @@ mod test_expand { macro_rules! si { ($i:expr) => {{ - let script = parse($i, std::path::Path::new("/home/me/test.rs")) - .unwrap_or_else(|err| panic!("{}", err)); - expand_manifest(&script, &Config::default().unwrap()) - .unwrap_or_else(|err| panic!("{}", err)) + expand_manifest( + $i, + std::path::Path::new("/home/me/test.rs"), + &Config::default().unwrap(), + ) + .unwrap_or_else(|err| panic!("{}", err)) }}; } @@ -693,73 +601,6 @@ fn main() {} } } -/// Given a Cargo manifest, attempts to rewrite relative file paths to absolute ones, allowing the manifest to be relocated. -fn remap_paths( - mani: toml::Table, - package_root: &std::path::Path, -) -> anyhow::Result { - // Values that need to be rewritten: - let paths: &[&[&str]] = &[ - &["build-dependencies", "*", "path"], - &["dependencies", "*", "path"], - &["dev-dependencies", "*", "path"], - &["package", "build"], - &["target", "*", "dependencies", "*", "path"], - ]; - - let mut mani = toml::Value::Table(mani); - - for path in paths { - iterate_toml_mut_path(&mut mani, path, &mut |v| { - if let toml::Value::String(s) = v { - if std::path::Path::new(s).is_relative() { - let p = package_root.join(&*s); - if let Some(p) = p.to_str() { - *s = p.into() - } - } - } - Ok(()) - })? - } - - match mani { - toml::Value::Table(mani) => Ok(mani), - _ => unreachable!(), - } -} - -/// Iterates over the specified TOML values via a path specification. -fn iterate_toml_mut_path( - base: &mut toml::Value, - path: &[&str], - on_each: &mut F, -) -> anyhow::Result<()> -where - F: FnMut(&mut toml::Value) -> anyhow::Result<()>, -{ - if path.is_empty() { - return on_each(base); - } - - let cur = path[0]; - let tail = &path[1..]; - - if cur == "*" { - if let toml::Value::Table(tab) = base { - for (_, v) in tab { - iterate_toml_mut_path(v, tail, on_each)?; - } - } - } else if let toml::Value::Table(tab) = base { - if let Some(v) = tab.get_mut(cur) { - iterate_toml_mut_path(v, tail, on_each)?; - } - } - - Ok(()) -} - #[cfg(test)] mod test_manifest { use super::*; diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 386c88722917..1cc32dee8f07 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1,4 +1,5 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; +use std::ffi::OsStr; use std::fmt::{self, Display, Write}; use std::marker::PhantomData; use std::path::{Path, PathBuf}; @@ -55,13 +56,29 @@ pub fn read_manifest( path.display(), source_id ); - let contents = paths::read(path).map_err(|err| ManifestError::new(err, path.into()))?; + let mut contents = paths::read(path).map_err(|err| ManifestError::new(err, path.into()))?; + let embedded = is_embedded(path); + if embedded { + if !config.cli_unstable().script { + return Err(ManifestError::new( + anyhow::anyhow!("parsing `{}` requires `-Zscript`", path.display()), + path.into(), + )); + } + contents = embedded::expand_manifest(&contents, path, config) + .map_err(|err| ManifestError::new(err, path.into()))?; + } - read_manifest_from_str(&contents, path, source_id, config) + read_manifest_from_str(&contents, path, embedded, source_id, config) .with_context(|| format!("failed to parse manifest at `{}`", path.display())) .map_err(|err| ManifestError::new(err, path.into())) } +fn is_embedded(path: &Path) -> bool { + let ext = path.extension(); + ext.is_none() || ext == Some(OsStr::new("rs")) +} + /// Parse an already-loaded `Cargo.toml` as a Cargo manifest. /// /// This could result in a real or virtual manifest being returned. @@ -73,6 +90,7 @@ pub fn read_manifest( fn read_manifest_from_str( contents: &str, manifest_file: &Path, + embedded: bool, source_id: SourceId, config: &Config, ) -> CargoResult<(EitherManifest, Vec)> { @@ -128,7 +146,7 @@ fn read_manifest_from_str( } return if manifest.project.is_some() || manifest.package.is_some() { let (mut manifest, paths) = - TomlManifest::to_real_manifest(&manifest, source_id, package_root, config)?; + TomlManifest::to_real_manifest(&manifest, embedded, source_id, package_root, config)?; add_unused(manifest.warnings_mut()); if manifest.targets().iter().all(|t| t.is_custom_build()) { bail!( @@ -1976,6 +1994,7 @@ impl TomlManifest { pub fn to_real_manifest( me: &Rc, + embedded: bool, source_id: SourceId, package_root: &Path, config: &Config, @@ -2644,6 +2663,7 @@ impl TomlManifest { package.metabuild.clone().map(|sov| sov.0), resolve_behavior, rustflags, + embedded, ); if package.license_file.is_some() && package.license.is_some() { manifest.warnings_mut().add_warning( diff --git a/tests/testsuite/script.rs b/tests/testsuite/script.rs index 20f8a46ab511..72e4f1176a43 100644 --- a/tests/testsuite/script.rs +++ b/tests/testsuite/script.rs @@ -26,16 +26,16 @@ fn basic_rs() { p.cargo("-Zscript echo.rs") .masquerade_as_nightly_cargo(&["script"]) .with_stdout( - r#"bin: [ROOT]/home/.cargo/eval/target/eval/[..] + r#"bin: target/debug/[..] args: [] "#, ) .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] echo v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/echo) +[COMPILING] echo v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/echo/target/debug/echo_[..]` +[RUNNING] `target/debug/echo_[..]` ", ) .run(); @@ -50,16 +50,16 @@ fn basic_path() { p.cargo("-Zscript ./echo") .masquerade_as_nightly_cargo(&["script"]) .with_stdout( - r#"bin: [ROOT]/home/.cargo/eval/target/eval/[..] + r#"bin: target/debug/[..] args: [] "#, ) .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] echo v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/echo) +[COMPILING] echo v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/echo/target/debug/echo_[..]` +[RUNNING] `target/debug/echo_[..]` ", ) .run(); @@ -104,16 +104,16 @@ fn manifest_precedence_over_plugins() { .env("PATH", &path) .masquerade_as_nightly_cargo(&["script"]) .with_stdout( - r#"bin: [ROOT]/home/.cargo/eval/target/eval/[..] + r#"bin: target/debug/[..] args: [] "#, ) .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] echo v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/echo) +[COMPILING] echo v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/echo/target/debug/echo_[..]` +[RUNNING] `target/debug/echo_[..]` ", ) .run(); @@ -203,9 +203,9 @@ fn main() { ) .with_stderr( "\ -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]` +[RUNNING] `target/debug/script_[..]` ", ) .run(); @@ -235,9 +235,9 @@ fn main() { .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]` +[RUNNING] `target/debug/script_[..]` ", ) .run(); @@ -264,9 +264,9 @@ fn main() { .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]` +[RUNNING] `target/debug/script_[..]` ", ) .run(); @@ -282,7 +282,7 @@ fn main() { "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]` +[RUNNING] `target/debug/script_[..]` ", ) .run(); @@ -298,9 +298,9 @@ fn main() { .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]` +[RUNNING] `target/debug/script_[..]` ", ) .run(); @@ -327,9 +327,9 @@ fn main() { .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]` +[RUNNING] `target/debug/script_[..]` ", ) .run(); @@ -345,16 +345,16 @@ fn test_escaped_hyphen_arg() { p.cargo("-Zscript -- script.rs -NotAnArg") .masquerade_as_nightly_cargo(&["script"]) .with_stdout( - r#"bin: [ROOT]/home/.cargo/eval/target/eval/[..] + r#"bin: target/debug/[..] args: ["-NotAnArg"] "#, ) .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] -NotAnArg` +[RUNNING] `target/debug/script_[..] -NotAnArg` ", ) .run(); @@ -370,16 +370,16 @@ fn test_unescaped_hyphen_arg() { p.cargo("-Zscript script.rs -NotAnArg") .masquerade_as_nightly_cargo(&["script"]) .with_stdout( - r#"bin: [ROOT]/home/.cargo/eval/target/eval/[..] + r#"bin: target/debug/[..] args: ["-NotAnArg"] "#, ) .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] -NotAnArg` +[RUNNING] `target/debug/script_[..] -NotAnArg` ", ) .run(); @@ -395,16 +395,16 @@ fn test_same_flags() { p.cargo("-Zscript script.rs --help") .masquerade_as_nightly_cargo(&["script"]) .with_stdout( - r#"bin: [ROOT]/home/.cargo/eval/target/eval/[..] + r#"bin: target/debug/[..] args: ["--help"] "#, ) .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] --help` +[RUNNING] `target/debug/script_[..] --help` ", ) .run(); @@ -420,13 +420,13 @@ fn test_name_has_weird_chars() { p.cargo("-Zscript s-h.w§c!.rs") .masquerade_as_nightly_cargo(&["script"]) .with_stdout( - r#"bin: [ROOT]/home/.cargo/eval/target/eval/[..] + r#"bin: target/debug/[..] args: [] "#, ) .with_stderr( r#"[WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] s-h_w_c_ v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/s-h_w_c_) +[COMPILING] s-h_w_c_ v0.0.0 ([ROOT]/foo) [WARNING] crate `s_h_w_c__[..]` should have a snake case name | = help: convert the identifier to snake case: `s_h_w_c_[..]` @@ -434,7 +434,7 @@ args: [] [WARNING] `s-h_w_c_` (bin "s-h_w_c__[..]") generated 1 warning [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/s-h_w_c_/target/debug/s-h_w_c__[..]` +[RUNNING] `target/debug/s-h_w_c__[..]` "#, ) .run(); @@ -470,9 +470,9 @@ fn main() { [DOWNLOADING] crates ... [DOWNLOADED] script v1.0.0 (registry `dummy-registry`) [COMPILING] script v1.0.0 -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] --help` +[RUNNING] `target/debug/script_[..] --help` ", ) .run(); @@ -507,9 +507,9 @@ fn main() { "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` [COMPILING] bar v0.0.1 ([ROOT]/foo/bar) -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) +[COMPILING] script v0.0.0 ([ROOT]/foo) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] --help` +[RUNNING] `target/debug/script_[..] --help` ", ) .run(); @@ -529,16 +529,12 @@ fn main() { p.cargo("-Zscript script.rs --help") .masquerade_as_nightly_cargo(&["script"]) - .with_stdout( - r#"Hello world! -"#, - ) + .with_status(101) .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s -[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] --help` +[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key. +available binaries: script, script_[..] ", ) .run();