diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-03-16 09:00:41 +1300 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2015-03-16 11:03:54 +1300 |
| commit | 432011d1437ce046c25dde8a4db67dac63c19ed0 (patch) | |
| tree | a58820426c5f3e925c3cdb0d11faf4d408ee37c4 | |
| parent | 170ccd615f976fc9e90a8f14ce6c373bfdf01533 (diff) | |
| download | rust-432011d1437ce046c25dde8a4db67dac63c19ed0.tar.gz rust-432011d1437ce046c25dde8a4db67dac63c19ed0.zip | |
Fallout in testing.
| -rw-r--r-- | src/doc/reference.md | 8 | ||||
| -rw-r--r-- | src/libsyntax/test.rs | 17 | ||||
| -rw-r--r-- | src/test/auxiliary/privacy_reexport.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-dead-code-3.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/privacy1.rs | 16 | ||||
| -rw-r--r-- | src/test/run-pass/issue-16597.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/issue-20823.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/issue-5950.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs | 4 | ||||
| -rw-r--r-- | src/test/run-pass/test-should-fail-good-message.rs | 4 |
10 files changed, 29 insertions, 30 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md index c4c122463a7..3fae49bfc6d 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -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 diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 5e858d8a79f..991ab77419f 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -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 diff --git a/src/test/auxiliary/privacy_reexport.rs b/src/test/auxiliary/privacy_reexport.rs index 266903169c7..e60dbb290b0 100644 --- a/src/test/auxiliary/privacy_reexport.rs +++ b/src/test/auxiliary/privacy_reexport.rs @@ -10,6 +10,6 @@ pub use foo as bar; -mod foo { +pub mod foo { pub fn frob() {} } diff --git a/src/test/compile-fail/lint-dead-code-3.rs b/src/test/compile-fail/lint-dead-code-3.rs index f60c39ba020..13ee3f16361 100644 --- a/src/test/compile-fail/lint-dead-code-3.rs +++ b/src/test/compile-fail/lint-dead-code-3.rs @@ -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 diff --git a/src/test/compile-fail/privacy1.rs b/src/test/compile-fail/privacy1.rs index 1ae79adbad7..67dccb4c93e 100644 --- a/src/test/compile-fail/privacy1.rs +++ b/src/test/compile-fail/privacy1.rs @@ -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(); } diff --git a/src/test/run-pass/issue-16597.rs b/src/test/run-pass/issue-16597.rs index 72e948e613b..d074095dbde 100644 --- a/src/test/run-pass/issue-16597.rs +++ b/src/test/run-pass/issue-16597.rs @@ -15,5 +15,5 @@ mod test { use super::*; #[test] - fn test(){} + pub fn test(){} } diff --git a/src/test/run-pass/issue-20823.rs b/src/test/run-pass/issue-20823.rs index 561b6195476..c297998b649 100644 --- a/src/test/run-pass/issue-20823.rs +++ b/src/test/run-pass/issue-20823.rs @@ -14,4 +14,4 @@ #![deny(unstable)] #[test] -fn foo() {} +pub fn foo() {} diff --git a/src/test/run-pass/issue-5950.rs b/src/test/run-pass/issue-5950.rs index c9413258e0f..88bbba44bbe 100644 --- a/src/test/run-pass/issue-5950.rs +++ b/src/test/run-pass/issue-5950.rs @@ -11,6 +11,6 @@ pub use local as local_alias; -mod local { } +pub mod local { } pub fn main() {} diff --git a/src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs b/src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs index 7c99c968e35..f7985efbc31 100644 --- a/src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs +++ b/src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs @@ -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() -> () {} diff --git a/src/test/run-pass/test-should-fail-good-message.rs b/src/test/run-pass/test-should-fail-good-message.rs index b8e05b4d35a..94d20f703a0 100644 --- a/src/test/run-pass/test-should-fail-good-message.rs +++ b/src/test/run-pass/test-should-fail-good-message.rs @@ -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") } |
