diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-07-30 08:53:22 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-08-04 14:02:36 -0700 |
| commit | 0d8340327c03f319b49cb91e2e64aa66dd1e76c7 (patch) | |
| tree | 308af0af76da6c6a020ee5e8d9e5dbb40152307a /src/libsyntax | |
| parent | 5cccf3cd256420d9f32c265e83036dea1d5f94d8 (diff) | |
| download | rust-0d8340327c03f319b49cb91e2e64aa66dd1e76c7.tar.gz rust-0d8340327c03f319b49cb91e2e64aa66dd1e76c7.zip | |
syntax: Don't assume `std` exists for tests
This commit removes the injection of `std::env::args()` from `--test` expanded code, relying on the test runner itself to call this funciton. This is more hygienic because we can't assume that `std` exists at the top layer all the time, and it meaks the injected test module entirely self contained.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/test.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 2408e6b65a3..ea99291d6c2 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -450,18 +450,11 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> { // test::test_main_static let test_main_path = ecx.path(sp, vec![token::str_to_ident("test"), token::str_to_ident("test_main_static")]); - // ::std::env::args - let os_args_path = ecx.path_global(sp, vec![token::str_to_ident("std"), - token::str_to_ident("env"), - token::str_to_ident("args")]); - // ::std::env::args() - let os_args_path_expr = ecx.expr_path(os_args_path); - let call_os_args = ecx.expr_call(sp, os_args_path_expr, vec![]); // test::test_main_static(...) let test_main_path_expr = ecx.expr_path(test_main_path); let tests_ident_expr = ecx.expr_ident(sp, token::str_to_ident("TESTS")); let call_test_main = ecx.expr_call(sp, test_main_path_expr, - vec![call_os_args, tests_ident_expr]); + vec![tests_ident_expr]); let call_test_main = ecx.stmt_expr(call_test_main); // #![main] let main_meta = ecx.meta_word(sp, token::intern_and_get_ident("main")); @@ -634,12 +627,14 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> { let fail_expr = match test.should_panic { ShouldPanic::No => ecx.expr_path(should_panic_path("No")), ShouldPanic::Yes(ref msg) => { - let path = should_panic_path("Yes"); - let arg = match *msg { - Some(ref msg) => ecx.expr_some(span, ecx.expr_str(span, msg.clone())), - None => ecx.expr_none(span), - }; - ecx.expr_call(span, ecx.expr_path(path), vec![arg]) + match *msg { + Some(ref msg) => { + let msg = ecx.expr_str(span, msg.clone()); + let path = should_panic_path("YesWithMessage"); + ecx.expr_call(span, ecx.expr_path(path), vec![msg]) + } + None => ecx.expr_path(should_panic_path("Yes")), + } } }; |
