diff --git a/src/lib.rs b/src/lib.rs index 0112f87..09a2dd6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,8 +123,8 @@ pub fn crate_name(orig_name: &str) -> Result { } /// Make sure that the given crate name is a valid rust identifier. -fn sanitize_crate_name(name: String) -> String { - name.replace("-", "_") +fn sanitize_crate_name>(name: S) -> String { + name.as_ref().replace("-", "_") } /// Open the given `Cargo.toml` and parse it into a hashmap. @@ -156,7 +156,13 @@ fn extract_crate_name( if let Some(toml::Value::Table(t)) = cargo_toml.get("package") { if let Some(toml::Value::String(s)) = t.get("name") { if s == orig_name { - return Ok(FoundCrate::Itself); + if std::env::var_os("CARGO_TARGET_TMPDIR").is_none() { + // We're running for a library/binary crate + return Ok(FoundCrate::Itself); + } else { + // We're running for an integration test + return Ok(FoundCrate::Name(sanitize_crate_name(orig_name))); + } } } }