add version check to the unit tests
This commit is contained in:
@@ -21,6 +21,7 @@ semver = "0.2.1"
|
|||||||
toml = "0.1"
|
toml = "0.1"
|
||||||
unicode-normalization = "0.1"
|
unicode-normalization = "0.1"
|
||||||
quine-mc_cluskey = "0.2.2"
|
quine-mc_cluskey = "0.2.2"
|
||||||
|
rustc-serialize = "0.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
debugging = []
|
debugging = []
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ extern crate regex_syntax;
|
|||||||
// for finding minimal boolean expressions
|
// for finding minimal boolean expressions
|
||||||
extern crate quine_mc_cluskey;
|
extern crate quine_mc_cluskey;
|
||||||
|
|
||||||
|
extern crate rustc_serialize;
|
||||||
|
|
||||||
extern crate rustc_plugin;
|
extern crate rustc_plugin;
|
||||||
extern crate rustc_const_eval;
|
extern crate rustc_const_eval;
|
||||||
extern crate rustc_const_math;
|
extern crate rustc_const_math;
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::process::Command;
|
||||||
|
use std::str::{from_utf8, Utf8Error};
|
||||||
|
use std::io;
|
||||||
|
use rustc_serialize::json;
|
||||||
|
|
||||||
#[derive(RustcDecodable, Debug)]
|
#[derive(RustcDecodable, Debug)]
|
||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
@@ -9,11 +13,11 @@ pub struct Metadata {
|
|||||||
|
|
||||||
#[derive(RustcDecodable, Debug)]
|
#[derive(RustcDecodable, Debug)]
|
||||||
pub struct Package {
|
pub struct Package {
|
||||||
name: String,
|
pub name: String,
|
||||||
version: String,
|
pub version: String,
|
||||||
id: String,
|
id: String,
|
||||||
source: Option<()>,
|
source: Option<()>,
|
||||||
dependencies: Vec<Dependency>,
|
pub dependencies: Vec<Dependency>,
|
||||||
pub targets: Vec<Target>,
|
pub targets: Vec<Target>,
|
||||||
features: HashMap<String, Vec<String>>,
|
features: HashMap<String, Vec<String>>,
|
||||||
manifest_path: String,
|
manifest_path: String,
|
||||||
@@ -21,9 +25,9 @@ pub struct Package {
|
|||||||
|
|
||||||
#[derive(RustcDecodable, Debug)]
|
#[derive(RustcDecodable, Debug)]
|
||||||
pub struct Dependency {
|
pub struct Dependency {
|
||||||
name: String,
|
pub name: String,
|
||||||
source: Option<String>,
|
source: Option<String>,
|
||||||
req: String,
|
pub req: String,
|
||||||
kind: Option<String>,
|
kind: Option<String>,
|
||||||
optional: bool,
|
optional: bool,
|
||||||
uses_default_features: bool,
|
uses_default_features: bool,
|
||||||
@@ -46,3 +50,26 @@ pub struct Target {
|
|||||||
pub kind: Vec<Kind>,
|
pub kind: Vec<Kind>,
|
||||||
src_path: String,
|
src_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
Io(io::Error),
|
||||||
|
Utf8(Utf8Error),
|
||||||
|
Json(json::DecoderError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<io::Error> for Error {
|
||||||
|
fn from(err: io::Error) -> Self { Error::Io(err) }
|
||||||
|
}
|
||||||
|
impl From<Utf8Error> for Error {
|
||||||
|
fn from(err: Utf8Error) -> Self { Error::Utf8(err) }
|
||||||
|
}
|
||||||
|
impl From<json::DecoderError> for Error {
|
||||||
|
fn from(err: json::DecoderError) -> Self { Error::Json(err) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn metadata() -> Result<Metadata, Error> {
|
||||||
|
let output = Command::new("cargo").args(&["metadata", "--no-deps"]).output()?;
|
||||||
|
let stdout = from_utf8(&output.stdout)?;
|
||||||
|
Ok(json::decode(stdout)?)
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ pub mod conf;
|
|||||||
mod hir;
|
mod hir;
|
||||||
pub mod paths;
|
pub mod paths;
|
||||||
pub use self::hir::{SpanlessEq, SpanlessHash};
|
pub use self::hir::{SpanlessEq, SpanlessHash};
|
||||||
|
pub mod cargo;
|
||||||
|
|
||||||
pub type MethodArgs = HirVec<P<Expr>>;
|
pub type MethodArgs = HirVec<P<Expr>>;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use syntax::diagnostics;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
mod cargo;
|
use clippy_lints::utils::cargo;
|
||||||
|
|
||||||
struct ClippyCompilerCalls(RustcDefaultCalls);
|
struct ClippyCompilerCalls(RustcDefaultCalls);
|
||||||
|
|
||||||
@@ -122,9 +122,7 @@ pub fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
|
if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
|
||||||
let output = std::process::Command::new("cargo").args(&["metadata", "--no-deps"]).output().expect("could not run `cargo metadata`");
|
let mut metadata = cargo::metadata().expect("could not obtain cargo metadata");
|
||||||
let stdout = std::str::from_utf8(&output.stdout).expect("`cargo metadata` output is not utf8");
|
|
||||||
let mut metadata: cargo::Metadata = rustc_serialize::json::decode(stdout).expect("`cargo metadata` output is not valid json");
|
|
||||||
assert_eq!(metadata.version, 1);
|
assert_eq!(metadata.version, 1);
|
||||||
for target in metadata.packages.remove(0).targets {
|
for target in metadata.packages.remove(0).targets {
|
||||||
let args = std::env::args().skip(2);
|
let args = std::env::args().skip(2);
|
||||||
|
|||||||
16
tests/versioncheck.rs
Normal file
16
tests/versioncheck.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
extern crate clippy_lints;
|
||||||
|
use clippy_lints::utils::cargo;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_that_clippy_lints_has_the_same_version_as_clippy() {
|
||||||
|
let clippy_meta = cargo::metadata().expect("could not obtain cargo metadata");
|
||||||
|
std::env::set_current_dir(std::env::current_dir().unwrap().join("clippy_lints")).unwrap();
|
||||||
|
let clippy_lints_meta = cargo::metadata().expect("could not obtain cargo metadata");
|
||||||
|
assert_eq!(clippy_lints_meta.packages[0].version, clippy_meta.packages[0].version);
|
||||||
|
for package in &clippy_meta.packages[0].dependencies {
|
||||||
|
if package.name == "clippy_lints" {
|
||||||
|
assert_eq!(clippy_lints_meta.packages[0].version, package.req[1..]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user