add version check to the unit tests

This commit is contained in:
Oliver Schneider 2016-05-30 12:47:04 +02:00
parent 3ad0a49632
commit 80e81d351d
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
6 changed files with 54 additions and 9 deletions

View file

@ -21,6 +21,7 @@ semver = "0.2.1"
toml = "0.1"
unicode-normalization = "0.1"
quine-mc_cluskey = "0.2.2"
rustc-serialize = "0.3"
[features]
debugging = []

View file

@ -36,6 +36,8 @@ extern crate regex_syntax;
// for finding minimal boolean expressions
extern crate quine_mc_cluskey;
extern crate rustc_serialize;
extern crate rustc_plugin;
extern crate rustc_const_eval;
extern crate rustc_const_math;

View file

@ -1,4 +1,8 @@
use std::collections::HashMap;
use std::process::Command;
use std::str::{from_utf8, Utf8Error};
use std::io;
use rustc_serialize::json;
#[derive(RustcDecodable, Debug)]
pub struct Metadata {
@ -9,11 +13,11 @@ pub struct Metadata {
#[derive(RustcDecodable, Debug)]
pub struct Package {
name: String,
version: String,
pub name: String,
pub version: String,
id: String,
source: Option<()>,
dependencies: Vec<Dependency>,
pub dependencies: Vec<Dependency>,
pub targets: Vec<Target>,
features: HashMap<String, Vec<String>>,
manifest_path: String,
@ -21,9 +25,9 @@ pub struct Package {
#[derive(RustcDecodable, Debug)]
pub struct Dependency {
name: String,
pub name: String,
source: Option<String>,
req: String,
pub req: String,
kind: Option<String>,
optional: bool,
uses_default_features: bool,
@ -46,3 +50,26 @@ pub struct Target {
pub kind: Vec<Kind>,
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)?)
}

View file

@ -23,6 +23,7 @@ pub mod conf;
mod hir;
pub mod paths;
pub use self::hir::{SpanlessEq, SpanlessHash};
pub mod cargo;
pub type MethodArgs = HirVec<P<Expr>>;

View file

@ -18,7 +18,7 @@ use syntax::diagnostics;
use std::path::PathBuf;
use std::process::Command;
mod cargo;
use clippy_lints::utils::cargo;
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) {
let output = std::process::Command::new("cargo").args(&["metadata", "--no-deps"]).output().expect("could not run `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");
let mut metadata = cargo::metadata().expect("could not obtain cargo metadata");
assert_eq!(metadata.version, 1);
for target in metadata.packages.remove(0).targets {
let args = std::env::args().skip(2);

16
tests/versioncheck.rs Normal file
View 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;
}
}
}