mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-10 06:47:34 +00:00
Add and use an ivec interface to std::test
This commit is contained in:
parent
053b8bff5a
commit
184eac90ab
@ -135,7 +135,7 @@ We're going to be building a module that looks more or less like:
|
|||||||
|
|
||||||
mod __test {
|
mod __test {
|
||||||
|
|
||||||
fn main(vec[str] args) -> int {
|
fn main(args: [str]) -> int {
|
||||||
std::test::test_main(args, tests())
|
std::test::test_main(args, tests())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
|
|||||||
fn mk_main(cx: &test_ctxt) -> @ast::item {
|
fn mk_main(cx: &test_ctxt) -> @ast::item {
|
||||||
|
|
||||||
let args_mt: ast::mt = {ty: @nospan(ast::ty_str), mut: ast::imm};
|
let args_mt: ast::mt = {ty: @nospan(ast::ty_str), mut: ast::imm};
|
||||||
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
|
let args_ty: ast::ty = nospan(ast::ty_ivec(args_mt));
|
||||||
|
|
||||||
let args_arg: ast::arg =
|
let args_arg: ast::arg =
|
||||||
{mode: ast::val, ty: @args_ty, ident: "args", id: cx.next_node_id()};
|
{mode: ast::val, ty: @args_ty, ident: "args", id: cx.next_node_id()};
|
||||||
@ -355,7 +355,7 @@ fn mk_test_main_call(cx: &test_ctxt) -> @ast::expr {
|
|||||||
// Call std::test::test_main
|
// Call std::test::test_main
|
||||||
let test_main_path: ast::path =
|
let test_main_path: ast::path =
|
||||||
nospan({global: false,
|
nospan({global: false,
|
||||||
idents: ~["std", "test", "test_main"],
|
idents: ~["std", "test", "test_main_ivec"],
|
||||||
types: ~[]});
|
types: ~[]});
|
||||||
|
|
||||||
let test_main_path_expr_: ast::expr_ = ast::expr_path(test_main_path);
|
let test_main_path_expr_: ast::expr_ = ast::expr_path(test_main_path);
|
||||||
|
@ -10,6 +10,7 @@ export test_name;
|
|||||||
export test_fn;
|
export test_fn;
|
||||||
export test_desc;
|
export test_desc;
|
||||||
export test_main;
|
export test_main;
|
||||||
|
export test_main_ivec;
|
||||||
export test_result;
|
export test_result;
|
||||||
export test_opts;
|
export test_opts;
|
||||||
export tr_ok;
|
export tr_ok;
|
||||||
@ -48,18 +49,20 @@ type test_desc = {name: test_name, fn: test_fn, ignore: bool};
|
|||||||
|
|
||||||
// The default console test runner. It accepts the command line
|
// The default console test runner. It accepts the command line
|
||||||
// arguments and a vector of test_descs (generated at compile time).
|
// arguments and a vector of test_descs (generated at compile time).
|
||||||
fn test_main(args: &vec[str], tests: &[test_desc]) {
|
fn test_main_ivec(args: &[str], tests: &[test_desc]) {
|
||||||
let ivec_args =
|
check (ivec::is_not_empty(args));
|
||||||
{ let iargs = ~[]; for arg: str in args { iargs += ~[arg] } iargs };
|
|
||||||
check (ivec::is_not_empty(ivec_args));
|
|
||||||
let opts =
|
let opts =
|
||||||
alt parse_opts(ivec_args) {
|
alt parse_opts(args) {
|
||||||
either::left(o) { o }
|
either::left(o) { o }
|
||||||
either::right(m) { fail m }
|
either::right(m) { fail m }
|
||||||
};
|
};
|
||||||
if !run_tests_console(opts, tests) { fail "Some tests failed"; }
|
if !run_tests_console(opts, tests) { fail "Some tests failed"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_main(args: &vec[str], tests: &[test_desc]) {
|
||||||
|
test_main_ivec(ivec::from_vec(args), tests);
|
||||||
|
}
|
||||||
|
|
||||||
type test_opts = {filter: option::t[str], run_ignored: bool};
|
type test_opts = {filter: option::t[str], run_ignored: bool};
|
||||||
|
|
||||||
type opt_res = either::t[test_opts, str];
|
type opt_res = either::t[test_opts, str];
|
||||||
|
Loading…
Reference in New Issue
Block a user