|
| 1 | +#![cfg(feature = "integration")] |
| 2 | + |
| 3 | +use git2::Repository; |
| 4 | +use tempfile; |
| 5 | + |
| 6 | +use std::env; |
| 7 | +use std::process::Command; |
| 8 | + |
| 9 | +#[cfg_attr(feature = "integration", test)] |
| 10 | +fn integration_test() { |
| 11 | + let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set"); |
| 12 | + let repo_url = format!("https://github.com/{}", repo_name); |
| 13 | + let crate_name = repo_name |
| 14 | + .split('/') |
| 15 | + .nth(1) |
| 16 | + .expect("repo name should have format `<org>/<name>`"); |
| 17 | + |
| 18 | + let repo_dir = tempfile::tempdir() |
| 19 | + .expect("couldn't create temp dir") |
| 20 | + .path() |
| 21 | + .join(crate_name); |
| 22 | + |
| 23 | + Repository::clone(&repo_url, &repo_dir).expect("clone of repo failed"); |
| 24 | + |
| 25 | + let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 26 | + let target_dir = std::path::Path::new(&root_dir).join("target"); |
| 27 | + let clippy_binary = target_dir.join(env!("PROFILE")).join("cargo-clippy"); |
| 28 | + |
| 29 | + let output = Command::new(clippy_binary) |
| 30 | + .current_dir(repo_dir) |
| 31 | + .env("RUST_BACKTRACE", "full") |
| 32 | + .env("CARGO_TARGET_DIR", target_dir) |
| 33 | + .args(&[ |
| 34 | + "clippy", |
| 35 | + "--all-targets", |
| 36 | + "--all-features", |
| 37 | + "--", |
| 38 | + "--cap-lints", |
| 39 | + "warn", |
| 40 | + "-Wclippy::pedantic", |
| 41 | + "-Wclippy::nursery", |
| 42 | + ]) |
| 43 | + .output() |
| 44 | + .expect("unable to run clippy"); |
| 45 | + |
| 46 | + let stderr = String::from_utf8_lossy(&output.stderr); |
| 47 | + if stderr.contains("internal compiler error") { |
| 48 | + let backtrace_start = stderr |
| 49 | + .find("thread 'rustc' panicked at") |
| 50 | + .expect("start of backtrace not found"); |
| 51 | + let backtrace_end = stderr |
| 52 | + .rfind("error: internal compiler error") |
| 53 | + .expect("end of backtrace not found"); |
| 54 | + |
| 55 | + panic!( |
| 56 | + "internal compiler error\nBacktrace:\n\n{}", |
| 57 | + &stderr[backtrace_start..backtrace_end] |
| 58 | + ); |
| 59 | + } else if stderr.contains("query stack during panic") { |
| 60 | + panic!("query stack during panic in the output"); |
| 61 | + } else if stderr.contains("E0463") { |
| 62 | + panic!("error: E0463"); |
| 63 | + } |
| 64 | + |
| 65 | + match output.status.code() { |
| 66 | + Some(code) => { |
| 67 | + if code != 0 { |
| 68 | + eprintln!("Compilation failed. Exit code: {}", code); |
| 69 | + } else { |
| 70 | + eprintln!("Compilation successful"); |
| 71 | + } |
| 72 | + }, |
| 73 | + None => panic!("Process terminated by signal"), |
| 74 | + } |
| 75 | +} |
0 commit comments