diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-07-06 14:29:50 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-07-06 14:39:36 -0700 |
| commit | b06ccb45abb5c9ea0b55c8ff8a32831188c2403f (patch) | |
| tree | becc2cf1cb9bbb9c109a86e69993a1dabfc5aa9b /src/comp/front/test.rs | |
| parent | 0eac640fdd56caa93d5f398a75d24e62feef4730 (diff) | |
| download | rust-b06ccb45abb5c9ea0b55c8ff8a32831188c2403f.tar.gz rust-b06ccb45abb5c9ea0b55c8ff8a32831188c2403f.zip | |
Begin adding unit testing infrastructure to the compiler
Add a --test flag and a pass for transforming the AST to generate a test harness. Issue #428
Diffstat (limited to 'src/comp/front/test.rs')
| -rw-r--r-- | src/comp/front/test.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs new file mode 100644 index 00000000000..376efc7932e --- /dev/null +++ b/src/comp/front/test.rs @@ -0,0 +1,44 @@ +import driver::session; +import syntax::ast; +import syntax::fold; + +export modify_for_testing; + +type test_ctxt = rec(@session::session sess); + +// Traverse the crate, collecting all the test functions, eliding any +// existing main functions, and synthesizing a main test harness +fn modify_for_testing(&session::session sess, + @ast::crate crate) -> @ast::crate { + + auto cx = rec(sess = @sess); + + auto precursor = rec(fold_crate = bind fold_crate(cx, _, _) + with *fold::default_ast_fold()); + + auto fold = fold::make_fold(precursor); + auto res = @fold.fold_crate(*crate); + // FIXME: This is necessary to break a circular reference + fold::dummy_out(fold); + ret res; +} + +fn fold_crate(&test_ctxt cx, &ast::crate_ c, + fold::ast_fold fld) -> ast::crate_ { + auto folded = fold::noop_fold_crate(c, fld); + ret rec(module = add_test_module(folded.module) + with folded); +} + +fn add_test_module(&ast::_mod m) -> ast::_mod { + ret m; +} + +// Local Variables: +// mode: rust +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; +// End: |
