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 all commits
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
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
69 changes: 21 additions & 48 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, DebugInfoGdb, 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) {
pub fn run_tests(config: &Config) {
if config.target == "arm-linux-androideabi".to_owned() {
match config.mode{
mode_debug_info_gdb => {
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
22 changes: 17 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 All @@ -34,6 +34,8 @@ pub struct TestProps {
pub check_stdout: bool,
// Don't force a --crate-type=dylib flag on the command line
pub no_prefer_dynamic: bool,
// Don't run --pretty expanded when running pretty printing tests
pub no_pretty_expanded: bool,
}

// Load any test directives embedded in the file
Expand All @@ -48,6 +50,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
let mut force_host = false;
let mut check_stdout = false;
let mut no_prefer_dynamic = false;
let mut no_pretty_expanded = false;
iter_header(testfile, |ln| {
match parse_error_pattern(ln) {
Some(ep) => error_patterns.push(ep),
Expand Down Expand Up @@ -78,6 +81,10 @@ pub fn load_props(testfile: &Path) -> TestProps {
no_prefer_dynamic = parse_no_prefer_dynamic(ln);
}

if !no_pretty_expanded {
no_pretty_expanded = parse_no_pretty_expanded(ln);
}

match parse_aux_build(ln) {
Some(ab) => { aux_builds.push(ab); }
None => {}
Expand Down Expand Up @@ -107,22 +114,23 @@ pub fn load_props(testfile: &Path) -> TestProps {
force_host: force_host,
check_stdout: check_stdout,
no_prefer_dynamic: no_prefer_dynamic,
no_pretty_expanded: no_pretty_expanded,
}
}

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 Expand Up @@ -180,6 +188,10 @@ fn parse_no_prefer_dynamic(line: &str) -> bool {
parse_name_directive(line, "no-prefer-dynamic")
}

fn parse_no_pretty_expanded(line: &str) -> bool {
parse_name_directive(line, "no-pretty-expanded")
}

fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
parse_name_value_directive(line, "exec-env".to_owned()).map(|nv| {
// nv is either FOO or FOO=BAR
Expand Down
Loading