#[cfg(feature = "test-support")]
#[must_use]
pub fn permissive_coupling_opts(repo_path: std::path::PathBuf) -> crate::Options {
crate::Options {
repo_path,
min_revs: 1,
min_shared_revs: 1,
min_coupling_pct: 0,
max_coupling_pct: 100,
fisher_significance: 1.0,
..crate::Options::default()
}
}
#[cfg(feature = "test-support")]
#[must_use]
pub fn sarif_fixture(name: &str) -> String {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/sarif")
.join(name);
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("could not read fixture {name}: {e}"))
}
#[cfg(feature = "test-support")]
#[must_use]
pub fn temp_external_store(cache_dir: &std::path::Path) -> crate::external::ExternalStore {
crate::external::ExternalStore::open_or_create(cache_dir, std::path::Path::new("/test/repo"))
.expect("open_or_create external store")
}
#[cfg(feature = "test-support")]
#[must_use]
pub fn finding_for(path: &str, engine: &str, level: &str) -> crate::external::ExternalFinding {
crate::external::ExternalFinding {
engine: engine.to_string(),
engine_version: "0.0.0".to_string(),
rule_id: "test/rule".to_string(),
path: path.to_string(),
start_line: Some(1),
end_line: None,
level: level.to_string(),
fingerprint: format!("test/v1/{engine}/{path}"),
message: "test finding".to_string(),
}
}
#[cfg(feature = "test-support")]
fn clone_bundle(bundle: &[u8], target: &std::path::Path) -> String {
let bundle_file = tempfile::NamedTempFile::new().expect("bundle scratch tempfile");
std::fs::write(bundle_file.path(), bundle).expect("write bundle bytes");
let status = std::process::Command::new("git")
.args(["clone", "--quiet"])
.arg(bundle_file.path())
.arg(target)
.status()
.expect("spawn git clone");
assert!(status.success(), "git clone from embedded bundle failed");
drop(bundle_file);
String::from_utf8(
std::process::Command::new("git")
.arg("-C")
.arg(target)
.args(["rev-parse", "HEAD"])
.output()
.expect("spawn git rev-parse")
.stdout,
)
.expect("utf8")
.trim()
.to_string()
}
#[cfg(feature = "test-support")]
pub mod tiny_repo {
use tempfile::TempDir;
static BUNDLE: &[u8] = include_bytes!("data/tiny-repo.bundle");
pub struct TinyRepo {
pub dir: TempDir,
pub head_sha: String,
}
#[must_use]
pub fn build() -> TinyRepo {
let dir = tempfile::tempdir().expect("tempdir");
let head_sha = super::clone_bundle(BUNDLE, dir.path());
TinyRepo { dir, head_sha }
}
}
#[cfg(feature = "test-support")]
pub mod biomarker_repo {
use tempfile::TempDir;
static BUNDLE: &[u8] = include_bytes!("data/biomarker-repo.bundle");
pub struct BiomarkerRepo {
pub dir: TempDir,
pub head_sha: String,
}
#[must_use]
pub fn build() -> BiomarkerRepo {
let dir = tempfile::tempdir().expect("tempdir");
let head_sha = super::clone_bundle(BUNDLE, dir.path());
BiomarkerRepo { dir, head_sha }
}
}
#[cfg(feature = "test-support")]
pub mod function_xray_repo {
use tempfile::TempDir;
static BUNDLE: &[u8] = include_bytes!("data/function-xray-repo.bundle");
pub struct FunctionXrayRepo {
pub dir: TempDir,
}
#[must_use]
pub fn build() -> FunctionXrayRepo {
let dir = tempfile::tempdir().expect("tempdir");
let _head_sha = super::clone_bundle(BUNDLE, dir.path());
FunctionXrayRepo { dir }
}
}
#[cfg(feature = "test-support")]
pub mod differential_repo {
use tempfile::TempDir;
static BUNDLE: &[u8] = include_bytes!("data/differential-repo.bundle");
pub struct DifferentialRepo {
pub dir: TempDir,
pub head_sha: String,
}
#[must_use]
pub fn build() -> DifferentialRepo {
let dir = tempfile::tempdir().expect("tempdir");
let head_sha = super::clone_bundle(BUNDLE, dir.path());
DifferentialRepo { dir, head_sha }
}
}
#[cfg(feature = "test-support")]
pub mod coupling_repo {
use tempfile::TempDir;
static BUNDLE: &[u8] = include_bytes!("data/coupling-repo.bundle");
pub struct CouplingRepo {
pub dir: TempDir,
pub head_sha: String,
}
#[must_use]
pub fn build() -> CouplingRepo {
let dir = tempfile::tempdir().expect("tempdir");
let head_sha = super::clone_bundle(BUNDLE, dir.path());
CouplingRepo { dir, head_sha }
}
}
#[cfg(feature = "test-support")]
pub mod medium_repo {
use tempfile::TempDir;
static BUNDLE: &[u8] = include_bytes!("data/medium-repo.bundle");
pub struct MediumRepo {
pub dir: TempDir,
pub head_sha: String,
}
#[must_use]
pub fn build() -> MediumRepo {
let dir = tempfile::tempdir().expect("tempdir");
let head_sha = super::clone_bundle(BUNDLE, dir.path());
MediumRepo { dir, head_sha }
}
}
#[cfg(feature = "test-support")]
pub mod delivery_repo {
use tempfile::TempDir;
static BUNDLE: &[u8] = include_bytes!("data/delivery-repo.bundle");
pub struct DeliveryRepo {
pub dir: TempDir,
pub head_sha: String,
}
#[must_use]
pub fn build() -> DeliveryRepo {
let dir = tempfile::tempdir().expect("tempdir");
let head_sha = super::clone_bundle(BUNDLE, dir.path());
DeliveryRepo { dir, head_sha }
}
}
#[cfg(feature = "test-support")]
pub mod mainline_advance_repo {
use tempfile::TempDir;
static BUNDLE: &[u8] = include_bytes!("data/mainline-advance-repo.bundle");
pub struct MainlineAdvanceRepo {
pub dir: TempDir,
pub head_sha: String,
}
#[must_use]
pub fn build() -> MainlineAdvanceRepo {
let dir = tempfile::tempdir().expect("tempdir");
let head_sha = super::clone_bundle(BUNDLE, dir.path());
MainlineAdvanceRepo { dir, head_sha }
}
}