about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-01-17 16:17:47 -0800
committerBrian Anderson <banderson@mozilla.com>2012-01-17 19:41:05 -0800
commit8acae671c70825f65bddaa5076e8d595b6721f46 (patch)
treedb5f6829713d8a59240339c831abd064f2a4276c /src/comp
parent050083a5e65e77ba843d6f06d576599b111da818 (diff)
downloadrust-8acae671c70825f65bddaa5076e8d595b6721f46.tar.gz
rust-8acae671c70825f65bddaa5076e8d595b6721f46.zip
rustc: Allow std to be built as a test runner
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/front/test.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs
index be9554d7c68..bbe08b73165 100644
--- a/src/comp/front/test.rs
+++ b/src/comp/front/test.rs
@@ -234,20 +234,33 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
     ret @item;
 }
 
+fn mk_path(cx: test_ctxt, path: [ast::ident]) -> [ast::ident] {
+    // For tests that are inside of std we don't want to prefix
+    // the paths with std::
+    let is_std = {
+        let items = attr::find_linkage_metas(cx.crate.node.attrs);
+        alt attr::meta_item_value_from_list(items, "name") {
+          some("std") { true }
+          _ { false }
+        }
+    };
+    (is_std ? [] : ["std"]) + path
+}
+
 // The ast::ty of [std::test::test_desc]
 fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
     let test_fn_ty: ast::ty = nospan(
         ast::ty_path(
             @nospan({
                 global: false,
-                idents: ["std", "test", "default_test_fn"],
+                idents: mk_path(cx, ["test", "default_test_fn"]),
                 types: []
             }),
             cx.sess.next_node_id()));
 
     let test_desc_ty_path =
         @nospan({global: false,
-                 idents: ["std", "test", "test_desc"],
+                 idents: mk_path(cx, ["test", "test_desc"]),
                  types: [@test_fn_ty]});
 
     let test_desc_ty: ast::ty =
@@ -437,7 +450,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
     // Call std::test::test_main
     let test_main_path =
         @nospan({global: false,
-                 idents: ["std", "test", "test_main"],
+                 idents: mk_path(cx, ["test", "test_main"]),
                  types: []});
 
     let test_main_path_expr_: ast::expr_ = ast::expr_path(test_main_path);