Skip to content

Commit 5e10686

Browse files
committed
auto merge of #14233 : pcwalton/rust/detildestr-morelibs, r=alexcrichton
r? @alexcrichton
2 parents 25c5422 + b84c0dc commit 5e10686

File tree

39 files changed

+1350
-1005
lines changed

39 files changed

+1350
-1005
lines changed

src/compiletest/common.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ impl fmt::Show for Mode {
5656
#[deriving(Clone)]
5757
pub struct Config {
5858
// The library paths required for running the compiler
59-
pub compile_lib_path: ~str,
59+
pub compile_lib_path: StrBuf,
6060

6161
// The library paths required for running compiled programs
62-
pub run_lib_path: ~str,
62+
pub run_lib_path: StrBuf,
6363

6464
// The rustc executable
6565
pub rustc_path: Path,
@@ -80,7 +80,7 @@ pub struct Config {
8080
pub aux_base: Path,
8181

8282
// The name of the stage being built (stage1, etc)
83-
pub stage_id: ~str,
83+
pub stage_id: StrBuf,
8484

8585
// The test mode, compile-fail, run-fail, run-pass
8686
pub mode: Mode,
@@ -110,37 +110,37 @@ pub struct Config {
110110

111111
// A command line to prefix program execution with,
112112
// for running under valgrind
113-
pub runtool: Option<~str>,
113+
pub runtool: Option<StrBuf>,
114114

115115
// Flags to pass to the compiler when building for the host
116-
pub host_rustcflags: Option<~str>,
116+
pub host_rustcflags: Option<StrBuf>,
117117

118118
// Flags to pass to the compiler when building for the target
119-
pub target_rustcflags: Option<~str>,
119+
pub target_rustcflags: Option<StrBuf>,
120120

121121
// Run tests using the JIT
122122
pub jit: bool,
123123

124124
// Target system to be tested
125-
pub target: ~str,
125+
pub target: StrBuf,
126126

127127
// Host triple for the compiler being invoked
128-
pub host: ~str,
128+
pub host: StrBuf,
129129

130130
// Path to the android tools
131131
pub android_cross_path: Path,
132132

133133
// Extra parameter to run adb on arm-linux-androideabi
134-
pub adb_path: ~str,
134+
pub adb_path: StrBuf,
135135

136136
// Extra parameter to run test sute on arm-linux-androideabi
137-
pub adb_test_dir: ~str,
137+
pub adb_test_dir: StrBuf,
138138

139139
// status whether android device available or not
140140
pub adb_device_status: bool,
141141

142142
// the path containing LLDB's Python module
143-
pub lldb_python_dir: Option<~str>,
143+
pub lldb_python_dir: Option<StrBuf>,
144144

145145
// Explain what's going on
146146
pub verbose: bool

src/compiletest/compiletest.rs

Lines changed: 85 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ fn start(argc: int, argv: **u8) -> int {
4848

4949
pub fn main() {
5050
let args = os::args();
51-
let config = parse_config(args.move_iter().collect());
51+
let config = parse_config(args.move_iter()
52+
.map(|x| x.to_strbuf())
53+
.collect());
5254
log_config(&config);
5355
run_tests(&config);
5456
}
5557

56-
pub fn parse_config(args: Vec<~str> ) -> Config {
58+
pub fn parse_config(args: Vec<StrBuf> ) -> Config {
5759

5860
let groups : Vec<getopts::OptGroup> =
5961
vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
@@ -91,15 +93,15 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
9193
assert!(!args.is_empty());
9294
let argv0 = (*args.get(0)).clone();
9395
let args_ = args.tail();
94-
if *args.get(1) == "-h".to_owned() || *args.get(1) == "--help".to_owned() {
96+
if args.get(1).as_slice() == "-h" || args.get(1).as_slice() == "--help" {
9597
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
9698
println!("{}", getopts::usage(message, groups.as_slice()));
9799
println!("");
98100
fail!()
99101
}
100102

101103
let matches =
102-
&match getopts::getopts(args_, groups.as_slice()) {
104+
&match getopts::getopts(args_.as_slice(), groups.as_slice()) {
103105
Ok(m) => m,
104106
Err(f) => fail!("{}", f.to_err_msg())
105107
};
@@ -129,39 +131,53 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
129131
};
130132

131133
Config {
132-
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
133-
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
134+
compile_lib_path: matches.opt_str("compile-lib-path")
135+
.unwrap()
136+
.to_strbuf(),
137+
run_lib_path: matches.opt_str("run-lib-path").unwrap().to_strbuf(),
134138
rustc_path: opt_path(matches, "rustc-path"),
135139
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
136140
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
137141
src_base: opt_path(matches, "src-base"),
138142
build_base: opt_path(matches, "build-base"),
139143
aux_base: opt_path(matches, "aux-base"),
140-
stage_id: matches.opt_str("stage-id").unwrap(),
141-
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"),
144+
stage_id: matches.opt_str("stage-id").unwrap().to_strbuf(),
145+
mode: FromStr::from_str(matches.opt_str("mode")
146+
.unwrap()
147+
.as_slice()).expect("invalid mode"),
142148
run_ignored: matches.opt_present("ignored"),
143149
filter: filter,
144150
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
145151
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
146152
ratchet_metrics:
147153
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
148154
ratchet_noise_percent:
149-
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
150-
runtool: matches.opt_str("runtool"),
151-
host_rustcflags: matches.opt_str("host-rustcflags"),
152-
target_rustcflags: matches.opt_str("target-rustcflags"),
155+
matches.opt_str("ratchet-noise-percent")
156+
.and_then(|s| from_str::<f64>(s.as_slice())),
157+
runtool: matches.opt_str("runtool").map(|x| x.to_strbuf()),
158+
host_rustcflags: matches.opt_str("host-rustcflags")
159+
.map(|x| x.to_strbuf()),
160+
target_rustcflags: matches.opt_str("target-rustcflags")
161+
.map(|x| x.to_strbuf()),
153162
jit: matches.opt_present("jit"),
154-
target: opt_str2(matches.opt_str("target")).to_str(),
155-
host: opt_str2(matches.opt_str("host")).to_str(),
163+
target: opt_str2(matches.opt_str("target").map(|x| x.to_strbuf())),
164+
host: opt_str2(matches.opt_str("host").map(|x| x.to_strbuf())),
156165
android_cross_path: opt_path(matches, "android-cross-path"),
157-
adb_path: opt_str2(matches.opt_str("adb-path")).to_str(),
158-
adb_test_dir:
159-
opt_str2(matches.opt_str("adb-test-dir")).to_str(),
166+
adb_path: opt_str2(matches.opt_str("adb-path")
167+
.map(|x| x.to_strbuf())),
168+
adb_test_dir: opt_str2(matches.opt_str("adb-test-dir")
169+
.map(|x| x.to_strbuf())),
160170
adb_device_status:
161-
"arm-linux-androideabi" == opt_str2(matches.opt_str("target")) &&
162-
"(none)" != opt_str2(matches.opt_str("adb-test-dir")) &&
163-
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
164-
lldb_python_dir: matches.opt_str("lldb-python-dir"),
171+
"arm-linux-androideabi" ==
172+
opt_str2(matches.opt_str("target")
173+
.map(|x| x.to_strbuf())).as_slice() &&
174+
"(none)" !=
175+
opt_str2(matches.opt_str("adb-test-dir")
176+
.map(|x| x.to_strbuf())).as_slice() &&
177+
!opt_str2(matches.opt_str("adb-test-dir")
178+
.map(|x| x.to_strbuf())).is_empty(),
179+
lldb_python_dir: matches.opt_str("lldb-python-dir")
180+
.map(|x| x.to_strbuf()),
165181
test_shard: test::opt_shard(matches.opt_str("test-shard")
166182
.map(|x| x.to_strbuf())),
167183
verbose: matches.opt_present("verbose")
@@ -170,50 +186,59 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
170186

171187
pub fn log_config(config: &Config) {
172188
let c = config;
173-
logv(c, format!("configuration:"));
174-
logv(c, format!("compile_lib_path: {}", config.compile_lib_path));
175-
logv(c, format!("run_lib_path: {}", config.run_lib_path));
176-
logv(c, format!("rustc_path: {}", config.rustc_path.display()));
177-
logv(c, format!("src_base: {}", config.src_base.display()));
178-
logv(c, format!("build_base: {}", config.build_base.display()));
179-
logv(c, format!("stage_id: {}", config.stage_id));
180-
logv(c, format!("mode: {}", config.mode));
181-
logv(c, format!("run_ignored: {}", config.run_ignored));
182-
logv(c, format!("filter: {}", opt_str(&config.filter.as_ref().map(|re| re.to_str()))));
183-
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
184-
logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
185-
logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));
186-
logv(c, format!("jit: {}", config.jit));
187-
logv(c, format!("target: {}", config.target));
188-
logv(c, format!("host: {}", config.host));
189-
logv(c, format!("android-cross-path: {}", config.android_cross_path.display()));
190-
logv(c, format!("adb_path: {}", config.adb_path));
191-
logv(c, format!("adb_test_dir: {}", config.adb_test_dir));
192-
logv(c, format!("adb_device_status: {}", config.adb_device_status));
189+
logv(c, format_strbuf!("configuration:"));
190+
logv(c, format_strbuf!("compile_lib_path: {}", config.compile_lib_path));
191+
logv(c, format_strbuf!("run_lib_path: {}", config.run_lib_path));
192+
logv(c, format_strbuf!("rustc_path: {}", config.rustc_path.display()));
193+
logv(c, format_strbuf!("src_base: {}", config.src_base.display()));
194+
logv(c, format_strbuf!("build_base: {}", config.build_base.display()));
195+
logv(c, format_strbuf!("stage_id: {}", config.stage_id));
196+
logv(c, format_strbuf!("mode: {}", config.mode));
197+
logv(c, format_strbuf!("run_ignored: {}", config.run_ignored));
198+
logv(c, format_strbuf!("filter: {}",
199+
opt_str(&config.filter
200+
.as_ref()
201+
.map(|re| {
202+
re.to_str().into_strbuf()
203+
}))));
204+
logv(c, format_strbuf!("runtool: {}", opt_str(&config.runtool)));
205+
logv(c, format_strbuf!("host-rustcflags: {}",
206+
opt_str(&config.host_rustcflags)));
207+
logv(c, format_strbuf!("target-rustcflags: {}",
208+
opt_str(&config.target_rustcflags)));
209+
logv(c, format_strbuf!("jit: {}", config.jit));
210+
logv(c, format_strbuf!("target: {}", config.target));
211+
logv(c, format_strbuf!("host: {}", config.host));
212+
logv(c, format_strbuf!("android-cross-path: {}",
213+
config.android_cross_path.display()));
214+
logv(c, format_strbuf!("adb_path: {}", config.adb_path));
215+
logv(c, format_strbuf!("adb_test_dir: {}", config.adb_test_dir));
216+
logv(c, format_strbuf!("adb_device_status: {}",
217+
config.adb_device_status));
193218
match config.test_shard {
194-
None => logv(c, "test_shard: (all)".to_owned()),
195-
Some((a,b)) => logv(c, format!("test_shard: {}.{}", a, b))
219+
None => logv(c, "test_shard: (all)".to_strbuf()),
220+
Some((a,b)) => logv(c, format_strbuf!("test_shard: {}.{}", a, b))
196221
}
197-
logv(c, format!("verbose: {}", config.verbose));
198-
logv(c, format!("\n"));
222+
logv(c, format_strbuf!("verbose: {}", config.verbose));
223+
logv(c, format_strbuf!("\n"));
199224
}
200225

201-
pub fn opt_str<'a>(maybestr: &'a Option<~str>) -> &'a str {
226+
pub fn opt_str<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
202227
match *maybestr {
203228
None => "(none)",
204-
Some(ref s) => {
205-
let s: &'a str = *s;
206-
s
207-
}
229+
Some(ref s) => s.as_slice(),
208230
}
209231
}
210232

211-
pub fn opt_str2(maybestr: Option<~str>) -> ~str {
212-
match maybestr { None => "(none)".to_owned(), Some(s) => { s } }
233+
pub fn opt_str2(maybestr: Option<StrBuf>) -> StrBuf {
234+
match maybestr {
235+
None => "(none)".to_strbuf(),
236+
Some(s) => s,
237+
}
213238
}
214239

215240
pub fn run_tests(config: &Config) {
216-
if config.target == "arm-linux-androideabi".to_owned() {
241+
if config.target.as_slice() == "arm-linux-androideabi" {
217242
match config.mode {
218243
DebugInfoGdb => {
219244
println!("arm-linux-androideabi debug-info \
@@ -321,11 +346,11 @@ pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn)
321346
pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
322347

323348
// Try to elide redundant long paths
324-
fn shorten(path: &Path) -> ~str {
349+
fn shorten(path: &Path) -> StrBuf {
325350
let filename = path.filename_str();
326351
let p = path.dir_path();
327352
let dir = p.filename_str();
328-
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
353+
format_strbuf!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
329354
}
330355

331356
test::DynTestName(format_strbuf!("[{}] {}",
@@ -336,14 +361,16 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
336361
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
337362
let config = (*config).clone();
338363
// FIXME (#9639): This needs to handle non-utf8 paths
339-
let testfile = testfile.as_str().unwrap().to_owned();
340-
test::DynTestFn(proc() { runtest::run(config, testfile) })
364+
let testfile = testfile.as_str().unwrap().to_strbuf();
365+
test::DynTestFn(proc() {
366+
runtest::run(config, testfile)
367+
})
341368
}
342369

343370
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
344371
let config = (*config).clone();
345372
// FIXME (#9639): This needs to handle non-utf8 paths
346-
let testfile = testfile.as_str().unwrap().to_owned();
373+
let testfile = testfile.as_str().unwrap().to_strbuf();
347374
test::DynMetricFn(proc(mm) {
348375
runtest::run_metrics(config, testfile, mm)
349376
})

src/compiletest/errors.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::io::{BufferedReader, File};
1212

1313
pub struct ExpectedError {
1414
pub line: uint,
15-
pub kind: ~str,
16-
pub msg: ~str,
15+
pub kind: StrBuf,
16+
pub msg: StrBuf,
1717
}
1818

1919
// Load any test directives embedded in the file
@@ -23,17 +23,18 @@ pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
2323
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
2424
let mut line_num = 1u;
2525
for ln in rdr.lines() {
26-
error_patterns.push_all_move(parse_expected(line_num, ln.unwrap()));
26+
error_patterns.push_all_move(parse_expected(line_num,
27+
ln.unwrap().to_strbuf()));
2728
line_num += 1u;
2829
}
2930
return error_patterns;
3031
}
3132

32-
fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
33-
let line = line.trim();
34-
let error_tag = "//~".to_owned();
33+
fn parse_expected(line_num: uint, line: StrBuf) -> Vec<ExpectedError> {
34+
let line = line.as_slice().trim().to_strbuf();
35+
let error_tag = "//~".to_strbuf();
3536
let mut idx;
36-
match line.find_str(error_tag) {
37+
match line.as_slice().find_str(error_tag.as_slice()) {
3738
None => return Vec::new(),
3839
Some(nn) => { idx = (nn as uint) + error_tag.len(); }
3940
}
@@ -42,25 +43,34 @@ fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
4243
// three lines above current line:
4344
let mut adjust_line = 0u;
4445
let len = line.len();
45-
while idx < len && line[idx] == ('^' as u8) {
46+
while idx < len && line.as_slice()[idx] == ('^' as u8) {
4647
adjust_line += 1u;
4748
idx += 1u;
4849
}
4950

5051
// Extract kind:
51-
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
52+
while idx < len && line.as_slice()[idx] == (' ' as u8) {
53+
idx += 1u;
54+
}
5255
let start_kind = idx;
53-
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
56+
while idx < len && line.as_slice()[idx] != (' ' as u8) {
57+
idx += 1u;
58+
}
5459

55-
let kind = line.slice(start_kind, idx);
56-
let kind = kind.to_ascii().to_lower().into_str();
60+
let kind = line.as_slice().slice(start_kind, idx);
61+
let kind = kind.to_ascii().to_lower().into_str().to_strbuf();
5762

5863
// Extract msg:
59-
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
60-
let msg = line.slice(idx, len).to_owned();
64+
while idx < len && line.as_slice()[idx] == (' ' as u8) {
65+
idx += 1u;
66+
}
67+
let msg = line.as_slice().slice(idx, len).to_strbuf();
6168

6269
debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg);
6370

64-
return vec!(ExpectedError{line: line_num - adjust_line, kind: kind,
65-
msg: msg});
71+
return vec!(ExpectedError{
72+
line: line_num - adjust_line,
73+
kind: kind,
74+
msg: msg,
75+
});
6676
}

0 commit comments

Comments
 (0)