Skip to content

Commit 6b22640

Browse files
committed
Convert std::test to istrs. Issue #855
1 parent 775b64c commit 6b22640

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

src/comp/front/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
253253
ast_util::path_name_i(path)];
254254

255255
let name_lit: ast::lit =
256-
nospan(ast::lit_str(ast_util::path_name_i(path), ast::sk_rc));
256+
nospan(ast::lit_str(ast_util::path_name_i(path), ast::sk_unique));
257257
let name_expr: ast::expr =
258258
{id: cx.next_node_id(),
259259
node: ast::expr_lit(@name_lit),
@@ -291,7 +291,7 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
291291

292292
fn mk_main(cx: &test_ctxt) -> @ast::item {
293293

294-
let args_mt: ast::mt = {ty: @nospan(ast::ty_str), mut: ast::imm};
294+
let args_mt: ast::mt = {ty: @nospan(ast::ty_istr), mut: ast::imm};
295295
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
296296

297297
let args_arg: ast::arg =

src/lib/test.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ native "rust" mod rustrt {
3535
// paths, i.e it should be a series of identifiers seperated by double
3636
// colons. This way if some test runner wants to arrange the tests
3737
// heirarchically it may.
38-
type test_name = str;
38+
type test_name = istr;
3939

4040
// A function that runs a test. If the function returns successfully,
4141
// 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};
4949

5050
// The default console test runner. It accepts the command line
5151
// arguments and a vector of test_descs (generated at compile time).
52-
fn test_main(args: &[str], tests: &[test_desc]) {
52+
fn test_main(args: &[istr], tests: &[test_desc]) {
5353
check (vec::is_not_empty(args));
5454
let opts =
5555
alt parse_opts(args) {
@@ -59,26 +59,26 @@ fn test_main(args: &[str], tests: &[test_desc]) {
5959
if !run_tests_console(opts, tests) { fail "Some tests failed"; }
6060
}
6161

62-
type test_opts = {filter: option::t<str>, run_ignored: bool};
62+
type test_opts = {filter: option::t<istr>, run_ignored: bool};
6363

64-
type opt_res = either::t<test_opts, str>;
64+
type opt_res = either::t<test_opts, istr>;
6565

6666
// Parses command line arguments into test options
67-
fn parse_opts(args: &[str]) : vec::is_not_empty(args) -> opt_res {
67+
fn parse_opts(args: &[istr]) : vec::is_not_empty(args) -> opt_res {
6868

69-
let args_ = istr::from_estrs(vec::tail(args));
69+
let args_ = vec::tail(args);
7070
let opts = [getopts::optflag(~"ignored")];
7171
let match =
7272
alt getopts::getopts(args_, opts) {
7373
getopts::success(m) { m }
7474
getopts::failure(f) {
75-
ret either::right(istr::to_estr(getopts::fail_str(f)))
75+
ret either::right(getopts::fail_str(f))
7676
}
7777
};
7878

7979
let filter =
8080
if vec::len(match.free) > 0u {
81-
option::some(istr::to_estr(match.free[0]))
81+
option::some(match.free[0])
8282
} else { option::none };
8383

8484
let run_ignored = getopts::opt_present(match, ~"ignored");
@@ -124,7 +124,7 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
124124
}
125125
te_wait(test) {
126126
st.out.write_str(
127-
#ifmt["test %s ... ", istr::from_estr(test.name)]);
127+
#ifmt["test %s ... ", test.name]);
128128
}
129129
te_result(test, result) {
130130
alt result {
@@ -167,7 +167,7 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
167167
st.out.write_line(~"\nfailures:");
168168
for test: test_desc in st.failures {
169169
let testname = test.name; // Satisfy alias analysis
170-
st.out.write_line(#ifmt[" %s", istr::from_estr(testname)]);
170+
st.out.write_line(#ifmt[" %s", testname]);
171171
}
172172
}
173173

@@ -259,13 +259,13 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] {
259259
let filter_str =
260260
alt opts.filter {
261261
option::some(f) { f }
262-
option::none. { "" }
262+
option::none. { ~"" }
263263
};
264264

265265
let filter =
266-
bind fn (test: &test_desc, filter_str: str) ->
266+
bind fn (test: &test_desc, filter_str: &istr) ->
267267
option::t<test_desc> {
268-
if str::find(test.name, filter_str) >= 0 {
268+
if istr::find(test.name, filter_str) >= 0 {
269269
ret option::some(test);
270270
} else { ret option::none; }
271271
}(_, filter_str);
@@ -296,7 +296,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] {
296296
filtered =
297297
{
298298
fn lteq(t1: &test_desc, t2: &test_desc) -> bool {
299-
str::lteq(t1.name, t2.name)
299+
istr::lteq(t1.name, t2.name)
300300
}
301301
sort::merge_sort(lteq, filtered)
302302
};

src/test/compiletest/compiletest.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn run_tests(config: &config) {
130130
fn test_opts(config: &config) -> test::test_opts {
131131
{
132132
filter: alt config.filter {
133-
option::some(s) { option::some(istr::to_estr(s)) }
133+
option::some(s) { option::some(s) }
134134
option::none. { option::none }
135135
},
136136
run_ignored: config.run_ignored
@@ -183,10 +183,8 @@ fn make_test(cx: &cx, testfile: &istr, configport: &port<[u8]>) ->
183183
ignore: header::is_test_ignored(cx.config, testfile)}
184184
}
185185

186-
fn make_test_name(config: &config, testfile: &istr) -> str {
187-
istr::to_estr(
188-
#ifmt["[%s] %s", mode_str(config.mode),
189-
testfile])
186+
fn make_test_name(config: &config, testfile: &istr) -> istr {
187+
#ifmt["[%s] %s", mode_str(config.mode), testfile]
190188
}
191189

192190
/*

src/test/stdtest/test.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import std::test;
2-
import std::str;
2+
import std::istr;
33
import std::option;
44
import std::either;
55
import std::vec;
@@ -9,7 +9,7 @@ fn do_not_run_ignored_tests() {
99
let ran = @mutable false;
1010
let f = bind fn (ran: @mutable bool) { *ran = true; }(ran);
1111

12-
let desc = {name: "whatever", fn: f, ignore: true};
12+
let desc = {name: ~"whatever", fn: f, ignore: true};
1313

1414
test::run_test(desc, test::default_test_to_task);
1515

@@ -19,22 +19,22 @@ fn do_not_run_ignored_tests() {
1919
#[test]
2020
fn ignored_tests_result_in_ignored() {
2121
fn f() { }
22-
let desc = {name: "whatever", fn: f, ignore: true};
22+
let desc = {name: ~"whatever", fn: f, ignore: true};
2323
let res = test::run_test(desc, test::default_test_to_task).wait();
2424
assert (res == test::tr_ignored);
2525
}
2626

2727
#[test]
2828
fn first_free_arg_should_be_a_filter() {
29-
let args = ["progname", "filter"];
29+
let args = [~"progname", ~"filter"];
3030
check (vec::is_not_empty(args));
3131
let opts = alt test::parse_opts(args) { either::left(o) { o } };
32-
assert (str::eq("filter", option::get(opts.filter)));
32+
assert (istr::eq(~"filter", option::get(opts.filter)));
3333
}
3434

3535
#[test]
3636
fn parse_ignored_flag() {
37-
let args = ["progname", "filter", "--ignored"];
37+
let args = [~"progname", ~"filter", ~"--ignored"];
3838
check (vec::is_not_empty(args));
3939
let opts = alt test::parse_opts(args) { either::left(o) { o } };
4040
assert (opts.run_ignored);
@@ -47,12 +47,12 @@ fn filter_for_ignored_option() {
4747

4848
let opts = {filter: option::none, run_ignored: true};
4949
let tests =
50-
[{name: "1", fn: fn () { }, ignore: true},
51-
{name: "2", fn: fn () { }, ignore: false}];
50+
[{name: ~"1", fn: fn () { }, ignore: true},
51+
{name: ~"2", fn: fn () { }, ignore: false}];
5252
let filtered = test::filter_tests(opts, tests);
5353

5454
assert (vec::len(filtered) == 1u);
55-
assert (filtered[0].name == "1");
55+
assert (filtered[0].name == ~"1");
5656
assert (filtered[0].ignore == false);
5757
}
5858

@@ -61,17 +61,17 @@ fn sort_tests() {
6161
let opts = {filter: option::none, run_ignored: false};
6262

6363
let names =
64-
["sha1::test", "int::test_to_str", "int::test_pow",
65-
"test::do_not_run_ignored_tests",
66-
"test::ignored_tests_result_in_ignored",
67-
"test::first_free_arg_should_be_a_filter",
68-
"test::parse_ignored_flag", "test::filter_for_ignored_option",
69-
"test::sort_tests"];
64+
[~"sha1::test", ~"int::test_to_str", ~"int::test_pow",
65+
~"test::do_not_run_ignored_tests",
66+
~"test::ignored_tests_result_in_ignored",
67+
~"test::first_free_arg_should_be_a_filter",
68+
~"test::parse_ignored_flag", ~"test::filter_for_ignored_option",
69+
~"test::sort_tests"];
7070
let tests =
7171
{
7272
let testfn = fn () { };
7373
let tests = [];
74-
for name: str in names {
74+
for name: istr in names {
7575
let test = {name: name, fn: testfn, ignore: false};
7676
tests += [test];
7777
}
@@ -80,11 +80,13 @@ fn sort_tests() {
8080
let filtered = test::filter_tests(opts, tests);
8181

8282
let expected =
83-
["int::test_pow", "int::test_to_str", "sha1::test",
84-
"test::do_not_run_ignored_tests", "test::filter_for_ignored_option",
85-
"test::first_free_arg_should_be_a_filter",
86-
"test::ignored_tests_result_in_ignored", "test::parse_ignored_flag",
87-
"test::sort_tests"];
83+
[~"int::test_pow", ~"int::test_to_str", ~"sha1::test",
84+
~"test::do_not_run_ignored_tests",
85+
~"test::filter_for_ignored_option",
86+
~"test::first_free_arg_should_be_a_filter",
87+
~"test::ignored_tests_result_in_ignored",
88+
~"test::parse_ignored_flag",
89+
~"test::sort_tests"];
8890

8991
check vec::same_length(expected, filtered);
9092
let pairs = vec::zip(expected, filtered);

0 commit comments

Comments
 (0)