about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-05-13 18:19:48 -0400
committerAlex Crichton <alex@alexcrichton.com>2013-05-14 14:11:07 -0400
commit54f2147e8eb49507e419b2129a08bfd1585f7e77 (patch)
tree44922443c8c7e3e3ce83e7a525f3fe869f2e04c5
parent767e3ae86cba26437a60009d79ac2a295b41768e (diff)
downloadrust-54f2147e8eb49507e419b2129a08bfd1585f7e77.tar.gz
rust-54f2147e8eb49507e419b2129a08bfd1585f7e77.zip
Get unit tests for rusti working
* They didn't work before, because the location of the tests caused the
  'sysroot' option to crate lookup to be wrong for finding the correct stage's
  core/std libraries. This moves the compiled tests from the $host/test
  directory into a $host/$stage/test directory. This means that the sysroot will
  be correct and the core/std libraries can actually be found
* The LLVM bindings apparently aren't threadsafe, so we can't run multiple tests
  in parallel.
-rwxr-xr-xconfigure3
-rw-r--r--mk/tests.mk22
-rw-r--r--src/librusti/rusti.rc53
3 files changed, 64 insertions, 14 deletions
diff --git a/configure b/configure
index 0c4afa0566d..e4ca72737db 100755
--- a/configure
+++ b/configure
@@ -695,6 +695,9 @@ do
             # host lib dir
             make_dir $h/stage$i/$CFG_LIBDIR
 
+            # host test dir
+            make_dir $h/stage$i/test
+
             # target bin dir
             make_dir $h/stage$i/$CFG_LIBDIR/rustc/$t/bin
 
diff --git a/mk/tests.mk b/mk/tests.mk
index 8ac2ad68e3a..5cdd900d65f 100644
--- a/mk/tests.mk
+++ b/mk/tests.mk
@@ -289,50 +289,50 @@ else
 STDTESTDEP_$(1)_$(2)_$(3) =
 endif
 
-$(3)/test/coretest.stage$(1)-$(2)$$(X_$(2)):			\
+$(3)/stage$(1)/test/coretest-$(2)$$(X_$(2)):			\
 		$$(CORELIB_CRATE) $$(CORELIB_INPUTS)	\
 		$$(STDTESTDEP_$(1)_$(2)_$(3))
 	@$$(call E, compile_and_link: $$@)
 	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
 
-$(3)/test/stdtest.stage$(1)-$(2)$$(X_$(2)):			\
+$(3)/stage$(1)/test/stdtest-$(2)$$(X_$(2)):			\
 		$$(STDLIB_CRATE) $$(STDLIB_INPUTS)	\
 		$$(STDTESTDEP_$(1)_$(2)_$(3))
 	@$$(call E, compile_and_link: $$@)
 	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
 
-$(3)/test/syntaxtest.stage$(1)-$(2)$$(X_$(2)):			\
+$(3)/stage$(1)/test/syntaxtest-$(2)$$(X_$(2)):			\
 		$$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS)	\
 		$$(STDTESTDEP_$(1)_$(2)_$(3))
 	@$$(call E, compile_and_link: $$@)
 	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
 
-$(3)/test/rustctest.stage$(1)-$(2)$$(X_$(2)):					\
+$(3)/stage$(1)/test/rustctest-$(2)$$(X_$(2)):					\
 		$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
 		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM_$(2)) \
                 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX_$(2))
 	@$$(call E, compile_and_link: $$@)
 	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
 
-$(3)/test/rustpkgtest.stage$(1)-$(2)$$(X_$(2)):					\
+$(3)/stage$(1)/test/rustpkgtest-$(2)$$(X_$(2)):					\
 		$$(RUSTPKG_LIB) $$(RUSTPKG_INPUTS)		\
 		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
 	@$$(call E, compile_and_link: $$@)
 	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
 
-$(3)/test/rustitest.stage$(1)-$(2)$$(X_$(2)):					\
+$(3)/stage$(1)/test/rustitest-$(2)$$(X_$(2)):					\
 		$$(RUSTI_LIB) $$(RUSTI_INPUTS)		\
 		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
 	@$$(call E, compile_and_link: $$@)
 	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
 
