use super::{stage::PureStage, stages::*, PipelineBuilder};
use crate::core::Language;
use crate::pipeline::data::PipelineData;
use std::path::{Path, PathBuf};
pub fn example_pipeline() -> super::BuiltPipeline<String> {
PipelineBuilder::new()
.stage(PureStage::new("Initialize", |()| {
vec!["analysis", "started"]
}))
.stage(PureStage::new("Process", |words: Vec<&str>| {
words
.into_iter()
.map(|w| w.to_uppercase())
.collect::<Vec<_>>()
}))
.stage(PureStage::new("Finalize", |words: Vec<String>| {
words.join(" ")
}))
.with_progress()
.build()
}
pub fn standard_pipeline(
project_path: &Path,
languages: &[Language],
coverage_file: Option<&PathBuf>,
enable_context: bool,
) -> super::BuiltPipeline<PipelineData> {
let mut builder = PipelineBuilder::new()
.stage(FileDiscoveryStage::new(project_path, languages))
.stage(ParsingStage::new())
.stage(CallGraphStage::new())
.stage(TraitResolutionStage::new(project_path));
if let Some(coverage_path) = coverage_file {
builder = builder.stage(CoverageLoadingStage::new(coverage_path));
}
builder = builder.stage(PurityAnalysisStage::new());
if enable_context {
builder = builder.stage(ContextLoadingStage::new(project_path));
}
builder
.stage(DebtDetectionStage::new())
.stage(ScoringStage::new())
.with_progress()
.build()
}
pub fn fast_pipeline(
project_path: &Path,
languages: &[Language],
) -> super::BuiltPipeline<PipelineData> {
PipelineBuilder::new()
.stage(FileDiscoveryStage::new(project_path, languages))
.stage(ParsingStage::new())
.stage(CallGraphStage::new())
.stage(PurityAnalysisStage::new())
.stage(DebtDetectionStage::new())
.stage(ScoringStage::new())
.with_progress()
.build()
}
pub fn complexity_only_pipeline(
project_path: &Path,
languages: &[Language],
) -> super::BuiltPipeline<PipelineData> {
PipelineBuilder::new()
.stage(FileDiscoveryStage::new(project_path, languages))
.stage(ParsingStage::new())
.stage(DebtDetectionStage::new())
.with_progress()
.build()
}
pub fn call_graph_pipeline(
project_path: &Path,
languages: &[Language],
) -> super::BuiltPipeline<PipelineData> {
PipelineBuilder::new()
.stage(FileDiscoveryStage::new(project_path, languages))
.stage(ParsingStage::new())
.stage(CallGraphStage::new())
.stage(TraitResolutionStage::new(project_path))
.stage(PurityAnalysisStage::new())
.with_progress()
.build()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_example_pipeline() {
let pipeline = example_pipeline();
let result = pipeline.execute().unwrap();
assert_eq!(result, "ANALYSIS STARTED");
}
#[test]
fn test_example_pipeline_with_timing() {
let pipeline = example_pipeline();
let (result, timings) = pipeline.execute_with_timing().unwrap();
assert_eq!(result, "ANALYSIS STARTED");
assert_eq!(timings.len(), 3);
assert_eq!(timings[0].name, "Initialize");
assert_eq!(timings[1].name, "Process");
assert_eq!(timings[2].name, "Finalize");
}
#[test]
fn test_standard_pipeline_builds() {
let pipeline = standard_pipeline(Path::new("."), &[Language::Rust], None, false);
assert!(pipeline.stage_count() >= 6);
}
#[test]
fn test_fast_pipeline_builds() {
let pipeline = fast_pipeline(Path::new("."), &[Language::Rust]);
assert_eq!(pipeline.stage_count(), 6);
}
#[test]
fn test_complexity_only_pipeline_builds() {
let pipeline = complexity_only_pipeline(Path::new("."), &[Language::Rust]);
assert_eq!(pipeline.stage_count(), 3);
}
#[test]
fn test_call_graph_pipeline_builds() {
let pipeline = call_graph_pipeline(Path::new("."), &[Language::Rust]);
assert_eq!(pipeline.stage_count(), 5);
}
}