Convert std::test to istrs. Issue #855

This commit is contained in:
Brian Anderson 2011-08-31 16:56:38 -07:00
parent 775b64c955
commit 6b22640a1f
4 changed files with 42 additions and 42 deletions

View file

@ -253,7 +253,7 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
ast_util::path_name_i(path)];
let name_lit: ast::lit =
nospan(ast::lit_str(ast_util::path_name_i(path), ast::sk_rc));
nospan(ast::lit_str(ast_util::path_name_i(path), ast::sk_unique));
let name_expr: ast::expr =
{id: cx.next_node_id(),
node: ast::expr_lit(@name_lit),
@ -291,7 +291,7 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
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_istr), mut: ast::imm};
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
let args_arg: ast::arg =

View file

@ -35,7 +35,7 @@ native "rust" mod rustrt {
// paths, i.e it should be a series of identifiers seperated by double
// colons. This way if some test runner wants to arrange the tests
// heirarchically it may.
type test_name = str;
type test_name = istr;
// A function that runs a test. If the function returns successfully,
// the test succeeds; if the function fails then the test fails. We
@ -49,7 +49,7 @@ type test_desc = {name: test_name, fn: test_fn, ignore: bool};
// The default console test runner. It accepts the command line
// arguments and a vector of test_descs (generated at compile time).
fn test_main(args: &[str], tests: &[test_desc]) {
fn test_main(args: &[istr], tests: &[test_desc]) {
check (vec::is_not_empty(args));
let opts =
alt parse_opts(args) {
@ -59,26 +59,26 @@ fn test_main(args: &[str], tests: &[test_desc]) {
if !run_tests_console(opts, tests) { fail "Some tests failed"; }
}
type test_opts = {filter: option::t<str>, run_ignored: bool};
type test_opts = {filter: option::t<istr>, run_ignored: bool};
type opt_res = either::t<test_opts, str>;
type opt_res = either::t<test_opts, istr>;
// Parses command line arguments into test options
fn parse_opts(args: &[str]) : vec::is_not_empty(args) -> opt_res {
fn parse_opts(args: &[istr]) : vec::is_not_empty(args) -> opt_res {
let args_ = istr::from_estrs(vec::tail(args));
let args_ = vec::tail(args);
let opts = [getopts::optflag(~"ignored")];
let match =
alt getopts::getopts(args_, opts) {
getopts::success(m) { m }
getopts::failure(f) {
ret either::right(istr::to_estr(getopts::fail_str(f)))
ret either::right(getopts::fail_str(f))
}
};
let filter =
if vec::len(match.free) > 0u {
option::some(istr::to_estr(match.free[0]))
option::some(match.free[0])
} else { option::none };
let run_ignored = getopts::opt_present(match, ~"ignored");
@ -124,7 +124,7 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
}
te_wait(test) {
st.out.write_str(
#ifmt["test %s ... ", istr::from_estr(test.name)]);
#ifmt["test %s ... ", test.name]);
}
te_result(test, result) {
alt result {
@ -167,7 +167,7 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
st.out.write_line(~"\nfailures:");
for test: test_desc in st.failures {
let testname = test.name; // Satisfy alias analysis
st.out.write_line(#ifmt[" %s", istr::from_estr(testname)]);
st.out.write_line(#ifmt[" %s", testname]);
}
}
@ -259,13 +259,13 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] {
let filter_str =
alt opts.filter {
option::some(f) { f }
option::none. { "" }
option::none. { ~"" }
};
let filter =
bind fn (test: &test_desc, filter_str: str) ->
bind fn (test: &test_desc, filter_str: &istr) ->
option::t<test_desc> {
if str::find(test.name, filter_str) >= 0 {
if istr::find(test.name, filter_str) >= 0 {
ret option::some(test);
} else { ret option::none; }
}(_, filter_str);
@ -296,7 +296,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] {
filtered =
{
fn lteq(t1: &test_desc, t2: &test_desc) -> bool {
str::lteq(t1.name, t2.name)
istr::lteq(t1.name, t2.name)
}
sort::merge_sort(lteq, filtered)
};

View file

@ -130,7 +130,7 @@ fn run_tests(config: &config) {
fn test_opts(config: &config) -> test::test_opts {
{
filter: alt config.filter {
option::some(s) { option::some(istr::to_estr(s)) }
option::some(s) { option::some(s) }
option::none. { option::none }
},
run_ignored: config.run_ignored
@ -183,10 +183,8 @@ fn make_test(cx: &cx, testfile: &istr, configport: &port<[u8]>) ->
ignore: header::is_test_ignored(cx.config, testfile)}
}
fn make_test_name(config: &config, testfile: &istr) -> str {
istr::to_estr(
#ifmt["[%s] %s", mode_str(config.mode),
testfile])
fn make_test_name(config: &config, testfile: &istr) -> istr {
#ifmt["[%s] %s", mode_str(config.mode), testfile]
}
/*

View file

@ -1,5 +1,5 @@
import std::test;
import std::str;
import std::istr;
import std::option;
import std::either;
import std::vec;
@ -9,7 +9,7 @@ fn do_not_run_ignored_tests() {
let ran = @mutable false;
let f = bind fn (ran: @mutable bool) { *ran = true; }(ran);
let desc = {name: "whatever", fn: f, ignore: true};
let desc = {name: ~"whatever", fn: f, ignore: true};
test::run_test(desc, test::default_test_to_task);
@ -19,22 +19,22 @@ fn do_not_run_ignored_tests() {
#[test]
fn ignored_tests_result_in_ignored() {
fn f() { }
let desc = {name: "whatever", fn: f, ignore: true};
let desc = {name: ~"whatever", fn: f, ignore: true};
let res = test::run_test(desc, test::default_test_to_task).wait();
assert (res == test::tr_ignored);
}
#[test]
fn first_free_arg_should_be_a_filter() {
let args = ["progname", "filter"];
let args = [~"progname", ~"filter"];
check (vec::is_not_empty(args));
let opts = alt test::parse_opts(args) { either::left(o) { o } };
assert (str::eq("filter", option::get(opts.filter)));
assert (istr::eq(~"filter", option::get(opts.filter)));
}
#[test]
fn parse_ignored_flag() {
let args = ["progname", "filter", "--ignored"];
let args = [~"progname", ~"filter", ~"--ignored"];
check (vec::is_not_empty(args));
let opts = alt test::parse_opts(args) { either::left(o) { o } };
assert (opts.run_ignored);
@ -47,12 +47,12 @@ fn filter_for_ignored_option() {
let opts = {filter: option::none, run_ignored: true};
let tests =
[{name: "1", fn: fn () { }, ignore: true},
{name: "2", fn: fn () { }, ignore: false}];
[{name: ~"1", fn: fn () { }, ignore: true},
{name: ~"2", fn: fn () { }, ignore: false}];
let filtered = test::filter_tests(opts, tests);
assert (vec::len(filtered) == 1u);
assert (filtered[0].name == "1");
assert (filtered[0].name == ~"1");
assert (filtered[0].ignore == false);
}
@ -61,17 +61,17 @@ fn sort_tests() {
let opts = {filter: option::none, run_ignored: false};
let names =
["sha1::test", "int::test_to_str", "int::test_pow",
"test::do_not_run_ignored_tests",
"test::ignored_tests_result_in_ignored",
"test::first_free_arg_should_be_a_filter",
"test::parse_ignored_flag", "test::filter_for_ignored_option",
"test::sort_tests"];
[~"sha1::test", ~"int::test_to_str", ~"int::test_pow",
~"test::do_not_run_ignored_tests",
~"test::ignored_tests_result_in_ignored",
~"test::first_free_arg_should_be_a_filter",
~"test::parse_ignored_flag", ~"test::filter_for_ignored_option",
~"test::sort_tests"];
let tests =
{
let testfn = fn () { };
let tests = [];
for name: str in names {
for name: istr in names {
let test = {name: name, fn: testfn, ignore: false};
tests += [test];
}
@ -80,11 +80,13 @@ fn sort_tests() {
let filtered = test::filter_tests(opts, tests);
let expected =
["int::test_pow", "int::test_to_str", "sha1::test",
"test::do_not_run_ignored_tests", "test::filter_for_ignored_option",
"test::first_free_arg_should_be_a_filter",
"test::ignored_tests_result_in_ignored", "test::parse_ignored_flag",
"test::sort_tests"];
[~"int::test_pow", ~"int::test_to_str", ~"sha1::test",
~"test::do_not_run_ignored_tests",
~"test::filter_for_ignored_option",
~"test::first_free_arg_should_be_a_filter",
~"test::ignored_tests_result_in_ignored",
~"test::parse_ignored_flag",
~"test::sort_tests"];
check vec::same_length(expected, filtered);
let pairs = vec::zip(expected, filtered);