-$(3)/test/rusttest.stage$(1)-$(2)$$(X_$(2)):					\
+$(3)/stage$(1)/test/rusttest-$(2)$$(X_$(2)):					\
 		$$(RUST_LIB) $$(RUST_INPUTS)		\
 		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
 	@$$(call E, compile_and_link: $$@)
 	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
 
-$(3)/test/rustdoctest.stage$(1)-$(2)$$(X_$(2)):					\
+$(3)/stage$(1)/test/rustdoctest-$(2)$$(X_$(2)):					\
 		$$(RUSTDOC_LIB) $$(RUSTDOC_INPUTS)		\
 		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
 	@$$(call E, compile_and_link: $$@)
@@ -349,7 +349,7 @@ define DEF_TEST_CRATE_RULES
 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
 
 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
-		$(3)/test/$(4)test.stage$(1)-$(2)$$(X_$(2))
+		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
 	@$$(call E, run: $$<)
 	$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) $$(TESTARGS)	\
 	--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
@@ -360,7 +360,7 @@ define DEF_TEST_CRATE_RULES_arm-linux-androideabi
 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
 
 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
-		$(3)/test/$(4)test.stage$(1)-$(2)$$(X_$(2))
+		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
 	@$$(call E, run: $$< via adb)
 	@$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
 	@$(CFG_ADB) shell LD_LIBRARY_PATH=$(CFG_ADB_TEST_DIR) \
@@ -385,7 +385,7 @@ define DEF_TEST_CRATE_RULES_null
 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
 
 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
-		$(3)/test/$(4)test.stage$(1)-$(2)$$(X_$(2))
+		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
 	@$$(call E, run: skipped $$< )
 	@touch $$@
 endef
diff --git a/src/librusti/rusti.rc b/src/librusti/rusti.rc
index 7e2ad69c88e..65cd50e4b7f 100644
--- a/src/librusti/rusti.rc
+++ b/src/librusti/rusti.rc
@@ -35,7 +35,7 @@ use std::rl;
  * A structure shared across REPL instances for storing history
  * such as statements and view items. I wish the AST was sendable.
  */
-struct Repl {
+pub struct Repl {
     prompt: ~str,
     binary: ~str,
     running: bool,
@@ -328,8 +328,8 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
 
 /// Executes a line of input, which may either be rust code or a
 /// :command. Returns a new Repl if it has changed.
-fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str,
-            use_rl: bool)
+pub fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str,
+                use_rl: bool)
     -> Option<Repl> {
     if line.starts_with(":") {
         let full = line.substr(1, line.len() - 1);
@@ -421,3 +421,50 @@ pub fn main() {
         }
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    fn repl() -> Repl {
+        Repl {
+            prompt: ~"rusti> ",
+            binary: ~"rusti",
+            running: true,
+            view_items: ~"",
+            lib_search_paths: ~[],
+            stmts: ~""
+        }
+    }
+
+    fn super_simple() {
+        let mut r = repl();
+        let result = run_line(&mut r, io::stdin(), io::stdout(), ~"", false);
+        result.expect("empty input shouldn't fail in rusti");
+    }
+
+    fn use_does_not_crash() {
+        let mut r = repl();
+        let result = run_line(&mut r, io::stdin(), io::stdout(),
+                              ~"use core::util::with;", false);
+        r = result.expect("use statements should't fail in rusti");
+        let result = run_line(&mut r, io::stdin(), io::stdout(),
+                              ~"", false);
+        result.expect("something should be able to happen after a use statement");
+    }
+
+    #[test]
+    fn run_all() {
+        // By default, unit tests are run in parallel. Rusti, on the other hand,
+        // does not enjoy doing this. I suspect that it is because the LLVM
+        // bindings are not thread-safe (when running parallel tests, some tests
+        // were triggering assertions in LLVM (or segfaults). Hence, this
+        // function exists to run everything serially (sadface).
+        //
+        // To get some interesting output, run with RUST_LOG=rusti::tests
+
+        debug!("super_simple");       super_simple();
+        debug!("use_does_not_crash"); use_does_not_crash();
+
+    }
+}