Skip to content

Commit 96eeda9

Browse files
klutzyalexcrichton
authored andcommitted
compiletest: Modernize typenames
1 parent 0350d8e commit 96eeda9

File tree

5 files changed

+119
-112
lines changed

5 files changed

+119
-112
lines changed

src/compiletest/common.rs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,52 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::from_str::FromStr;
12+
use std::fmt;
13+
1114
#[deriving(Clone, Eq)]
12-
pub enum mode {
13-
mode_compile_fail,
14-
mode_run_fail,
15-
mode_run_pass,
16-
mode_pretty,
17-
mode_debug_info_gdb,
18-
mode_debug_info_lldb,
19-
mode_codegen
15+
pub enum Mode {
16+
CompileFail,
17+
RunFail,
18+
RunPass,
19+
Pretty,
20+
DebugInfoGdb,
21+
DebugInfoLldb,
22+
Codegen
23+
}
24+
25+
impl FromStr for Mode {
26+
fn from_str(s: &str) -> Option<Mode> {
27+
match s {
28+
"compile-fail" => Some(CompileFail),
29+
"run-fail" => Some(RunFail),
30+
"run-pass" => Some(RunPass),
31+
"pretty" => Some(Pretty),
32+
"debuginfo-lldb" => Some(DebugInfoLldb),
33+
"debuginfo-gdb" => Some(DebugInfoGdb),
34+
"codegen" => Some(Codegen),
35+
_ => None,
36+
}
37+
}
38+
}
39+
40+
impl fmt::Show for Mode {
41+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42+
let msg = match *self {
43+
CompileFail => "compile-fail",
44+
RunFail => "run-fail",
45+
RunPass => "run-pass",
46+
Pretty => "pretty",
47+
DebugInfoGdb => "debuginfo-gdb",
48+
DebugInfoLldb => "debuginfo-lldb",
49+
Codegen => "codegen",
50+
};
51+
write!(f.buf, "{}", msg)
52+
}
2053
}
2154

