Skip to content

Commit

Permalink
Merge pull request #38 from mcarton/rustup
Browse files Browse the repository at this point in the history
Update from rustc repository
  • Loading branch information
Manishearth committed Jun 5, 2016
2 parents b32b64c + 5a4d78e commit af54362
Show file tree
Hide file tree
Showing 9 changed files with 2,551 additions and 1,788 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "compiletest_rs"
version = "0.1.3"
version = "0.2.0"
authors = [ "The Rust Project Developers"
, "Thomas Bracht Laumann Jespersen <[email protected]>"
, "Manish Goregaokar <[email protected]>"
Expand All @@ -17,3 +17,4 @@ path = "src/compiletest.rs"

[dependencies]
log = "0.3.5"
rustc-serialize = "0.3"
35 changes: 26 additions & 9 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub enum Mode {
Codegen,
Rustdoc,
CodegenUnits,
Incremental,
RunMake,
Ui,
}

impl FromStr for Mode {
Expand All @@ -43,6 +46,9 @@ impl FromStr for Mode {
"codegen" => Ok(Codegen),
"rustdoc" => Ok(Rustdoc),
"codegen-units" => Ok(CodegenUnits),
"incremental" => Ok(Incremental),
"run-make" => Ok(RunMake),
"ui" => Ok(Ui),
_ => Err(()),
}
}
Expand All @@ -62,29 +68,35 @@ impl fmt::Display for Mode {
Codegen => "codegen",
Rustdoc => "rustdoc",
CodegenUnits => "codegen-units",
Incremental => "incremental",
RunMake => "run-make",
Ui => "ui",
}, f)
}
}

#[derive(Clone)]
pub struct Config {
// The library paths required for running the compiler
pub compile_lib_path: String,
pub compile_lib_path: PathBuf,

// The library paths required for running compiled programs
pub run_lib_path: String,
pub run_lib_path: PathBuf,

// The rustc executable
pub rustc_path: PathBuf,

// The rustdoc executable
pub rustdoc_path: PathBuf,

// The python executable
pub python: String,
// The python executable to use for LLDB
pub lldb_python: String,

// The llvm binaries path
pub llvm_bin_path: Option<PathBuf>,
// The python executable to use for htmldocck
pub docck_python: String,

// The llvm FileCheck binary path
pub llvm_filecheck: Option<PathBuf>,

// The valgrind path
pub valgrind_path: Option<String>,
Expand All @@ -99,9 +111,6 @@ pub struct Config {
// The directory where programs should be built
pub build_base: PathBuf,

// Directory for auxiliary libraries
pub aux_base: PathBuf,

// The name of the stage being built (stage1, etc)
pub stage_id: String,

Expand Down Expand Up @@ -159,4 +168,12 @@ pub struct Config {

// Print one character per test instead of one line
pub quiet: bool,

// Configuration for various run-make tests frobbing things like C compilers
// or querying about various LLVM component information.
pub cc: String,
pub cxx: String,
pub cflags: String,
pub llvm_components: String,
pub llvm_cxxflags: String,
}
31 changes: 22 additions & 9 deletions src/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

extern crate test;
extern crate rustc;
extern crate rustc_serialize;

#[macro_use]
extern crate log;
Expand All @@ -31,6 +32,10 @@ use test::TestPaths;
use std::borrow::ToOwned;
use rustc::session::config::host_triple;

use self::header::EarlyProps;

pub mod uidiff;
pub mod json;
pub mod procsrv;
pub mod util;
pub mod header;
Expand All @@ -40,18 +45,18 @@ pub mod errors;

pub fn default_config() -> Config {
Config {
compile_lib_path: "".to_owned(),
run_lib_path: "".to_owned(),
compile_lib_path: PathBuf::from(""),
run_lib_path: PathBuf::from(""),
rustc_path: PathBuf::from("rustc"),
rustdoc_path: PathBuf::from("rustdoc-path"),
python: "python".to_owned(),
lldb_python: "python".to_owned(),
docck_python: "docck-python".to_owned(),
valgrind_path: None,
force_valgrind: false,
llvm_bin_path: None,
llvm_filecheck: None,
src_base: PathBuf::from("tests/run-pass"),
build_base: env::temp_dir(),
aux_base: PathBuf::from("aux-base"),
stage_id: "stage3".to_owned(),
stage_id: "stage-id".to_owned(),
mode: Mode::RunPass,
run_ignored: false,
filter: None,
Expand All @@ -63,13 +68,18 @@ pub fn default_config() -> Config {
host: "(none)".to_owned(),
gdb_version: None,
lldb_version: None,
lldb_python_dir: None,
android_cross_path: PathBuf::from("android-cross-path"),
adb_path: "adb-path".to_owned(),
adb_test_dir: "adb-test-dir/target".to_owned(),
adb_device_status: false,
lldb_python_dir: None,
verbose: false,
quiet: false,
cc: "cc".to_string(),
cxx: "cxx".to_string(),
cflags: "cflags".to_string(),
llvm_components: "llvm-components".to_string(),
llvm_cxxflags: "llvm-cxxflags".to_string(),
}
}

Expand Down Expand Up @@ -120,7 +130,10 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
logfile: config.logfile.clone(),
run_tests: true,
bench_benchmarks: true,
nocapture: env::var("RUST_TEST_NOCAPTURE").is_ok(),
nocapture: match env::var("RUST_TEST_NOCAPTURE") {
Ok(val) => &val != "0",
Err(_) => false
},
color: test::AutoColor,
}
}
Expand Down Expand Up @@ -214,7 +227,7 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
}

pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
let early_props = header::early_props(config, &testpaths.file);
let early_props = EarlyProps::from_file(config, &testpaths.file);

// The `should-fail` annotation doesn't apply to pretty tests,
// since we run the pretty printer across all tests by default.
Expand Down
90 changes: 74 additions & 16 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,57 @@
// except according to those terms.
use self::WhichLine::*;

use std::fmt;
use std::fs::File;
use std::io::BufReader;
use std::io::prelude::*;
use std::path::Path;
use std::str::FromStr;

pub struct ExpectedError {
#[derive(Clone, Debug, PartialEq)]
pub enum ErrorKind {
Help,
Error,
Note,
Suggestion,
Warning,
}

impl FromStr for ErrorKind {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.to_uppercase();
let part0: &str = s.split(':').next().unwrap();
match part0 {
"HELP" => Ok(ErrorKind::Help),
"ERROR" => Ok(ErrorKind::Error),
"NOTE" => Ok(ErrorKind::Note),
"SUGGESTION" => Ok(ErrorKind::Suggestion),
"WARN" => Ok(ErrorKind::Warning),
"WARNING" => Ok(ErrorKind::Warning),
_ => Err(()),
}
}
}

impl fmt::Display for ErrorKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ErrorKind::Help => write!(f, "help"),
ErrorKind::Error => write!(f, "error"),
ErrorKind::Note => write!(f, "note"),
ErrorKind::Suggestion => write!(f, "suggestion"),
ErrorKind::Warning => write!(f, "warning"),
}
}
}

#[derive(Debug)]
pub struct Error {
pub line_num: usize,
pub kind: String,
/// What kind of message we expect (e.g. warning, error, suggestion).
/// `None` if not specified or unknown message kind.
pub kind: Option<ErrorKind>,
pub msg: String,
}

Expand All @@ -33,7 +76,7 @@ enum WhichLine { ThisLine, FollowPrevious(usize), AdjustBackward(usize) }
///
/// If cfg is not None (i.e., in an incremental test), then we look
/// for `//[X]~` instead, where `X` is the current `cfg`.
pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec<ExpectedError> {
pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec<Error> {
let rdr = BufReader::new(File::open(testfile).unwrap());

// `last_nonfollow_error` tracks the most recently seen
Expand Down Expand Up @@ -73,23 +116,38 @@ fn parse_expected(last_nonfollow_error: Option<usize>,
line_num: usize,
line: &str,
tag: &str)
-> Option<(WhichLine, ExpectedError)> {
-> Option<(WhichLine, Error)> {
let start = match line.find(tag) { Some(i) => i, None => return None };
let (follow, adjusts) = if line[start + tag.len()..].chars().next().unwrap() == '|' {
(true, 0)
} else {
(false, line[start + tag.len()..].chars().take_while(|c| *c == '^').count())
};
let kind_start = start + tag.len() + adjusts + (follow as usize);
let letters = line[kind_start..].chars();
let kind = letters.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.flat_map(|c| c.to_lowercase())
.collect::<String>();
let letters = line[kind_start..].chars();
let msg = letters.skip_while(|c| c.is_whitespace())
.skip_while(|c| !c.is_whitespace())
.collect::<String>().trim().to_owned();
let (kind, msg);
match
line[kind_start..].split_whitespace()
.next()
.expect("Encountered unexpected empty comment")
.parse::<ErrorKind>()
{
Ok(k) => {
// If we find `//~ ERROR foo` or something like that:
kind = Some(k);
let letters = line[kind_start..].chars();
msg = letters.skip_while(|c| c.is_whitespace())
.skip_while(|c| !c.is_whitespace())
.collect::<String>();
}
Err(_) => {
// Otherwise we found `//~ foo`:
kind = None;
let letters = line[kind_start..].chars();
msg = letters.skip_while(|c| c.is_whitespace())
.collect::<String>();
}
}
let msg = msg.trim().to_owned();

let (which, line_num) = if follow {
assert!(adjusts == 0, "use either //~| or //~^, not both.");
Expand All @@ -105,7 +163,7 @@ fn parse_expected(last_nonfollow_error: Option<usize>,

debug!("line={} tag={:?} which={:?} kind={:?} msg={:?}",
line_num, tag, which, kind, msg);
Some((which, ExpectedError { line_num: line_num,
kind: kind,
msg: msg, }))
Some((which, Error { line_num: line_num,
kind: kind,
msg: msg, }))
}
Loading

0 comments on commit af54362

Please sign in to comment.