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

allow procmacro usage in integration tests #13

merged 2 commits into from
Sep 9, 2021

Conversation

CobaltCause
Copy link
Contributor

If generating code for an integration test, avoid returning FoundCrate::Itself since that leads to incorrect paths. This fixes #10.

If generating code for an integration test, avoid returning
FoundCrate::Itself since that leads to incorrect paths.
Copy link
Owner

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general idea is nice!

However, it would not work currently. It would return CrateNotFound because a crate is normally not a dependency of itself.

        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 {
                    if env::var_os("CARGO_TARGET_TMPDIR").is_some() {
                        return Ok(FoundCrate::Itself);
                    } else {
                        return Ok(FoundCrate::Name(sanitize_crate_name(orig_name));
                }
            }
        }

This should do it.

@CobaltCause
Copy link
Contributor Author

I've added a commit to address that concern.

It appeared to work for me (see here and here), but I just realized that's probably because I wasn't using the crate correctly. Indeed, what I had before didn't actually work after fixing that. It works after adding that commit though.

(Sidenote, I think your .is_some() is a typo; CARGO_TARGET_TMPDIR is only set for integration tests and not libraries/binaries, and for the latter it needs to return FoundCrate::Itself and for the former we need FoundCrate::Name.)

@bkchr bkchr merged commit 44b3888 into bkchr:master Sep 9, 2021
@CobaltCause
Copy link
Contributor Author

@bkchr any chance of doing a crates.io release with this change?

@bkchr
Copy link
Owner

bkchr commented Sep 15, 2021

@SoftwareSheriff published as 1.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FoundCrate::Itself does not distinguish between crate and integration tests
2 participants