about summary refs log tree commit diff
path: root/src/comp/front/test.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-07-11 15:57:11 -0700
committerBrian Anderson <banderson@mozilla.com>2011-07-11 19:01:53 -0700
commit94e1b362f06cba2f2cc894cff44d0fdde4cb204a (patch)
tree57be4d2131ff5b0b84ff54180549a8875a518567 /src/comp/front/test.rs
parent2e46438507e95462f38f28c3a03acd5cd00e8890 (diff)
downloadrust-94e1b362f06cba2f2cc894cff44d0fdde4cb204a.tar.gz
rust-94e1b362f06cba2f2cc894cff44d0fdde4cb204a.zip
Pass command-line args to the test runner. Issue #428
This will let the test runner filter the tests it runs.
Diffstat (limited to 'src/comp/front/test.rs')
-rw-r--r--src/comp/front/test.rs33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs
index ae047b01a77..ca7f3b69d7a 100644
--- a/src/comp/front/test.rs
+++ b/src/comp/front/test.rs
@@ -249,11 +249,20 @@ fn mk_test_desc_rec(&test_ctxt cx, ast::ident[] path) -> @ast::expr {
 }
 
 fn mk_main(&test_ctxt cx) -> @ast::item {
-    auto ret_ty = @rec(node=ast::ty_int,
-                       span=rec(lo=0u, hi=0u));
 
-    let ast::fn_decl decl = rec(inputs = ~[],
-                                output = ret_ty,
+    let ast::mt args_mt = rec(ty = @nospan(ast::ty_str),
+                              mut = ast::imm);
+    let ast::ty args_ty = nospan(ast::ty_vec(args_mt));
+
+    let ast::arg args_arg = rec(mode = ast::val,
+                                ty = @args_ty,
+                                ident = "args",
+                                id = cx.next_node_id());
+
+    auto ret_ty = nospan(ast::ty_int);
+
+    let ast::fn_decl decl = rec(inputs = ~[args_arg],
+                                output = @ret_ty,
                                 purity = ast::impure_fn,
                                 cf = ast::return,
                                 constraints = ~[]);
@@ -281,6 +290,18 @@ fn mk_main(&test_ctxt cx) -> @ast::item {
 
 fn mk_test_main_call(&test_ctxt cx) -> @ast::expr {
 
+    // Get the args passed to main so we can pass the to test_main
+    let ast::path args_path = nospan(rec(global = false,
+                                         idents = ~["args"],
+                                         types = ~[]));
+
+    let ast::expr_ args_path_expr_ = ast::expr_path(args_path);
+
+    let ast::expr args_path_expr = rec(id = cx.next_node_id(),
+                                       node = args_path_expr_,
+                                       span = rec(lo=0u, hi=0u));
+
+    // Call __test::test to generate the vector of test_descs
     let ast::path test_path = nospan(rec(global = false,
                                          idents = ~["tests"],
                                          types = ~[]));
@@ -297,6 +318,7 @@ fn mk_test_main_call(&test_ctxt cx) -> @ast::expr {
                                        node = test_call_expr_,
                                        span = rec(lo=0u, hi=0u));
 
+    // Call std::test::test_main
     let ast::path test_main_path = nospan(rec(global = false,
                                               idents = ~["std",
                                                          "test",
@@ -311,7 +333,8 @@ fn mk_test_main_call(&test_ctxt cx) -> @ast::expr {
                                             span = rec(lo=0u, hi=0u));
 
     let ast::expr_ test_main_call_expr_ 
-        = ast::expr_call(@test_main_path_expr, ~[@test_call_expr]);
+        = ast::expr_call(@test_main_path_expr, ~[@args_path_expr,
+                                                 @test_call_expr]);
 
     let ast::expr test_main_call_expr = rec(id = cx.next_node_id(),
                                             node = test_main_call_expr_,