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

Rustup to *rustc 1.13.0-nightly (4f9812a59 2016-09-21)* #47

Merged
merged 1 commit into from
Sep 23, 2016
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "compiletest_rs"
version = "0.2.1"
version = "0.2.2"
authors = [ "The Rust Project Developers"
, "Thomas Bracht Laumann Jespersen <laumann.thomas@gmail.com>"
, "Manish Goregaokar <manishsmail@gmail.com>"
Expand Down
67 changes: 37 additions & 30 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,53 @@ pub enum Mode {
Incremental,
RunMake,
Ui,
MirOpt,
}

impl FromStr for Mode {
type Err = ();
fn from_str(s: &str) -> Result<Mode, ()> {
match s {
"compile-fail" => Ok(CompileFail),
"parse-fail" => Ok(ParseFail),
"run-fail" => Ok(RunFail),
"run-pass" => Ok(RunPass),
"run-pass-valgrind" => Ok(RunPassValgrind),
"pretty" => Ok(Pretty),
"debuginfo-lldb" => Ok(DebugInfoLldb),
"debuginfo-gdb" => Ok(DebugInfoGdb),
"codegen" => Ok(Codegen),
"rustdoc" => Ok(Rustdoc),
"codegen-units" => Ok(CodegenUnits),
"incremental" => Ok(Incremental),
"run-make" => Ok(RunMake),
"ui" => Ok(Ui),
_ => Err(()),
"compile-fail" => Ok(CompileFail),
"parse-fail" => Ok(ParseFail),
"run-fail" => Ok(RunFail),
"run-pass" => Ok(RunPass),
"run-pass-valgrind" => Ok(RunPassValgrind),
"pretty" => Ok(Pretty),
"debuginfo-lldb" => Ok(DebugInfoLldb),
"debuginfo-gdb" => Ok(DebugInfoGdb),
"codegen" => Ok(Codegen),
"rustdoc" => Ok(Rustdoc),
"codegen-units" => Ok(CodegenUnits),
"incremental" => Ok(Incremental),
"run-make" => Ok(RunMake),
"ui" => Ok(Ui),
"mir-opt" => Ok(MirOpt),
_ => Err(()),
}
}
}

impl fmt::Display for Mode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(match *self {
CompileFail => "compile-fail",
ParseFail => "parse-fail",
RunFail => "run-fail",
RunPass => "run-pass",
RunPassValgrind => "run-pass-valgrind",
Pretty => "pretty",
DebugInfoGdb => "debuginfo-gdb",
DebugInfoLldb => "debuginfo-lldb",
Codegen => "codegen",
Rustdoc => "rustdoc",
CodegenUnits => "codegen-units",
Incremental => "incremental",
RunMake => "run-make",
Ui => "ui",
}, f)
CompileFail => "compile-fail",
ParseFail => "parse-fail",
RunFail => "run-fail",
RunPass => "run-pass",
RunPassValgrind => "run-pass-valgrind",
Pretty => "pretty",
DebugInfoGdb => "debuginfo-gdb",
DebugInfoLldb => "debuginfo-lldb",
Codegen => "codegen",
Rustdoc => "rustdoc",
CodegenUnits => "codegen-units",
Incremental => "incremental",
RunMake => "run-make",
Ui => "ui",
MirOpt => "mir-opt",
},
f)
}
}

