Skip to content

Improve pprust-expanded #13596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
49 changes: 40 additions & 9 deletions src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,49 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::from_str::FromStr;
use std::fmt;

#[deriving(Clone, Eq)]
pub enum mode {
mode_compile_fail,
mode_run_fail,
mode_run_pass,
mode_pretty,
mode_debug_info,
mode_codegen
pub enum Mode {
CompileFail,
RunFail,
RunPass,
Pretty,
DebugInfo,
Codegen
}

impl FromStr for Mode {
fn from_str(s: &str) -> Option<Mode> {
match s {
"compile-fail" => Some(CompileFail),
"run-fail" => Some(RunFail),
"run-pass" => Some(RunPass),
"pretty" => Some(Pretty),
"debug-info" => Some(DebugInfo),
"codegen" => Some(Codegen),
_ => None,
}
}
}

impl fmt::Show for Mode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let msg = match *self {
CompileFail => "compile-fail",
RunFail => "run-fail",
RunPass => "run-pass",
Pretty => "pretty",
DebugInfo => "debug-info",
Codegen => "codegen",
};
write!(f.buf, "{}", msg)
}
}

#[deriving(Clone)]
pub struct config {
pub struct Config {
// The library paths required for running the compiler
pub compile_lib_path: ~str,

Expand Down Expand Up @@ -48,7 +79,7 @@ pub struct config {
pub stage_id: ~str,

// The test mode, compile-fail, run-fail, run-pass
pub mode: mode,
pub mode: Mode,

// Run ignored tests
pub run_ignored: bool,
Expand Down
71 changes: 20 additions & 51 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// we use our own (green) start below; do not link in libnative; issue #13247.
#![no_start]

#![allow(non_camel_case_types)]
#![deny(warnings)]

extern crate test;
Expand All @@ -27,15 +26,10 @@ extern crate rustuv;
use std::os;
use std::io;
use std::io::fs;
use std::from_str::FromStr;
use getopts::{optopt, optflag, reqopt};
use common::config;
use common::mode_run_pass;
use common::mode_run_fail;
use common::mode_compile_fail;
use common::mode_pretty;
use common::mode_debug_info;
use common::mode_codegen;
use common::mode;
use common::Config;
use common::{Pretty, DebugInfo, Codegen};
use util::logv;

pub mod procsrv;
Expand All @@ -57,7 +51,7 @@ pub fn main() {
run_tests(&config);
}

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

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

config {
Config {
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
rustc_path: opt_path(matches, "rustc-path"),
Expand All @@ -127,7 +121,7 @@ pub fn parse_config(args: Vec<~str> ) -> config {
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
stage_id: matches.opt_str("stage-id").unwrap(),
mode: str_mode(matches.opt_str("mode").unwrap()),
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"),
run_ignored: matches.opt_present("ignored"),
filter:
if !matches.free.is_empty() {
Expand Down Expand Up @@ -159,7 +153,7 @@ pub fn parse_config(args: Vec<~str> ) -> config {
}
}

pub fn log_config(config: &config) {
pub fn log_config(config: &Config) {
let c = config;
logv(c, format!("configuration:"));
logv(c, format!("compile_lib_path: {}", config.compile_lib_path));
Expand All @@ -168,7 +162,7 @@ pub fn log_config(config: &config) {
logv(c, format!("src_base: {}", config.src_base.display()));
logv(c, format!("build_base: {}", config.build_base.display()));
logv(c, format!("stage_id: {}", config.stage_id));
logv(c, format!("mode: {}", mode_str(config.mode)));
logv(c, format!("mode: {}", config.mode));
logv(c, format!("run_ignored: {}", config.run_ignored));
logv(c, format!("filter: {}", opt_str(&config.filter)));
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
Expand Down Expand Up @@ -202,33 +196,10 @@ pub fn opt_str2(maybestr: Option<~str>) -> ~str {
match maybestr { None => ~"(none)", Some(s) => { s } }
}

pub fn str_mode(s: ~str) -> mode {
match s.as_slice() {
"compile-fail" => mode_compile_fail,
"run-fail" => mode_run_fail,
"run-pass" => mode_run_pass,
"pretty" => mode_pretty,
"debug-info" => mode_debug_info,
"codegen" => mode_codegen,
_ => fail!("invalid mode")
}
}

pub fn mode_str(mode: mode) -> ~str {
match mode {
mode_compile_fail => ~"compile-fail",
mode_run_fail => ~"run-fail",
mode_run_pass => ~"run-pass",
mode_pretty => ~"pretty",
mode_debug_info => ~"debug-info",
mode_codegen => ~"codegen",
}
}

pub fn run_tests(config: &config) {
pub fn run_tests(config: &Config) {
if config.target == ~"arm-linux-androideabi" {
match config.mode{
mode_debug_info => {
DebugInfo => {
println!("arm-linux-androideabi debug-info \
test uses tcp 5039 port. please reserve it");
}
Expand Down Expand Up @@ -257,7 +228,7 @@ pub fn run_tests(config: &config) {
}
}

pub fn test_opts(config: &config) -> test::TestOpts {
pub fn test_opts(config: &Config) -> test::TestOpts {
test::TestOpts {
filter: config.filter.clone(),
run_ignored: config.run_ignored,
Expand All @@ -271,7 +242,7 @@ pub fn test_opts(config: &config) -> test::TestOpts {
}
}

pub fn make_tests(config: &config) -> Vec<test::TestDescAndFn> {
pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
debug!("making tests from {}",
config.src_base.display());
let mut tests = Vec::new();
Expand All @@ -282,7 +253,7 @@ pub fn make_tests(config: &config) -> Vec<test::TestDescAndFn> {
if is_test(config, &file) {
let t = make_test(config, &file, || {
match config.mode {
mode_codegen => make_metrics_test_closure(config, &file),
Codegen => make_metrics_test_closure(config, &file),
_ => make_test_closure(config, &file)
}
});
Expand All @@ -292,11 +263,11 @@ pub fn make_tests(config: &config) -> Vec<test::TestDescAndFn> {
tests
}

pub fn is_test(config: &config, testfile: &Path) -> bool {
pub fn is_test(config: &Config, testfile: &Path) -> bool {
// Pretty-printer does not work with .rc files yet
let valid_extensions =
match config.mode {
mode_pretty => vec!(~".rs"),
Pretty => vec!(~".rs"),
_ => vec!(~".rc", ~".rs")
};
let invalid_prefixes = vec!(~".", ~"#", ~"~");
Expand All @@ -315,7 +286,7 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
return valid;
}

pub fn make_test(config: &config, testfile: &Path, f: || -> test::TestFn)
pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn)
-> test::TestDescAndFn {
test::TestDescAndFn {
desc: test::TestDesc {
Expand All @@ -327,7 +298,7 @@ pub fn make_test(config: &config, testfile: &Path, f: || -> test::TestFn)
}
}

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

// Try to elide redundant long paths
fn shorten(path: &Path) -> ~str {
Expand All @@ -337,19 +308,17 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
}

test::DynTestName(format!("[{}] {}",
mode_str(config.mode),
shorten(testfile)))
test::DynTestName(format!("[{}] {}", config.mode, shorten(testfile)))
}

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

pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn {
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_owned();
Expand Down
10 changes: 5 additions & 5 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use common::config;
use common::Config;
use common;
use util;

Expand Down Expand Up @@ -110,19 +110,19 @@ pub fn load_props(testfile: &Path) -> TestProps {
};
}

pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
fn ignore_target(config: &config) -> ~str {
pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
fn ignore_target(config: &Config) -> ~str {
~"ignore-" + util::get_os(config.target)
}
fn ignore_stage(config: &config) -> ~str {
fn ignore_stage(config: &Config) -> ~str {
~"ignore-" + config.stage_id.split('-').next().unwrap()
}

let val = iter_header(testfile, |ln| {
if parse_name_directive(ln, "ignore-test") { false }
else if parse_name_directive(ln, ignore_target(config)) { false }
else if parse_name_directive(ln, ignore_stage(config)) { false }
else if config.mode == common::mode_pretty &&
else if config.mode == common::Pretty &&
parse_name_directive(ln, "ignore-pretty") { false }
else if config.target != config.host &&
parse_name_directive(ln, "ignore-cross-compile") { false }
Expand Down
Loading