Doc tests are compiled as if they were clients of a library, so you'll have to write the test assuming the rest of the source was built with `--crate-type lib` and then import it directly.
For example, you may have to do this: ```rust main::under_test(); ``` Doc test aren't really designed with executables in mind, sadly, but perhaps that could change! On Wed, Jul 9, 2014 at 9:37 AM, Jeffery Olson <[email protected]> wrote: > Consider the following docs: > > > /// Foo > /// > /// ```rust > /// under_test(); > /// ``` > pub fn under_test() { > } > > doing `rustdoc main.rs --test` produces: > > jeff@jeff-mbp:~/src/rust-intro-presentation/Jun2014$ rustdoc main.rs --test > > running 1 test > test foo::under_test_0 ... FAILED > > failures: > > ---- foo::under_test_0 stdout ---- > <anon>:5:5: 5:15 error: unresolved name `under_test`. > <anon>:5 under_test(); > ^~~~~~~~~~ > error: aborting due to previous error > task 'foo::under_test_0' failed at 'Box<Any>', > /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/diagnostic.rs:128 > > > > failures: > foo::under_test_0 > > test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured > > > Why is this? I've also tried different combinations of module imports to get > this to work.. the only place this feature is used, extensively, is in > libstd and it appears that maybe this is sidestepped because libstd is > always linked by default? The manual doesn't really cover this in-depth, > either. > > Any help would be appreciated. > > Thanks, > Jeff > > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev > _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
