Skip to content
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

Pretty printer improvements #14106

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
compiletest: Modernize typenames
  • Loading branch information
klutzy authored and alexcrichton committed May 13, 2014
commit f3e7bfa6a604be75ea064e3285c4054bf9b007ef
53 changes: 43 additions & 10 deletions src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,52 @@
// 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_gdb,
mode_debug_info_lldb,
mode_codegen
pub enum Mode {
CompileFail,
RunFail,
RunPass,
Pretty,
DebugInfoGdb,
DebugInfoLldb,
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),
"debuginfo-lldb" => Some(DebugInfoLldb),
"debuginfo-gdb" => Some(DebugInfoGdb),
"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",
DebugInfoGdb => "debuginfo-gdb",
DebugInfoLldb => "debuginfo-lldb",
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 @@ -49,7 +82,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: 22 additions & 49 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,9 +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, mode_run_pass, mode_run_fail, mode_compile_fail, mode_pretty,
mode_debug_info_gdb, mode_debug_info_lldb, mode_codegen, mode};
use common::Config;
use common::{Pretty, DebugInfo, Codegen};
use util::logv;

pub mod procsrv;
Expand All @@ -51,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 @@ -112,7 +112,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 @@ -122,7 +122,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 @@ -155,7 +155,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 @@ -164,7 +164,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 @@ -198,35 +198,10 @@ pub fn opt_str2(maybestr: Option<~str>) -> ~str {
match maybestr { None => "(none)".to_owned(), 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,
"debuginfo-gdb" => mode_debug_info_gdb,
"debuginfo-lldb" => mode_debug_info_lldb,
"codegen" => mode_codegen,
s => fail!("invalid mode: " + s)
}
}

pub fn mode_str(mode: mode) -> ~str {
match mode {
mode_compile_fail => "compile-fail".to_owned(),
mode_run_fail => "run-fail".to_owned(),
mode_run_pass => "run-pass".to_owned(),
mode_pretty => "pretty".to_owned(),
mode_debug_info_gdb => "debuginfo-gdb".to_owned(),
mode_debug_info_lldb => "debuginfo-lldb".to_owned(),
mode_codegen => "codegen".to_owned(),
}
}

pub fn run_tests(config: &config) {
if config.target == "arm-linux-androideabi".to_owned() {
match config.mode{
mode_debug_info_gdb => {
pub fn run_tests(config: &Config) {
if config.target == ~"arm-linux-androideabi" {
match config.mode {
DebugInfoGdb => {
println!("arm-linux-androideabi debug-info \
test uses tcp 5039 port. please reserve it");
}
Expand Down Expand Up @@ -255,7 +230,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 @@ -270,7 +245,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 @@ -281,7 +256,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 @@ -291,11 +266,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".to_owned()),
Pretty => vec!(".rs".to_owned()),
_ => vec!(".rc".to_owned(), ".rs".to_owned())
};
let invalid_prefixes = vec!(".".to_owned(), "#".to_owned(), "~".to_owned());
Expand All @@ -314,7 +289,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 @@ -326,7 +301,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 @@ -336,19 +311,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-".to_owned() + util::get_os(config.target)
}
fn ignore_stage(config: &config) -> ~str {
fn ignore_stage(config: &Config) -> ~str {
"ignore-".to_owned() + 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