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

Tests don't pass when sending Cargo.toml with optional dependency #1762

Closed
mrkgnt opened this issue Nov 7, 2023 · 1 comment
Closed

Tests don't pass when sending Cargo.toml with optional dependency #1762

mrkgnt opened this issue Nov 7, 2023 · 1 comment

Comments

@mrkgnt
Copy link

mrkgnt commented Nov 7, 2023

Hi,

I have been working on reverse-string issue. Looking at the Cargo.toml file, it contains [features] grapheme entry, which lead me to believe I can add an optional dependency to the feature. So I did -

Cargo.toml:

[dependencies]
unicode-segmentation = { version = "1.7.1", optional = true }

[features]
grapheme = ["dep:unicode-segmentation"]

[package]
edition = "2021"
name = "reverse_string"
version = "1.2.0"

I was expecting tests that don't have #[cfg(feature = "grapheme")] annotation to run fine but after submitting my solution to the website, they all fail due to compiler not finding the crate for non-annotated tests.

Exercism test output -

Compiling reverse_string v1.2.0 (/mnt/exercism-iteration)
error[E0432]: unresolved import `unicode_segmentation`
 --> src/lib.rs:4:13
  |
4 |         use unicode_segmentation::UnicodeSegmentation;
  |             ^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `unicode_segmentation`

error[E0599]: no method named `graphemes` found for reference `&str` in the current scope
 --> src/lib.rs:5:22
  |
5 |         return input.graphemes(true).rev().collect::<String>();
  |                      ^^^^^^^^^ method not found in `&str`

Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `reverse_string` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `reverse_string` due to 2 previous errors

And here's my solution to the problem -

pub fn reverse(input: &str) -> String {
    if cfg!(feature = "grapheme") {
        use unicode_segmentation::UnicodeSegmentation;
        return input.graphemes(true).rev().collect::<String>();
    }

    return input.chars().rev().collect::<String>();
}

It works fine on my machine (said every developer ever), I assume that the tests that are ran on the exercism end are not running with --all-features flag or something or am I doing something wrong here?

Local env versions -
cargo 1.72.0 (103a7ff2e 2023-08-15)
rustc 1.72.0 (5680fa18f 2023-08-23)

Copy link
Contributor

github-actions bot commented Nov 7, 2023

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use this link to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.

@github-actions github-actions bot closed this as completed Nov 7, 2023
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

No branches or pull requests

1 participant