Tidy up and pass tests

This commit is contained in:
Nick Cameron 2018-03-02 15:07:13 +13:00
parent 39301ae5f2
commit 4f522794ae
573 changed files with 8 additions and 212 deletions

View File

@ -1,17 +0,0 @@
[package]
name = "cargo-fmt"
version = "0.4.0"
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "The Rustfmt developers"]
description = "Cargo frontend for rustfmt"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
categories = ["development-tools"]
[[bin]]
name = "cargo-fmt"
[dependencies]
cargo_metadata = "0.4"
getopts = "0.2"
serde_json = "1.0"

View File

@ -1,19 +0,0 @@
[package]
name = "git-rustfmt"
version = "0.4.0"
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "The Rustfmt developers"]
description = "Run rustfmt against git diff"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
categories = ["development-tools"]
[[bin]]
name = "git-rustfmt"
[dependencies]
env_logger = "0.5"
getopts = "0.2"
log = "0.3"
rustfmt-config = { path = "../rustfmt-config" }
rustfmt-core = { path = "../rustfmt-core" }

View File

@ -1,20 +0,0 @@
[package]
name = "rustfmt-bin"
version = "0.4.0"
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "The Rustfmt developers"]
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
build = "build.rs"
categories = ["development-tools"]
[[bin]]
name = "rustfmt"
path = "src/main.rs"
[dependencies]
env_logger = "0.4"
getopts = "0.2"
rustfmt-config = { path = "../rustfmt-config" }
rustfmt-core = { path = "../rustfmt-core" }

View File

@ -1,59 +0,0 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;
fn main() {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out_dir.join("commit-info.txt"))
.unwrap()
.write_all(commit_info().as_bytes())
.unwrap();
}
// Try to get hash and date of the last commit on a best effort basis. If anything goes wrong
// (git not installed or if this is not a git repository) just return an empty string.
fn commit_info() -> String {
match (channel(), commit_hash(), commit_date()) {
(channel, Some(hash), Some(date)) => {
format!("{} ({} {})", channel, hash.trim_right(), date)
}
_ => String::new(),
}
}
fn channel() -> String {
if let Ok(channel) = env::var("CFG_RELEASE_CHANNEL") {
channel
} else {
"nightly".to_owned()
}
}
fn commit_hash() -> Option<String> {
Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
}
fn commit_date() -> Option<String> {
Command::new("git")
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
}

View File

@ -1,16 +0,0 @@
[package]
name = "rustfmt-config"
version = "0.4.0"
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "The Rustfmt developers"]
description = "A library for configuring and customizing rustfmt"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
categories = ["development-tools"]
[dependencies]
rustc-ap-syntax = "29.0.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
toml = "0.4"

View File

@ -1,3 +0,0 @@
# rustfmt-config
Configuration for Rustfmt

View File

@ -1,33 +0,0 @@
[package]
name = "rustfmt-core"
version = "0.4.0"
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "The Rustfmt developers"]
description = "A core library of rustfmt"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
categories = ["development-tools"]
[lib]
doctest = false
[dependencies]
derive-new = "0.5"
diff = "0.1"
log = "0.3"
regex = "0.2"
rustc-ap-syntax = "29.0.0"
rustc-ap-rustc_errors = "29.0.0"
rustfmt-config = { path = "../rustfmt-config" }
term = "0.4"
unicode-segmentation = "1.0.0"
[dev-dependencies]
lazy_static = "1.0.0"
[target.'cfg(unix)'.dependencies]
libc = "0.2.11"
[target.'cfg(windows)'.dependencies]
kernel32-sys = "0.2.2"
winapi = "0.2.7"

View File

@ -1,3 +0,0 @@
# rustfmt-core
Core formatting functionality for Rustfmt

View File

@ -1,21 +0,0 @@
[package]
name = "rustfmt-format-diff"
version = "0.4.0"
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "The Rustfmt developers"]
description = "Run rustfmt against diff"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
categories = ["development-tools"]
[[bin]]
name = "rustfmt-format-diff"
[dependencies]
env_logger = "0.5"
getopts = "0.2"
log = "0.3"
regex = "0.2"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"

View File

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(custom_attribute)]
#![feature(decl_macro)]
#![feature(match_default_bindings)]

View File

@ -13,8 +13,7 @@ extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate regex;
extern crate rustfmt_config as config;
extern crate rustfmt_core as rustfmt;
extern crate rustfmt_nightly as rustfmt;
extern crate term;
use std::collections::{HashMap, HashSet};
@ -25,8 +24,8 @@ use std::path::{Path, PathBuf};
use std::str::Chars;
use rustfmt::*;
use config::{Color, Config, ReportTactic};
use config::summary::Summary;
use rustfmt::config::{Color, Config, ReportTactic};
use rustfmt::config::summary::Summary;
use rustfmt::filemap::write_system_newlines;
use rustfmt::rustfmt_diff::*;
@ -211,25 +210,14 @@ fn idempotence_tests() {
#[test]
fn self_tests() {
let mut files = get_test_files(Path::new("tests"), false);
let bin_directories = vec![
"cargo-fmt",
"git-rustfmt",
"rustfmt-bin",
"rustfmt-format-diff",
];
let bin_directories = vec!["cargo-fmt", "git-rustfmt", "bin", "format-diff"];
for dir in bin_directories {
let mut path = PathBuf::from("..");
let mut path = PathBuf::from("src");
path.push(dir);
path.push("src/main.rs");
files.push(path);
}
let lib_directories = vec!["rustfmt-core", "rustfmt-config"];
for dir in lib_directories {
let mut path = PathBuf::from("..");
path.push(dir);
path.push("src/lib.rs");
path.push("main.rs");
files.push(path);
}
files.push(PathBuf::from("src/lib.rs"));
let (reports, count, fails) = check_files(files);
let mut warnings = 0;
@ -838,7 +826,7 @@ fn configuration_snippet_tests() {
// entry for each Rust code block found.
fn get_code_blocks() -> Vec<ConfigCodeBlock> {
let mut file_iter = BufReader::new(
fs::File::open(Path::new("..").join(CONFIGURATIONS_FILE_NAME))
fs::File::open(Path::new(CONFIGURATIONS_FILE_NAME))
.expect(&format!("Couldn't read file {}", CONFIGURATIONS_FILE_NAME)),
).lines()
.map(|l| l.unwrap())

Some files were not shown because too many files have changed in this diff Show More