Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow procmacro usage in integration tests #13

Merged
merged 2 commits into from
Sep 9, 2021
Merged
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
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ pub fn crate_name(orig_name: &str) -> Result<FoundCrate, Error> {
}

/// 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<S: AsRef<str>>(name: S) -> String {
name.as_ref().replace("-", "_")
}

/// Open the given `Cargo.toml` and parse it into a hashmap.
Expand Down Expand Up @@ -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)));
}
}
}
}
Expand Down