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

Can ctor be used to initialize doctests? #298

Open
ivan-aksamentov opened this issue Jan 9, 2024 · 0 comments
Open

Can ctor be used to initialize doctests? #298

ivan-aksamentov opened this issue Jan 9, 2024 · 0 comments

Comments

@ivan-aksamentov
Copy link

Thank you for the fantastic crate!

I succesfully use ctor in order to initialize my tests, notably I initialize color_eyre, which makes output much prettier:

#[cfg(test)]
mod tests {
  use crate::utils::global_init::global_init;
  use ctor::ctor;

  #[ctor]
  fn init() {
    global_init();
  }
}

However, it does not work for doctests. I tried various permutations of things, none worked - the function is not called. Some of my attempts on Ubuntu 22.04:

#[cfg(doctest)]
mod tests {
  use crate::utils::global_init::global_init;
  use ctor::ctor;

  #[ctor]
  fn init() {
    global_init();
  }
}
#[cfg(any(test, doctest))]
mod tests {
  use crate::utils::global_init::global_init;
  use ctor::ctor;

  #[ctor]
  fn init() {
    global_init();
  }
}
#[cfg(doctest)]
#[ctor::ctor]
fn init() {
  utils::global_init::global_init();
}

Have anyone managed to run ctor with for doctests? Please share your experience.

Or is this something that ctor does not support, perhaps due to technical limitations?

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