Fallout in testing.

This commit is contained in:
Nick Cameron 2015-03-16 09:00:41 +13:00
parent 170ccd615f
commit 432011d143
10 changed files with 29 additions and 30 deletions

View file

@ -1961,16 +1961,18 @@ module through the rules above. It essentially allows public access into the
re-exported item. For example, this program is valid:
```
pub use self::implementation as api;
pub use self::implementation::api;
mod implementation {
pub fn f() {}
pub mod api {
pub fn f() {}
}
}
# fn main() {}
```
This means that any external crate referencing `implementation::f` would
This means that any external crate referencing `implementation::api::f` would
receive a privacy violation, while the path `api::f` would be allowed.
When re-exporting a private item, it can be thought of as allowing the "privacy

View file

@ -121,13 +121,11 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
debug!("current path: {}",
ast_util::path_name_i(&self.cx.path));
if is_test_fn(&self.cx, &*i) || is_bench_fn(&self.cx, &*i) {
let i = if is_test_fn(&self.cx, &*i) || is_bench_fn(&self.cx, &*i) {
match i.node {
ast::ItemFn(_, ast::Unsafety::Unsafe, _, _, _) => {
let diag = self.cx.span_diagnostic;
diag.span_fatal(i.span,
"unsafe functions cannot be used for \
tests");
diag.span_fatal(i.span, "unsafe functions cannot be used for tests");
}
_ => {
debug!("this is a test function");
@ -142,9 +140,18 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
self.tests.push(i.ident);
// debug!("have {} test/bench functions",
// cx.testfns.len());
// Make all tests public so we can call them from outside
// the module (note that the tests are re-exported and must
// be made public themselves to avoid privacy errors).
let mut result = (*i).clone();
result.vis = ast::Public;
P(result)
}
}
}
} else {
i
};
// We don't want to recurse into anything other than mods, since
// mods or tests inside of functions will break things

View file

@ -10,6 +10,6 @@
pub use foo as bar;
mod foo {
pub mod foo {
pub fn frob() {}
}

View file

@ -19,7 +19,7 @@ extern crate libc;
pub use extern_foo as x;
extern {
fn extern_foo();
pub fn extern_foo();
}
struct Foo; //~ ERROR: struct is never used

View file

@ -27,10 +27,6 @@ mod bar {
// can't publicly re-export private items
pub use self::baz::{foo, bar};
//~^ ERROR: function `bar` is private
pub use self::private::ppriv;
//~^ ERROR: function `ppriv` is private
pub struct A;
impl A {
@ -61,10 +57,8 @@ mod bar {
fn bar2(&self) {}
}
// both of these are re-exported by `bar`, but only one should be
// validly re-exported
pub fn foo() {}
fn bar() {}
pub fn bar() {}
}
extern {
@ -92,10 +86,6 @@ mod bar {
pub fn gpub() {}
fn gpriv() {}
}
mod private {
fn ppriv() {}
}
}
pub fn gpub() {}
@ -142,13 +132,13 @@ mod foo {
::bar::baz::foo(); //~ ERROR: function `foo` is inaccessible
//~^ NOTE: module `baz` is private
::bar::baz::bar(); //~ ERROR: function `bar` is private
::bar::baz::bar(); //~ ERROR: function `bar` is inaccessible
}
fn test2() {
use bar::baz::{foo, bar};
//~^ ERROR: function `foo` is inaccessible
//~^^ ERROR: function `bar` is private
//~^^ ERROR: function `bar` is inaccessible
foo();
bar();
}

View file

@ -15,5 +15,5 @@ mod test {
use super::*;
#[test]
fn test(){}
pub fn test(){}
}

View file

@ -14,4 +14,4 @@
#![deny(unstable)]
#[test]
fn foo() {}
pub fn foo() {}

View file

@ -11,6 +11,6 @@
pub use local as local_alias;
mod local { }
pub mod local { }
pub fn main() {}

View file

@ -13,8 +13,8 @@
extern crate test;
#[bench]
fn bench_explicit_return_type(_: &mut ::test::Bencher) -> () {}
pub fn bench_explicit_return_type(_: &mut ::test::Bencher) -> () {}
#[test]
fn test_explicit_return_type() -> () {}
pub fn test_explicit_return_type() -> () {}

View file

@ -13,13 +13,13 @@
#[test]
#[should_panic(expected = "foo")]
fn test_foo() {
pub fn test_foo() {
panic!("foo bar")
}
#[test]
#[should_panic(expected = "foo")]
fn test_foo_dynamic() {
pub fn test_foo_dynamic() {
panic!("{} bar", "foo")
}