From bc41a7afe916c5b5b90faf22d10d260d7742d034 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Fri, 21 Sep 2018 10:33:43 -0500 Subject: [PATCH] add tests for private doctests --- src/test/rustdoc/private-doctests-private.rs | 49 ++++++++++++++++++++ src/test/rustdoc/private-doctests.rs | 45 ++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/test/rustdoc/private-doctests-private.rs create mode 100644 src/test/rustdoc/private-doctests.rs diff --git a/src/test/rustdoc/private-doctests-private.rs b/src/test/rustdoc/private-doctests-private.rs new file mode 100644 index 0000000000000..c168cbd8f6d27 --- /dev/null +++ b/src/test/rustdoc/private-doctests-private.rs @@ -0,0 +1,49 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: --test --document-private-items +// should-fail + +// issue #30094: rustdoc runs doctests on private items even though those docs don't appear +// +// in this version, we show that passing --document-private-items causes the private doctests to +// run + +mod private { + /// Does all the work. + /// + /// ``` + /// panic!("oh no"); + /// ``` + pub fn real_job(a: u32, b: u32) -> u32 { + return a + b; + } +} + +pub mod public { + use super::private; + + /// ``` + /// // this was originally meant to link to public::function but we can't do that here + /// assert_eq!(2+2, 4); + /// ``` + pub fn function(a: u32, b: u32) -> u32 { + return complex_helper(a, b); + } + + /// Helps with stuff. + /// + /// ``` + /// panic!("oh no"); + /// ``` + fn complex_helper(a: u32, b: u32) -> u32 { + return private::real_job(a, b); + } +} diff --git a/src/test/rustdoc/private-doctests.rs b/src/test/rustdoc/private-doctests.rs new file mode 100644 index 0000000000000..480a525761489 --- /dev/null +++ b/src/test/rustdoc/private-doctests.rs @@ -0,0 +1,45 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: --test + +// issue #30094: rustdoc runs doctests on private items even though those docs don't appear + +mod private { + /// Does all the work. + /// + /// ``` + /// panic!("oh no"); + /// ``` + pub fn real_job(a: u32, b: u32) -> u32 { + return a + b; + } +} + +pub mod public { + use super::private; + + /// ``` + /// // this was originally meant to link to public::function but we can't do that here + /// assert_eq!(2+2, 4); + /// ``` + pub fn function(a: u32, b: u32) -> u32 { + return complex_helper(a, b); + } + + /// Helps with stuff. + /// + /// ``` + /// panic!("oh no"); + /// ``` + fn complex_helper(a: u32, b: u32) -> u32 { + return private::real_job(a, b); + } +}