diff --git a/mk/target.mk b/mk/target.mk index c3995dbd23351..4cee1ffe62f00 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -28,7 +28,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \ $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg test && touch $$@ $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X): \ $$(DRIVER_CRATE) \ @@ -47,7 +47,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX): \ $$(TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3)) \ $$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3)) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) -o $$@ $$< --cfg test && touch $$@ endef @@ -110,7 +110,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB): \ $$(CORELIB_CRATE) $$(CORELIB_INPUTS) \ $$(TSREQ$(1)_T_$(2)_H_$(3)) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg test && touch $$@ endef @@ -134,7 +134,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \ $$(TSREQ$(1)_T_$(2)_H_$(3)) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg test && touch $$@ endef diff --git a/mk/tests.mk b/mk/tests.mk index 29e6b08efc0f1..a8e59e0773638 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -223,6 +223,7 @@ FULL_TEST_SREQ$(1)_T_$(2)_H_$(3) = \ $$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3)) check-stage$(1)-T-$(2)-H-$(3): \ + check-stage$(1)-T-$(2)-H-$(3)-syntax \ check-stage$(1)-T-$(2)-H-$(3)-rustc \ check-stage$(1)-T-$(2)-H-$(3)-core \ check-stage$(1)-T-$(2)-H-$(3)-std \ @@ -248,6 +249,9 @@ check-stage$(1)-T-$(2)-H-$(3)-core: \ check-stage$(1)-T-$(2)-H-$(3)-std: \ check-stage$(1)-T-$(2)-H-$(3)-std-dummy +check-stage$(1)-T-$(2)-H-$(3)-syntax: \ + check-stage$(1)-T-$(2)-H-$(3)-syntax-dummy + check-stage$(1)-T-$(2)-H-$(3)-rustc: \ check-stage$(1)-T-$(2)-H-$(3)-rustc-dummy @@ -321,10 +325,11 @@ check-stage$(1)-T-$(2)-H-$(3)-doc-ref: \ # Rules for the core library test runner $(3)/test/coretest.stage$(1)-$(2)$$(X): \ - $$(CORELIB_CRATE) $$(CORELIB_INPUTS) \ - $$(SREQ$(1)_T_$(2)_H_$(3)) + $$(DRIVER_CRATE) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg core_test check-stage$(1)-T-$(2)-H-$(3)-core-dummy: \ $(3)/test/coretest.stage$(1)-$(2)$$(X) @@ -335,10 +340,10 @@ check-stage$(1)-T-$(2)-H-$(3)-core-dummy: \ # Rules for the standard library test runner $(3)/test/stdtest.stage$(1)-$(2)$$(X): \ - $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \ - $$(SREQ$(1)_T_$(2)_H_$(3)) + $$(DRIVER_CRATE) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg std_test check-stage$(1)-T-$(2)-H-$(3)-std-dummy: \ $(3)/test/stdtest.stage$(1)-$(2)$$(X) @@ -346,15 +351,27 @@ check-stage$(1)-T-$(2)-H-$(3)-std-dummy: \ $$(Q)$$(call CFG_RUN_TEST,$$<,$(2),$(3)) $$(TESTARGS) \ --logfile tmp/check-stage$(1)-T-$(2)-H-$(3)-std.log +# Rules for the syntax test runner + +$(3)/test/syntaxtest.stage$(1)-$(2)$$(X): \ + $$(DRIVER_CRATE) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX) + @$$(call E, compile_and_link: $$@) + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg syntax_test + +check-stage$(1)-T-$(2)-H-$(3)-syntax-dummy: \ + $(3)/test/syntaxtest.stage$(1)-$(2)$$(X) + @$$(call E, run: $$<) + $$(Q)$$(call CFG_RUN_TEST,$$<,$(2),$(3)) $$(TESTARGS) \ + --logfile tmp/check-stage$(1)-T-$(2)-H-$(3)-syntax.log + # Rules for the rustc test runner $(3)/test/rustctest.stage$(1)-$(2)$$(X): \ - $$(COMPILER_CRATE) \ - $$(COMPILER_INPUTS) \ - $$(SREQ$(1)_T_$(2)_H_$(3)) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM) + $$(DRIVER_CRATE) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg rustc_test check-stage$(1)-T-$(2)-H-$(3)-rustc-dummy: \ $(3)/test/rustctest.stage$(1)-$(2)$$(X) @@ -365,13 +382,10 @@ check-stage$(1)-T-$(2)-H-$(3)-rustc-dummy: \ # Rules for the rustdoc test runner $(3)/test/rustdoctest.stage$(1)-$(2)$$(X): \ - $$(RUSTDOC_LIB) $$(RUSTDOC_INPUTS) \ - $$(TSREQ$(1)_T_$(2)_H_$(3)) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC) + $$(DRIVER_CRATE) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTDOC) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg rustdoc_test check-stage$(1)-T-$(2)-H-$(3)-rustdoc-dummy: \ $(3)/test/rustdoctest.stage$(1)-$(2)$$(X) @@ -382,13 +396,10 @@ check-stage$(1)-T-$(2)-H-$(3)-rustdoc-dummy: \ # Rules for the rusti test runner $(3)/test/rustitest.stage$(1)-$(2)$$(X): \ - $$(RUSTI_LIB) $$(RUSTI_INPUTS) \ - $$(TSREQ$(1)_T_$(2)_H_$(3)) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC) + $$(DRIVER_CRATE) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTI) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg rusti_test check-stage$(1)-T-$(2)-H-$(3)-rusti-dummy: \ $(3)/test/rustitest.stage$(1)-$(2)$$(X) @@ -400,13 +411,10 @@ check-stage$(1)-T-$(2)-H-$(3)-rusti-dummy: \ # Rules for the cargo test runner $(3)/test/cargotest.stage$(1)-$(2)$$(X): \ - $$(CARGO_LIB) $$(CARGO_INPUTS) \ - $$(TSREQ$(1)_T_$(2)_H_$(3)) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC) + $$(DRIVER_CRATE) \ + $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBCARGO) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test + $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg cargo_test check-stage$(1)-T-$(2)-H-$(3)-cargo-dummy: \ $(3)/test/cargotest.stage$(1)-$(2)$$(X) @@ -737,6 +745,9 @@ check-stage$(1)-H-$(2): \ check-stage$(1)-H-$(2)-perf: \ $$(foreach target,$$(CFG_TARGET_TRIPLES), \ check-stage$(1)-T-$$(target)-H-$(2)-perf) +check-stage$(1)-H-$(2)-syntax: \ + $$(foreach target,$$(CFG_TARGET_TRIPLES), \ + check-stage$(1)-T-$$(target)-H-$(2)-syntax) check-stage$(1)-H-$(2)-rustc: \ $$(foreach target,$$(CFG_TARGET_TRIPLES), \ check-stage$(1)-T-$$(target)-H-$(2)-rustc) @@ -830,6 +841,9 @@ check-stage$(1)-H-all: \ check-stage$(1)-H-all-perf: \ $$(foreach target,$$(CFG_TARGET_TRIPLES), \ check-stage$(1)-H-$$(target)-perf) +check-stage$(1)-H-all-syntax: \ + $$(foreach target,$$(CFG_TARGET_TRIPLES), \ + check-stage$(1)-H-$$(target)-syntax) check-stage$(1)-H-all-rustc: \ $$(foreach target,$$(CFG_TARGET_TRIPLES), \ check-stage$(1)-H-$$(target)-rustc) @@ -897,6 +911,7 @@ define DEF_CHECK_FOR_STAGE check-stage$(1): check-stage$(1)-H-$$(CFG_HOST_TRIPLE) check-stage$(1)-perf: check-stage$(1)-H-$$(CFG_HOST_TRIPLE)-perf +check-stage$(1)-syntax: check-stage$(1)-H-$$(CFG_HOST_TRIPLE)-syntax check-stage$(1)-rustc: check-stage$(1)-H-$$(CFG_HOST_TRIPLE)-rustc check-stage$(1)-core: check-stage$(1)-H-$$(CFG_HOST_TRIPLE)-core check-stage$(1)-std: check-stage$(1)-H-$$(CFG_HOST_TRIPLE)-std diff --git a/mk/tools.mk b/mk/tools.mk index 93f794be29da7..951a2371f8e75 100644 --- a/mk/tools.mk +++ b/mk/tools.mk @@ -31,7 +31,7 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBFUZZER): \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< --cfg test && touch $$@ $$(TBIN$(1)_T_$(4)_H_$(3))/fuzzer$$(X): \ $$(DRIVER_CRATE) \ @@ -77,7 +77,7 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBCARGO): \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< --cfg test && touch $$@ $$(TBIN$(1)_T_$(4)_H_$(3))/cargo$$(X): \ $$(DRIVER_CRATE) \ @@ -106,7 +106,7 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTDOC): \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< --cfg test && touch $$@ $$(TBIN$(1)_T_$(4)_H_$(3))/rustdoc$$(X): \ $$(DRIVER_CRATE) \ @@ -135,7 +135,7 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTI): \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< --cfg test && touch $$@ $$(TBIN$(1)_T_$(4)_H_$(3))/rusti$$(X): \ $$(DRIVER_CRATE) \ diff --git a/src/driver/driver.rs b/src/driver/driver.rs index 49143ddc97d4f..5b70e3a038601 100644 --- a/src/driver/driver.rs +++ b/src/driver/driver.rs @@ -1,19 +1,62 @@ #[no_core]; extern mod core(vers = "0.5"); +use core::*; + +extern mod std(vers = "0.5"); + +#[cfg(rustc)] +extern mod self(name = "rustc", vers = "0.5"); + +#[cfg(rusti)] +extern mod self(name = "rusti", vers = "0.5"); #[cfg(cargo)] extern mod self(name = "cargo", vers = "0.5"); +#[cfg(rustdoc)] +extern mod self(name = "rustdoc", vers = "0.5"); + #[cfg(fuzzer)] extern mod self(name = "fuzzer", vers = "0.5"); -#[cfg(rustdoc)] -extern mod self(name = "rustdoc", vers = "0.5"); +#[cfg(core_test)] +extern mod self(name = "core", vers = "0.5"); -#[cfg(rusti)] +#[cfg(std_test)] +extern mod self(name = "std", vers = "0.5"); + +#[cfg(syntax_test)] +extern mod self(name = "syntax", vers = "0.5"); + +#[cfg(rustc_test)] +extern mod self(name = "rustc", vers = "0.5"); + +#[cfg(rusti_test)] extern mod self(name = "rusti", vers = "0.5"); +#[cfg(rustdoc_test)] +extern mod self(name = "rustdoc", vers = "0.5"); + +#[cfg(cargo_test)] +extern mod self(name = "cargo", vers = "0.5"); + +#[cfg(cargo)] +#[cfg(fuzzer)] +#[cfg(rustdoc)] +#[cfg(rusti)] #[cfg(rustc)] -extern mod self(name = "rustc", vers = "0.5"); +fn main() { self::main() } -fn main() { self::main() } \ No newline at end of file +#[cfg(core_test)] +#[cfg(std_test)] +#[cfg(syntax_test)] +#[cfg(rustc_test)] +#[cfg(rusti_test)] +#[cfg(rustdoc_test)] +#[cfg(cargo_test)] +fn main() { + let args = os::args(); + // The test vector generated by rustc + let tests = self::__test::tests(); + std::test::test_main(args, tests) +} diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 6d4a5849e3522..57b9efd75d194 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -133,19 +133,13 @@ pub pure fn from_elem(n_elts: uint, t: T) -> @[T] { } } -#[cfg(notest)] -pub mod traits { - pub impl @[T] : Add<&[const T],@[T]> { - #[inline(always)] - pure fn add(rhs: & &self/[const T]) -> @[T] { - append(self, (*rhs)) - } +pub impl @[T] : Add<&[const T],@[T]> { + #[inline(always)] + pure fn add(rhs: & &self/[const T]) -> @[T] { + append(self, (*rhs)) } } -#[cfg(test)] -pub mod traits {} - pub mod raw { pub type VecRepr = vec::raw::VecRepr; pub type SliceRepr = vec::raw::SliceRepr; diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index 9a3b40757a703..bd84ab45be9ad 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -105,7 +105,6 @@ struct Task { */ /// Destroys all managed memory (i.e. @ boxes) held by the current task. -#[cfg(notest)] #[lang="annihilate"] pub unsafe fn annihilate() { use rt::rt_free; diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index c3630e9f857c5..60cc6750a7f93 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -14,69 +14,37 @@ and `Eq` to overload the `==` and `!=` operators. #[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; -pub use nounittest::*; -pub use unittest::*; - /// Interfaces used for comparison. -// Awful hack to work around duplicate lang items in core test. -#[cfg(notest)] -mod nounittest { - /** - * Trait for values that can be compared for a sort-order. - * - * Eventually this may be simplified to only require - * an `le` method, with the others generated from - * default implementations. - */ - #[lang="ord"] - pub trait Ord { - pure fn lt(other: &self) -> bool; - pure fn le(other: &self) -> bool; - pure fn ge(other: &self) -> bool; - pure fn gt(other: &self) -> bool; - } - - #[lang="eq"] - /** - * Trait for values that can be compared for equality - * and inequality. - * - * Eventually this may be simplified to only require - * an `eq` method, with the other generated from - * a default implementation. - */ - #[lang="eq"] - pub trait Eq { - pure fn eq(other: &self) -> bool; - pure fn ne(other: &self) -> bool; - } +/** +* Trait for values that can be compared for a sort-order. +* +* Eventually this may be simplified to only require +* an `le` method, with the others generated from +* default implementations. +*/ +#[lang="ord"] +pub trait Ord { + pure fn lt(other: &self) -> bool; + pure fn le(other: &self) -> bool; + pure fn ge(other: &self) -> bool; + pure fn gt(other: &self) -> bool; } -#[cfg(test)] -mod nounittest { - #[legacy_exports];} - -#[cfg(test)] -mod unittest { - #[legacy_exports]; - pub trait Ord { - pure fn lt(other: &self) -> bool; - pure fn le(other: &self) -> bool; - pure fn ge(other: &self) -> bool; - pure fn gt(other: &self) -> bool; - } - - pub trait Eq { - pure fn eq(other: &self) -> bool; - pure fn ne(other: &self) -> bool; - } +/** +* Trait for values that can be compared for equality +* and inequality. +* +* Eventually this may be simplified to only require +* an `eq` method, with the other generated from +* a default implementation. +*/ +#[lang="eq"] +pub trait Eq { + pure fn eq(other: &self) -> bool; + pure fn ne(other: &self) -> bool; } -#[cfg(notest)] -mod unittest { - #[legacy_exports];} - pub pure fn lt(v1: &T, v2: &T) -> bool { (*v1).lt(v2) } diff --git a/src/libcore/condition.rs b/src/libcore/condition.rs index 30b25403a4ec9..6940294624b01 100644 --- a/src/libcore/condition.rs +++ b/src/libcore/condition.rs @@ -92,7 +92,11 @@ struct Guard { } -#[cfg(test)] +// XXX: Remove after snapshot and uncommond cfg(test) +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +//#[cfg(test)] mod test { fn sadness_key(_x: @Handler) { } diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 707d612504628..e2b0b73c92cf7 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -137,7 +137,6 @@ pub mod owned; // Ubiquitous-utility-type modules -#[cfg(notest)] pub mod ops; pub mod cmp; pub mod num; @@ -206,12 +205,13 @@ pub mod condition; pub mod extfmt; // The test harness links against core, so don't include runtime in tests. -#[cfg(notest)] #[legacy_exports] pub mod rt; // Ideally not exported, but currently is. -pub mod private; +pub mod private { + pub mod test; +} // For internal use, not exported. mod unicode; diff --git a/src/libcore/core.rs b/src/libcore/core.rs index 1be217dac9f9f..98eebc921799c 100644 --- a/src/libcore/core.rs +++ b/src/libcore/core.rs @@ -25,30 +25,11 @@ pub use to_str::ToStr; // The following exports are the core operators and kinds // The compiler has special knowlege of these so we must not duplicate them // when compiling for testing -#[cfg(notest)] pub use ops::{Const, Copy, Send, Owned}; -#[cfg(notest)] pub use ops::{Drop}; -#[cfg(notest)] pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, BitAnd, BitOr, BitXor}; -#[cfg(notest)] pub use ops::{Shl, Shr, Index}; -#[cfg(test)] -extern mod coreops(name = "core", vers = "0.5"); - -#[cfg(test)] -pub use coreops::ops::{Const, Copy, Send, Owned}; -#[cfg(test)] -pub use coreops::ops::{Drop}; -#[cfg(test)] -pub use coreops::ops::{Add, Sub, Mul, Div, Modulo, Neg, BitAnd, BitOr}; -#[cfg(test)] -pub use coreops::ops::{BitXor}; -#[cfg(test)] -pub use coreops::ops::{Shl, Shr, Index}; - - // Export the log levels as global constants. Higher levels mean // more-verbosity. Error is the bottom level, default logging level is // warn-and-below. @@ -74,8 +55,6 @@ mod core { } // Similar to above. Some magic to make core testable. -#[cfg(test)] -mod std { - extern mod std(vers = "0.5"); - pub use std::test; +priv mod std { + pub use private::test; } diff --git a/src/libcore/logging.rs b/src/libcore/logging.rs index 958d1ac56ea78..0f87a90818b26 100644 --- a/src/libcore/logging.rs +++ b/src/libcore/logging.rs @@ -29,7 +29,6 @@ pub fn console_off() { rustrt::rust_log_console_off(); } -#[cfg(notest)] #[lang="log_type"] pub fn log_type(level: u32, object: &T) { let bytes = do io::with_bytes_writer |writer| { diff --git a/src/libcore/private/test.rs b/src/libcore/private/test.rs new file mode 100644 index 0000000000000..aecc10822bbd0 --- /dev/null +++ b/src/libcore/private/test.rs @@ -0,0 +1,29 @@ +/*! Test definitions. The actual test runner is in std */ + +// The name of a test. By convention this follows the rules for rust +// paths; i.e. it should be a series of identifiers seperated by double +// colons. This way if some test runner wants to arrange the tests +// hierarchically it may. +pub type TestName = ~str; + +// A function that runs a test. If the function returns successfully, +// the test succeeds; if the function fails then the test fails. We +// may need to come up with a more clever definition of test in order +// to support isolation of tests into tasks. +pub type TestFn = fn~(); + +// The definition of a single test. A test runner will run a list of +// these. +pub type TestDesc = { + name: TestName, + testfn: TestFn, + ignore: bool, + should_fail: bool +}; + +// This exists to satisfy linkage. rustc's test pass generates a call to it, +// but we'll never use it. Instead driver.rs will call std::test::test_main +// directly. +pub fn test_main(_args: &[~str], _tests: &[TestDesc]) { + fail +} \ No newline at end of file diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 8b67d30b66bb1..3ffbdfc19ca3d 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -659,7 +659,6 @@ Section: Comparing strings */ /// Bytewise slice equality -#[cfg(notest)] #[lang="str_eq"] pub pure fn eq_slice(a: &str, b: &str) -> bool { do as_buf(a) |ap, alen| { @@ -676,34 +675,12 @@ pub pure fn eq_slice(a: &str, b: &str) -> bool { } } -#[cfg(test)] -pub pure fn eq_slice(a: &str, b: &str) -> bool { - do as_buf(a) |ap, alen| { - do as_buf(b) |bp, blen| { - if (alen != blen) { false } - else { - unsafe { - libc::memcmp(ap as *libc::c_void, - bp as *libc::c_void, - (alen - 1) as libc::size_t) == 0 - } - } - } - } -} - /// Bytewise string equality -#[cfg(notest)] #[lang="uniq_str_eq"] pub pure fn eq(a: &~str, b: &~str) -> bool { eq_slice(*a, *b) } -#[cfg(test)] -pub pure fn eq(a: &~str, b: &~str) -> bool { - eq_slice(*a, *b) -} - /// Bytewise slice less than pure fn lt(a: &str, b: &str) -> bool { let (a_len, b_len) = (a.len(), b.len()); @@ -2094,19 +2071,13 @@ impl ~str: Trimmable { pure fn trim_right() -> ~str { trim_right(self) } } -#[cfg(notest)] -pub mod traits { - impl ~str : Add<&str,~str> { - #[inline(always)] - pure fn add(rhs: & &self/str) -> ~str { - append(copy self, (*rhs)) - } +impl ~str : Add<&str,~str> { + #[inline(always)] + pure fn add(rhs: & &self/str) -> ~str { + append(copy self, (*rhs)) } } -#[cfg(test)] -pub mod traits {} - pub trait StrSlice { pure fn all(it: fn(char) -> bool) -> bool; pure fn any(it: fn(char) -> bool) -> bool; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 16415300b09ee..be50ae3df3761 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1393,26 +1393,20 @@ impl @[T] : Ord { pure fn gt(other: &@[T]) -> bool { gt(self, (*other)) } } -#[cfg(notest)] -pub mod traits { - impl ~[T] : Add<&[const T],~[T]> { - #[inline(always)] - pure fn add(rhs: & &self/[const T]) -> ~[T] { - append(copy self, (*rhs)) - } +impl ~[T] : Add<&[const T],~[T]> { + #[inline(always)] + pure fn add(rhs: & &self/[const T]) -> ~[T] { + append(copy self, (*rhs)) } +} - impl ~[mut T] : Add<&[const T],~[mut T]> { - #[inline(always)] - pure fn add(rhs: & &self/[const T]) -> ~[mut T] { - append_mut(copy self, (*rhs)) - } +impl ~[mut T] : Add<&[const T],~[mut T]> { + #[inline(always)] + pure fn add(rhs: & &self/[const T]) -> ~[mut T] { + append_mut(copy self, (*rhs)) } } -#[cfg(test)] -pub mod traits {} - pub trait ConstVector { pure fn is_empty() -> bool; pure fn is_not_empty() -> bool; diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index c839be0739f9c..21fb1d49b3a6a 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -29,7 +29,13 @@ type test_ctxt = fn modify_for_testing(sess: session::Session, crate: @ast::crate) -> @ast::crate { - if sess.opts.test { + // We generate the test harness when building in the 'test' + // configuration, either with the '--test' or '--cfg test' + // command line options. + let should_test = attr::contains(crate.node.config, + attr::mk_word_item(~"test")); + + if should_test { generate_test_harness(sess, crate) } else { strip_test_functions(crate) @@ -65,14 +71,15 @@ fn strip_test_functions(crate: @ast::crate) -> @ast::crate { fn fold_mod(cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { // Remove any defined main function from the AST so it doesn't clash with - // the one we're going to add. + // the one we're going to add. Only if compiling an executable. // FIXME (#2403): This is sloppy. Instead we should have some mechanism to // indicate to the translation pass which function we want to be main. fn nomain(cx: test_ctxt, item: @ast::item) -> Option<@ast::item> { match item.node { ast::item_fn(*) => { - if item.ident == cx.sess.ident_of(~"main") { + if item.ident == cx.sess.ident_of(~"main") + && !cx.sess.building_library { option::None } else { option::Some(item) } } diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 58366042fe988..d269ebffe404b 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -21,26 +21,9 @@ extern mod rustrt { fn rust_sched_threads() -> libc::size_t; } -// The name of a test. By convention this follows the rules for rust -// paths; i.e. it should be a series of identifiers seperated by double -// colons. This way if some test runner wants to arrange the tests -// hierarchically it may. -pub type TestName = ~str; - -// A function that runs a test. If the function returns successfully, -// the test succeeds; if the function fails then the test fails. We -// may need to come up with a more clever definition of test in order -// to support isolation of tests into tasks. -pub type TestFn = fn~(); - -// The definition of a single test. A test runner will run a list of -// these. -pub type TestDesc = { - name: TestName, - testfn: TestFn, - ignore: bool, - should_fail: bool -}; +pub type TestName = core::private::test::TestName; +pub type TestFn = core::private::test::TestFn; +pub type TestDesc = core::private::test::TestDesc; // The default console test runner. It accepts the command line // arguments and a vector of test_descs (generated at compile time). diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index ed64d02cea36e..daf592dc7b75e 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -135,19 +135,6 @@ fn fun_to_str(decl: ast::fn_decl, name: ast::ident, } } -#[test] -fn test_fun_to_str() { - let decl: ast::fn_decl = { - inputs: ~[], - output: @{id: 0, - node: ast::ty_nil, - span: ast_util::dummy_sp()}, - purity: ast::impure_fn, - cf: ast::return_val - }; - assert fun_to_str(decl, "a", ~[]) == "fn a()"; -} - fn block_to_str(blk: ast::blk, intr: @ident_interner) -> ~str { do io::with_str_writer |wr| { let s = rust_printer(wr, intr); @@ -172,20 +159,6 @@ fn variant_to_str(var: ast::variant, intr: @ident_interner) -> ~str { to_str(var, print_variant, intr) } -#[test] -fn test_variant_to_str() { - let var = ast_util::respan(ast_util::dummy_sp(), { - name: "principle_skinner", - attrs: ~[], - args: ~[], - id: 0, - disr_expr: none - }); - - let varstr = variant_to_str(var); - assert varstr == "principle_skinner"; -} - fn cbox(s: ps, u: uint) { s.boxes.push(pp::consistent); pp::cbox(s.s, u); diff --git a/src/test/compile-fail/multiple-main.rs b/src/test/compile-fail/multiple-main.rs new file mode 100644 index 0000000000000..03e40167e88bf --- /dev/null +++ b/src/test/compile-fail/multiple-main.rs @@ -0,0 +1,7 @@ +fn main() { +} + +mod foo { + fn main() { //~ ERROR multiple 'main' functions + } +} \ No newline at end of file