kaj/ructe

Ructe produces a failing doc-test

Closed this issue · 2 comments

If I run cargo test on my app that uses ructe, I see the following failure. It looks like the generated _utils.rs file contains a code example that fails when run as a doc-test.

running 1 test
test target/debug/build/neros-dev-ec30b69737b0722c/out/templates/_utils.rs - templates::templates::_utils::ToHtml::to_buffer (line 21) ... FAILED

failures:

---- target/debug/build/neros-dev-ec30b69737b0722c/out/templates/_utils.rs - templates::templates::_utils::ToHtml::to_buffer (line 21) stdout ----
error[E0432]: unresolved imports `ructe`, `templates::ToHtml`
 --> target/debug/build/neros-dev-ec30b69737b0722c/out/templates/_utils.rs:23:5
  |
3 | use ructe::templates;
  |     ^^^^^ use of undeclared crate or module `ructe`
4 | use templates::ToHtml;
  |     ^^^^^^^^^^^^^^^^^

error[E0689]: can't call method `to_buffer` on ambiguous numeric type `{integer}`
 --> target/debug/build/neros-dev-ec30b69737b0722c/out/templates/_utils.rs:25:15
  |
5 | assert_eq!(17.to_buffer()?, "17");
  |               ^^^^^^^^^
  |
help: you must specify a concrete type for this numeric value, like `i32`
  |
5 | assert_eq!(17_i32.to_buffer()?, "17");
  |            ~~~~~~

error[E0599]: no method named `to_buffer` found for reference `&'static str` in the current scope
  --> target/debug/build/neros-dev-ec30b69737b0722c/out/templates/_utils.rs:26:20
   |
6  | assert_eq!("a < b".to_buffer()?, "a &lt; b");
   |                    ^^^^^^^^^ method not found in `&'static str`
   |
  ::: /home/soren/src/github.com/nerosnm/neros.dev/target/debug/build/neros-dev-ec30b69737b0722c/out/templates/_utils.rs:30:8
   |
30 |     fn to_buffer(&self) -> io::Result<HtmlBuffer> {
   |        --------- the method is available for `&'static str` here
   |
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
2  | use neros_dev::templates::ToHtml;
   |

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0432, E0599, E0689.
For more information about an error, try `rustc --explain E0432`.
Couldn't compile the test.

failures:
    target/debug/build/neros-dev-ec30b69737b0722c/out/templates/_utils.rs - templates::templates::_utils::ToHtml::to_buffer (line 21)
kaj commented

Thanks for the report! I'll look into it!

Are you using ructe 0.14.0 (the latest release) ?

kaj commented

Ah. I have only used ructe in binary crates, and doc tests are by default not used in binary crates. Adding a test of using ructe in a library crate, I see the problem and should be able to fix it.