Expand Down Expand Up @@ -148,6 +152,9 @@ pub struct Config {
// Version of LLDB
pub lldb_version: Option<String>,

// Version of LLVM
pub llvm_version: Option<String>,

// Path to the android tools
pub android_cross_path: PathBuf,

Expand Down
92 changes: 59 additions & 33 deletions src/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern crate rustc_serialize;
extern crate log;

use std::env;
use std::ffi::OsString;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -68,6 +69,7 @@ pub fn default_config() -> Config {
host: "(none)".to_owned(),
gdb_version: None,
lldb_version: None,
llvm_version: None,
android_cross_path: PathBuf::from("android-cross-path"),
adb_path: "adb-path".to_owned(),
adb_test_dir: "adb-test-dir/target".to_owned(),
Expand All @@ -85,9 +87,9 @@ pub fn default_config() -> Config {

pub fn run_tests(config: &Config) {
if config.target.contains("android") {
if config.mode == DebugInfoGdb {
if let DebugInfoGdb = config.mode {
println!("{} debug-info test uses tcp 5039 port.\
please reserve it", config.target);
please reserve it", config.target);
}

// android debug-info test uses remote debugger
Expand Down Expand Up @@ -162,18 +164,39 @@ fn collect_tests_from_dir(config: &Config,
// `compiletest-ignore-dir`.
for file in try!(fs::read_dir(dir)) {
let file = try!(file);
if file.file_name() == *"compiletest-ignore-dir" {
let name = file.file_name();
if name == *"compiletest-ignore-dir" {
return Ok(());
}
if name == *"Makefile" && config.mode == Mode::RunMake {
let paths = TestPaths {
file: dir.to_path_buf(),
base: base.to_path_buf(),
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
};
tests.push(make_test(config, &paths));
return Ok(())
}
}

// If we find a test foo/bar.rs, we have to build the
// output directory `$build/foo` so we can write
// `$build/foo/bar` into it. We do this *now* in this
// sequential loop because otherwise, if we do it in the
// tests themselves, they race for the privilege of
// creating the directories and sometimes fail randomly.
let build_dir = config.build_base.join(&relative_dir_path);
fs::create_dir_all(&build_dir).unwrap();

// Add each `.rs` file as a test, and recurse further on any
// subdirectories we find, except for `aux` directories.
let dirs = try!(fs::read_dir(dir));
for file in dirs {
let file = try!(file);
let file_path = file.path();
debug!("inspecting file {:?}", file_path.display());
if is_test(config, &file_path) {
// If we find a test foo/bar.rs, we have to build the
let file_name = file.file_name();
if is_test(&file_name) {
debug!("found test file: {:?}", file_path.display());
// output directory `$build/foo` so we can write
// `$build/foo/bar` into it. We do this *now* in this
// sequential loop because otherwise, if we do it in the
Expand All @@ -190,41 +213,39 @@ fn collect_tests_from_dir(config: &Config,
tests.push(make_test(config, &paths))
} else if file_path.is_dir() {
let relative_file_path = relative_dir_path.join(file.file_name());
try!(collect_tests_from_dir(config,
base,
&file_path,
&relative_file_path,
tests));
if &file_name == "auxiliary" {
// `aux` directories contain other crates used for
// cross-crate tests. Don't search them for tests, but
// do create a directory in the build dir for them,
// since we will dump intermediate output in there
// sometimes.
let build_dir = config.build_base.join(&relative_file_path);
fs::create_dir_all(&build_dir).unwrap();
} else {
debug!("found directory: {:?}", file_path.display());
try!(collect_tests_from_dir(config,
base,
&file_path,
&relative_file_path,
tests));
}
} else {
debug!("found other file/directory: {:?}", file_path.display());
}
}
Ok(())
}

pub fn is_test(config: &Config, testfile: &Path) -> bool {
// Pretty-printer does not work with .rc files yet
let valid_extensions =
match config.mode {
Pretty => vec!(".rs".to_owned()),
_ => vec!(".rc".to_owned(), ".rs".to_owned())
};
let invalid_prefixes = vec!(".".to_owned(), "#".to_owned(), "~".to_owned());
let name = testfile.file_name().unwrap().to_str().unwrap();

let mut valid = false;

for ext in &valid_extensions {
if name.ends_with(ext) {
valid = true;
}
}
pub fn is_test(file_name: &OsString) -> bool {
let file_name = file_name.to_str().unwrap();

for pre in &invalid_prefixes {
if name.starts_with(pre) {
valid = false;
}
if !file_name.ends_with(".rs") {
return false;
}

valid
// `.`, `#`, and `~` are common temp-file prefixes.
let invalid_prefixes = &[".", "#", "~"];
!invalid_prefixes.iter().any(|p| file_name.starts_with(p))
}

pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
Expand Down Expand Up @@ -352,3 +373,8 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
}
None
}

#[allow(dead_code)]
fn is_blacklisted_lldb_version(version: &str) -> bool {
version == "350"
}
79 changes: 46 additions & 33 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ pub struct Error {
}

#[derive(PartialEq, Debug)]
enum WhichLine { ThisLine, FollowPrevious(usize), AdjustBackward(usize) }
enum WhichLine {
ThisLine,
FollowPrevious(usize),
AdjustBackward(usize),
}

/// Looks for either "//~| KIND MESSAGE" or "//~^^... KIND MESSAGE"
/// The former is a "follow" that inherits its target from the preceding line;
Expand All @@ -91,60 +95,59 @@ pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec<Error> {

let tag = match cfg {
Some(rev) => format!("//[{}]~", rev),
None => format!("//~")
None => format!("//~"),
};

rdr.lines()
.enumerate()
.filter_map(|(line_num, line)| {
parse_expected(last_nonfollow_error,
line_num + 1,
&line.unwrap(),
&tag)
.map(|(which, error)| {
match which {
FollowPrevious(_) => {}
_ => last_nonfollow_error = Some(error.line_num),
}
error
})
})
.collect()
.enumerate()
.filter_map(|(line_num, line)| {
parse_expected(last_nonfollow_error, line_num + 1, &line.unwrap(), &tag)
.map(|(which, error)| {
match which {
FollowPrevious(_) => {}
_ => last_nonfollow_error = Some(error.line_num),
}
error
})
})
.collect()
}

fn parse_expected(last_nonfollow_error: Option<usize>,
line_num: usize,
line: &str,
tag: &str)
-> Option<(WhichLine, Error)> {
let start = match line.find(tag) { Some(i) => i, None => return None };
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 (kind, msg);
match
line[kind_start..].split_whitespace()
.next()
.expect("Encountered unexpected empty comment")
.parse::<ErrorKind>()
{
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>();
.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>();
.collect::<String>();
}
}
let msg = msg.trim().to_owned();
Expand All @@ -155,15 +158,25 @@ fn parse_expected(last_nonfollow_error: Option<usize>,
preceding //~^ line.");
(FollowPrevious(line_num), line_num)
} else {
let which =
if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine };
let which = if adjusts > 0 {
AdjustBackward(adjusts)
} else {
ThisLine
};
let line_num = line_num - adjusts;
(which, line_num)
};

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