about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-07-14 11:29:54 -0700
committerBrian Anderson <banderson@mozilla.com>2011-07-14 13:51:30 -0700
commitb3dee955144a722da50e17dde62cb36cbcccf73f (patch)
treec4fe653b9eaf9be74f48fac73406f77a427768e9 /src/comp
parent49da7da441716da2ae99b893907f0fbd1655d813 (diff)
downloadrust-b3dee955144a722da50e17dde62cb36cbcccf73f.tar.gz
rust-b3dee955144a722da50e17dde62cb36cbcccf73f.zip
Add a facility for ignoring tests. Issue #428
Adding the #[ignore] attribute will cause the test not to be run, though it
will still show up in the list of tests.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/front/test.rs39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs
index 939d2c717da..a0d1118bdd0 100644
--- a/src/comp/front/test.rs
+++ b/src/comp/front/test.rs
@@ -11,9 +11,12 @@ export modify_for_testing;
 
 type node_id_gen = @fn() -> ast::node_id;
 
+type test = rec(ast::ident[] path,
+                bool ignore);
+
 type test_ctxt = @rec(node_id_gen next_node_id,
                       mutable ast::ident[] path,
-                      mutable ast::ident[][] testfns);
+                      mutable test[] testfns);
 
 // Traverse the crate, collecting all the test functions, eliding any
 // existing main functions, and synthesizing a main test harness
@@ -88,7 +91,9 @@ fn fold_item(&test_ctxt cx, &@ast::item i,
 
     if (is_test_fn(i)) {
         log "this is a test function";
-        cx.testfns += ~[cx.path];
+        auto test = rec(path = cx.path,
+                        ignore = is_ignored(i));
+        cx.testfns += ~[test];
         log #fmt("have %u test functions", ivec::len(cx.testfns));
     }
 
@@ -116,6 +121,10 @@ fn is_test_fn(&@ast::item i) -> bool {
     ret has_test_attr && has_test_signature(i);
 }
 
+fn is_ignored(&@ast::item i) -> bool {
+    attr::contains_name(attr::attr_metas(i.attrs), "ignore")
+}
+
 fn add_test_module(&test_ctxt cx, &ast::_mod m) -> ast::_mod {
     auto testmod = mk_test_module(cx);
     ret rec(items=m.items + ~[testmod] with m);
@@ -225,10 +234,9 @@ fn mk_test_desc_vec(&test_ctxt cx) -> @ast::expr {
     log #fmt("building test vector from %u tests",
              ivec::len(cx.testfns));
     auto descs = ~[];
-    for (ast::ident[] testpath in cx.testfns) {
-        log #fmt("encoding %s", ast::path_name_i(testpath));
-        auto path = testpath;
-        descs += ~[mk_test_desc_rec(cx, path)];
+    for (test test in cx.testfns) {
+        auto test_ = test; // Satisfy alias analysis
+        descs += ~[mk_test_desc_rec(cx, test_)];
     }
 
     ret @rec(id = cx.next_node_id(),
@@ -236,7 +244,10 @@ fn mk_test_desc_vec(&test_ctxt cx) -> @ast::expr {
              span = rec(lo=0u,hi=0u));
 }
 
-fn mk_test_desc_rec(&test_ctxt cx, ast::ident[] path) -> @ast::expr {
+fn mk_test_desc_rec(&test_ctxt cx, test test) -> @ast::expr {
+    auto path = test.path;
+
+    log #fmt("encoding %s", ast::path_name_i(path));
 
     let ast::lit name_lit = nospan(ast::lit_str(ast::path_name_i(path),
                                                 ast::sk_rc));
@@ -260,7 +271,19 @@ fn mk_test_desc_rec(&test_ctxt cx, ast::ident[] path) -> @ast::expr {
                                          ident = "fn",
                                          expr = @fn_expr));
 
-    let ast::expr_ desc_rec_ = ast::expr_rec(~[name_field, fn_field],
+    let ast::lit ignore_lit = nospan(ast::lit_bool(test.ignore));
+
+    let ast::expr ignore_expr = rec(id = cx.next_node_id(),
+                                    node = ast::expr_lit(@ignore_lit),
+                                    span = rec(lo=0u, hi=0u));
+
+    let ast::field ignore_field = nospan(rec(mut = ast::imm,
+                                             ident = "ignore",
+                                             expr = @ignore_expr));
+
+    let ast::expr_ desc_rec_ = ast::expr_rec(~[name_field,
+                                               fn_field,
+                                               ignore_field],
                                              option::none);
     let ast::expr desc_rec = rec(id = cx.next_node_id(),
                                  node = desc_rec_,