@@ -26,198 +26,6 @@ mod common;
26
26
#[legacy_exports]
27
27
mod errors;
28
28
29
- use std::getopts;
30
- use std::test;
31
-
32
- use core::result;
33
- use result::{Ok, Err};
34
-
35
- use common::config;
36
- use common::mode_run_pass;
37
- use common::mode_run_fail;
38
- use common::mode_compile_fail;
39
- use common::mode_pretty;
40
- use common::mode;
41
- use util::logv;
42
-
43
- fn main() {
44
- let args = os::args();
45
- let config = parse_config(args);
46
- log_config(config);
47
- run_tests(config);
48
- }
49
-
50
- fn parse_config(args: ~[~str]) -> config {
51
- let opts =
52
- ~[getopts::reqopt(~"compile-lib-path"),
53
- getopts::reqopt(~"run-lib-path"),
54
- getopts::reqopt(~"rustc-path"), getopts::reqopt(~"src-base"),
55
- getopts::reqopt(~"build-base"), getopts::reqopt(~"aux-base"),
56
- getopts::reqopt(~"stage-id"),
57
- getopts::reqopt(~"mode"), getopts::optflag(~"ignored"),
58
- getopts::optopt(~"runtool"), getopts::optopt(~"rustcflags"),
59
- getopts::optflag(~"verbose"),
60
- getopts::optopt(~"logfile"),
61
- getopts::optflag(~"jit")];
62
-
63
- assert (vec::is_not_empty(args));
64
- let args_ = vec::tail(args);
65
- let matches =
66
- &match getopts::getopts(args_, opts) {
67
- Ok(m) => m,
68
- Err(f) => fail getopts::fail_str(f)
69
- };
70
-
71
- fn opt_path(m: &getopts::Matches, nm: ~str) -> Path {
72
- Path(getopts::opt_str(m, nm))
73
- }
74
-
75
- return {compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"),
76
- run_lib_path: getopts::opt_str(matches, ~"run-lib-path"),
77
- rustc_path: opt_path(matches, ~"rustc-path"),
78
- src_base: opt_path(matches, ~"src-base"),
79
- build_base: opt_path(matches, ~"build-base"),
80
- aux_base: opt_path(matches, ~"aux-base"),
81
- stage_id: getopts::opt_str(matches, ~"stage-id"),
82
- mode: str_mode(getopts::opt_str(matches, ~"mode")),
83
- run_ignored: getopts::opt_present(matches, ~"ignored"),
84
- filter:
85
- if vec::len(matches.free) > 0u {
86
- option::Some(matches.free[0])
87
- } else { option::None },
88
- logfile: option::map(&getopts::opt_maybe_str(matches,
89
- ~"logfile"),
90
- |s| Path(*s)),
91
- runtool: getopts::opt_maybe_str(matches, ~"runtool"),
92
- rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
93
- jit: getopts::opt_present(matches, ~"jit"),
94
- verbose: getopts::opt_present(matches, ~"verbose")};
95
- }
96
-
97
- fn log_config(config: config) {
98
- let c = config;
99
- logv(c, fmt!("configuration:"));
100
- logv(c, fmt!("compile_lib_path: %s", config.compile_lib_path));
101
- logv(c, fmt!("run_lib_path: %s", config.run_lib_path));
102
- logv(c, fmt!("rustc_path: %s", config.rustc_path.to_str()));
103
- logv(c, fmt!("src_base: %s", config.src_base.to_str()));
104
- logv(c, fmt!("build_base: %s", config.build_base.to_str()));
105
- logv(c, fmt!("stage_id: %s", config.stage_id));
106
- logv(c, fmt!("mode: %s", mode_str(config.mode)));
107
- logv(c, fmt!("run_ignored: %b", config.run_ignored));
108
- logv(c, fmt!("filter: %s", opt_str(config.filter)));
109
- logv(c, fmt!("runtool: %s", opt_str(config.runtool)));
110
- logv(c, fmt!("rustcflags: %s", opt_str(config.rustcflags)));
111
- logv(c, fmt!("jit: %b", config.jit));
112
- logv(c, fmt!("verbose: %b", config.verbose));
113
- logv(c, fmt!("\n"));
114
- }
115
-
116
- fn opt_str(maybestr: Option<~str>) -> ~str {
117
- match maybestr { option::Some(s) => s, option::None => ~"(none)" }
118
- }
119
-
120
- fn str_opt(maybestr: ~str) -> Option<~str> {
121
- if maybestr != ~"(none)" { option::Some(maybestr) } else { option::None }
122
- }
123
-
124
- fn str_mode(s: ~str) -> mode {
125
- match s {
126
- ~"compile-fail" => mode_compile_fail,
127
- ~"run-fail" => mode_run_fail,
128
- ~"run-pass" => mode_run_pass,
129
- ~"pretty" => mode_pretty,
130
- _ => fail ~"invalid mode"
131
- }
132
- }
133
-
134
- fn mode_str(mode: mode) -> ~str {
135
- match mode {
136
- mode_compile_fail => ~"compile-fail",
137
- mode_run_fail => ~"run-fail",
138
- mode_run_pass => ~"run-pass",
139
- mode_pretty => ~"pretty"
140
- }
141
- }
142
-
143
- fn run_tests(config: config) {
144
- let opts = test_opts(config);
145
- let tests = make_tests(config);
146
- let res = test::run_tests_console(&opts, tests);
147
- if !res { fail ~"Some tests failed"; }
148
- }
149
-
150
- fn test_opts(config: config) -> test::TestOpts {
151
- {filter:
152
- match config.filter {
153
- option::Some(s) => option::Some(s),
154
- option::None => option::None
155
- },
156
- run_ignored: config.run_ignored,
157
- logfile:
158
- match config.logfile {
159
- option::Some(s) => option::Some(s.to_str()),
160
- option::None => option::None
161
- }
162
- }
163
- }
164
-
165
- fn make_tests(config: config) -> ~[test::TestDesc] {
166
- debug!("making tests from %s",
167
- config.src_base.to_str());
168
- let mut tests = ~[];
169
- for os::list_dir_path(&config.src_base).each |file| {
170
- let file = copy *file;
171
- debug!("inspecting file %s", file.to_str());
172
- if is_test(config, file) {
173
- tests.push(make_test(config, file))
174
- }
175
- }
176
- move tests
177
- }
178
-
179
- fn is_test(config: config, testfile: &Path) -> bool {
180
- // Pretty-printer does not work with .rc files yet
181
- let valid_extensions =
182
- match config.mode {
183
- mode_pretty => ~[~".rs"],
184
- _ => ~[~".rc", ~".rs"]
185
- };
186
- let invalid_prefixes = ~[~".", ~"#", ~"~"];
187
- let name = testfile.filename().get();
188
-
189
- let mut valid = false;
190
-
191
- for valid_extensions.each |ext| {
192
- if str::ends_with(name, *ext) { valid = true; }
193
- }
194
-
195
- for invalid_prefixes.each |pre| {
196
- if str::starts_with(name, *pre) { valid = false; }
197
- }
198
-
199
- return valid;
200
- }
201
-
202
- fn make_test(config: config, testfile: &Path) ->
203
- test::TestDesc {
204
- {
205
- name: make_test_name(config, testfile),
206
- testfn: make_test_closure(config, testfile),
207
- ignore: header::is_test_ignored(config, testfile),
208
- should_fail: false
209
- }
210
- }
211
-
212
- fn make_test_name(config: config, testfile: &Path) -> ~str {
213
- fmt!("[%s] %s", mode_str(config.mode), testfile.to_str())
214
- }
215
-
216
- fn make_test_closure(config: config, testfile: &Path) -> test::TestFn {
217
- let testfile = testfile.to_str();
218
- fn~() { runtest::run(config, testfile) }
219
- }
220
-
221
29
// Local Variables:
222
30
// fill-column: 78;
223
31
// indent-tabs-mode: nil
0 commit comments