about summary refs log tree commit diff
path: root/src/comp/front
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-07-08 20:52:54 -0700
committerBrian Anderson <banderson@mozilla.com>2011-07-09 12:35:30 -0700
commit5543404abe2ecfe280ffd4393d4e4c9ad3d489b8 (patch)
tree6413f156d3d7744c20d644f457a4715eb877edf3 /src/comp/front
parent9af59f9d81b8d8c91e2c470e82813d75a6bcdc9e (diff)
downloadrust-5543404abe2ecfe280ffd4393d4e4c9ad3d489b8.tar.gz
rust-5543404abe2ecfe280ffd4393d4e4c9ad3d489b8.zip
Track the path as we fold over the AST looking for unit tests. Issue #428
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/test.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs
index 0f93e61a410..101a8e5cc89 100644
--- a/src/comp/front/test.rs
+++ b/src/comp/front/test.rs
@@ -1,6 +1,7 @@
 // Code that generates a test runner to run all the tests in a crate
 
 import std::option;
+import std::ivec;
 import syntax::ast;
 import syntax::fold;
 
@@ -8,7 +9,8 @@ export modify_for_testing;
 
 type node_id_gen = @fn() -> ast::node_id;
 
-type test_ctxt = rec(node_id_gen next_node_id);
+type test_ctxt = rec(node_id_gen next_node_id,
+                     mutable ast::ident[] path);
 
 // Traverse the crate, collecting all the test functions, eliding any
 // existing main functions, and synthesizing a main test harness
@@ -26,9 +28,11 @@ fn modify_for_testing(@ast::crate crate) -> @ast::crate {
         ret this_node_id;
     } (next_node_id);
 
-    auto cx = rec(next_node_id = next_node_id_fn);
+    auto cx = rec(next_node_id = next_node_id_fn,
+                  mutable path = ~[]);
 
-    auto precursor = rec(fold_crate = bind fold_crate(cx, _, _)
+    auto precursor = rec(fold_crate = bind fold_crate(cx, _, _),
+                         fold_item = bind fold_item(cx, _, _)
                          with *fold::default_ast_fold());
 
     auto fold = fold::make_fold(precursor);
@@ -94,6 +98,16 @@ fn mk_main(&test_ctxt cx) -> @ast::item {
     ret @item;
 }
 
+fn fold_item(&test_ctxt cx, &@ast::item i,
+             fold::ast_fold fld) -> @ast::item {
+
+    cx.path += ~[i.ident];
+    log #fmt("current path: %s", ast::path_name_i(cx.path));
+    auto res = fold::noop_fold_item(i, fld);
+    ivec::pop(cx.path);
+    ret res;
+}
+
 // Local Variables:
 // mode: rust
 // fill-column: 78;