2255
#[deriving(Clone)]
23-
pub struct config {
56+
pub struct Config {
2457
// The library paths required for running the compiler
2558
pub compile_lib_path: ~str,
2659

@@ -49,7 +82,7 @@ pub struct config {
4982
pub stage_id: ~str,
5083

5184
// The test mode, compile-fail, run-fail, run-pass
52-
pub mode: mode,
85+
pub mode: Mode,
5386

5487
// Run ignored tests
5588
pub run_ignored: bool,

src/compiletest/compiletest.rs

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// we use our own (green) start below; do not link in libnative; issue #13247.
1515
#![no_start]
1616

17-
#![allow(non_camel_case_types)]
1817
#![deny(warnings)]
1918

2019
extern crate test;
@@ -27,9 +26,10 @@ extern crate rustuv;
2726
use std::os;
2827
use std::io;
2928
use std::io::fs;
29+
use std::from_str::FromStr;
3030
use getopts::{optopt, optflag, reqopt};
31-
use common::{config, mode_run_pass, mode_run_fail, mode_compile_fail, mode_pretty,
32-
mode_debug_info_gdb, mode_debug_info_lldb, mode_codegen, mode};
31+
use common::Config;
32+
use common::{Pretty, DebugInfo, Codegen};
3333
use util::logv;
3434

3535
pub mod procsrv;
@@ -51,7 +51,7 @@ pub fn main() {
5151
run_tests(&config);
5252
}
5353

54-
pub fn parse_config(args: Vec<~str> ) -> config {
54+
pub fn parse_config(args: Vec<~str> ) -> Config {
5555

5656
let groups : Vec<getopts::OptGroup> =
5757
vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
@@ -112,7 +112,7 @@ pub fn parse_config(args: Vec<~str> ) -> config {
112112
Path::new(m.opt_str(nm).unwrap())
113113
}
114114

115-
config {
115+
Config {
116116
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
117117
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
118118
rustc_path: opt_path(matches, "rustc-path"),
@@ -122,7 +122,7 @@ pub fn parse_config(args: Vec<~str> ) -> config {
122122
build_base: opt_path(matches, "build-base"),
123123
aux_base: opt_path(matches, "aux-base"),
124124
stage_id: matches.opt_str("stage-id").unwrap(),
125-
mode: str_mode(matches.opt_str("mode").unwrap()),
125+
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"),
126126
run_ignored: matches.opt_present("ignored"),
127127
filter:
128128
if !matches.free.is_empty() {
@@ -155,7 +155,7 @@ pub fn parse_config(args: Vec<~str> ) -> config {
155155
}
156156
}
157157

158-
pub fn log_config(config: &config) {
158+
pub fn log_config(config: &Config) {
159159
let c = config;
160160
logv(c, format!("configuration:"));
161161
logv(c, format!("compile_lib_path: {}", config.compile_lib_path));
@@ -164,7 +164,7 @@ pub fn log_config(config: &config) {
164164
logv(c, format!("src_base: {}", config.src_base.display()));
165165
logv(c, format!("build_base: {}", config.build_base.display()));
166166
logv(c, format!("stage_id: {}", config.stage_id));
167-
logv(c, format!("mode: {}", mode_str(config.mode)));
167+
logv(c, format!("mode: {}", config.mode));
168168
logv(c, format!("run_ignored: {}", config.run_ignored));
169169
logv(c, format!("filter: {}", opt_str(&config.filter)));
170170
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
@@ -198,35 +198,10 @@ pub fn opt_str2(maybestr: Option<~str>) -> ~str {
198198
match maybestr { None => "(none)".to_owned(), Some(s) => { s } }
199199
}
200200

201-
pub fn str_mode(s: ~str) -> mode {
202-
match s.as_slice() {
203-
"compile-fail" => mode_compile_fail,
204-
"run-fail" => mode_run_fail,
205-
"run-pass" => mode_run_pass,
206-
"pretty" => mode_pretty,
207-
"debuginfo-gdb" => mode_debug_info_gdb,
208-
"debuginfo-lldb" => mode_debug_info_lldb,
209-
"codegen" => mode_codegen,
210-
s => fail!("invalid mode: " + s)
211-
}
212-
}
213-
214-
pub fn mode_str(mode: mode) -> ~str {
215-
match mode {
216-
mode_compile_fail => "compile-fail".to_owned(),
217-
mode_run_fail => "run-fail".to_owned(),
218-
mode_run_pass => "run-pass".to_owned(),
219-
mode_pretty => "pretty".to_owned(),
220-
mode_debug_info_gdb => "debuginfo-gdb".to_owned(),
221-
mode_debug_info_lldb => "debuginfo-lldb".to_owned(),
222-
mode_codegen => "codegen".to_owned(),
223-
}
224-
}
225-
226-
pub fn run_tests(config: &config) {
227-
if config.target == "arm-linux-androideabi".to_owned() {
228-
match config.mode{
229-
mode_debug_info_gdb => {
201+
pub fn run_tests(config: &Config) {
202+
if config.target == ~"arm-linux-androideabi" {
203+
match config.mode {
204+
DebugInfoGdb => {
230205
println!("arm-linux-androideabi debug-info \
231206
test uses tcp 5039 port. please reserve it");
232207
}
@@ -255,7 +230,7 @@ pub fn run_tests(config: &config) {
255230
}
256231
}
257232

258-
pub fn test_opts(config: &config) -> test::TestOpts {
233+
pub fn test_opts(config: &Config) -> test::TestOpts {
259234
test::TestOpts {
260235
filter: config.filter.clone(),
261236
run_ignored: config.run_ignored,
@@ -270,7 +245,7 @@ pub fn test_opts(config: &config) -> test::TestOpts {
270245
}
271246
}
272247

273-
pub fn make_tests(config: &config) -> Vec<test::TestDescAndFn> {
248+
pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
274249
debug!("making tests from {}",
275250
config.src_base.display());
276251
let mut tests = Vec::new();
@@ -281,7 +256,7 @@ pub fn make_tests(config: &config) -> Vec<test::TestDescAndFn> {
281256
if is_test(config, &file) {
282257
let t = make_test(config, &file, || {
283258
match config.mode {
284-
mode_codegen => make_metrics_test_closure(config, &file),
259+
Codegen => make_metrics_test_closure(config, &file),
285260
_ => make_test_closure(config, &file)
286261
}
287262
});
@@ -291,11 +266,11 @@ pub fn make_tests(config: &config) -> Vec<test::TestDescAndFn> {
291266
tests
292267
}
293268

294-
pub fn is_test(config: &config, testfile: &Path) -> bool {
269+
pub fn is_test(config: &Config, testfile: &Path) -> bool {
295270
// Pretty-printer does not work with .rc files yet
296271
let valid_extensions =
297272
match config.mode {
298-
mode_pretty => vec!(".rs".to_owned()),
273+
Pretty => vec!(".rs".to_owned()),
299274
_ => vec!(".rc".to_owned(), ".rs".to_owned())
300275
};
301276
let invalid_prefixes = vec!(".".to_owned(), "#".to_owned(), "~".to_owned());
@@ -314,7 +289,7 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
314289
return valid;
315290
}
316291

317-
pub fn make_test(config: &config, testfile: &Path, f: || -> test::TestFn)
292+
pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn)
318293
-> test::TestDescAndFn {
319294
test::TestDescAndFn {
320295
desc: test::TestDesc {
@@ -326,7 +301,7 @@ pub fn make_test(config: &config, testfile: &Path, f: || -> test::TestFn)
326301
}
327302
}
328303

329-
pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
304+
pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
330305

331306
// Try to elide redundant long paths
332307
fn shorten(path: &Path) -> ~str {
@@ -336,19 +311,17 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
336311
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
337312
}
338313

339-
test::DynTestName(format!("[{}] {}",
340-
mode_str(config.mode),
341-
shorten(testfile)))
314+
test::DynTestName(format!("[{}] {}", config.mode, shorten(testfile)))
342315
}
343316

344-
pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn {
317+
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
345318
let config = (*config).clone();
346319
// FIXME (#9639): This needs to handle non-utf8 paths
347320
let testfile = testfile.as_str().unwrap().to_owned();
348321
test::DynTestFn(proc() { runtest::run(config, testfile) })
349322
}
350323

351-
pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn {
324+
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
352325
let config = (*config).clone();
353326
// FIXME (#9639): This needs to handle non-utf8 paths
354327
let testfile = testfile.as_str().unwrap().to_owned();

src/compiletest/header.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use common::config;
11+
use common::Config;
1212
use common;
1313
use util;
1414

@@ -110,19 +110,19 @@ pub fn load_props(testfile: &Path) -> TestProps {
110110
}
111111
}
112112

113-
pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
114-
fn ignore_target(config: &config) -> ~str {
113+
pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
114+
fn ignore_target(config: &Config) -> ~str {
115115
"ignore-".to_owned() + util::get_os(config.target)
116116
}
117-
fn ignore_stage(config: &config) -> ~str {
117+
fn ignore_stage(config: &Config) -> ~str {
118118
"ignore-".to_owned() + config.stage_id.split('-').next().unwrap()
119119
}
120120

121121
let val = iter_header(testfile, |ln| {
122122
if parse_name_directive(ln, "ignore-test") { false }
123123
else if parse_name_directive(ln, ignore_target(config)) { false }
124124
else if parse_name_directive(ln, ignore_stage(config)) { false }
125-
else if config.mode == common::mode_pretty &&
125+
else if config.mode == common::Pretty &&
126126
parse_name_directive(ln, "ignore-pretty") { false }
127127
else if config.target != config.host &&
128128
parse_name_directive(ln, "ignore-cross-compile") { false }

0 commit comments

Comments
 (0)