use crate::utils::get_test_path; use tarp::config::{Config, RunType}; use tarp::launch_tarpaulin; use std::env; use std::time::Duration; mod compile_fail; mod doc_coverage; mod line_coverage; mod test_types; mod utils; pub fn check_percentage_with_config( project_name: &str, minimum_coverage: f64, has_lines: bool, mut config: Config, ) { config.verbose = true; config.test_timeout = Duration::from_secs(60); let restore_dir = env::current_dir().unwrap(); let test_dir = get_test_path(project_name); env::set_current_dir(&test_dir).unwrap(); config.manifest = test_dir; config.manifest.push("Cargo.toml"); let (res, _) = launch_tarpaulin(&config).unwrap(); env::set_current_dir(restore_dir).unwrap(); assert!(res.coverage_percentage() >= minimum_coverage); if has_lines { assert!(res.total_coverable() > 0); } } pub fn check_percentage(project_name: &str, minimum_coverage: f64, has_lines: bool) { let config = Config::default(); check_percentage_with_config(project_name, minimum_coverage, has_lines, config); } #[test] fn incorrect_manifest_path() { let mut config = Config::default(); config.manifest.push("__invalid_dir__"); assert!(launch_tarpaulin(&config).is_err()); } #[test] fn proc_macro_link() { let mut config = Config::default(); config.test_timeout = Duration::from_secs(60); let test_dir = get_test_path("proc_macro"); config.manifest = test_dir.join("Cargo.toml"); assert!(launch_tarpaulin(&config).is_ok()); } #[test] fn array_coverage() { check_percentage("arrays", 1.0f64, true); } #[test] fn lets_coverage() { check_percentage("lets", 1.0f64, true); } #[test] fn struct_expr_coverage() { check_percentage("structs", 1.0f64, true); } #[test] fn ifelse_expr_coverage() { check_percentage("ifelse", 1.0f64, true); } #[test] fn returns_expr_coverage() { check_percentage("returns", 1.0f64, true); } #[test] fn loops_expr_coverage() { check_percentage("loops", 1.0f64, true); } #[test] fn loops_assigns_coverage() { check_percentage("assigns", 1.0f64, true); } #[test] fn paths_coverage() { check_percentage("paths", 1.0f64, true); } #[test] #[ignore] fn futures_coverage() { check_percentage("futures", 1.0f64, true); } #[test] fn breaks_expr_coverage() { check_percentage("breaks", 1.0f64, true); } #[test] fn continues_expr_coverage() { check_percentage("continues", 1.0f64, true); } // This test is currently being ignored because it contains cases which Tarpaulin // does not handle correctly yet. So, once (#136) [https://github.com/xd009642/tarpaulin/issues/136] // is updated to resolve method call coverage and multi-line expressions, then // the #[ignore] can be removed from this test. #[test] #[ignore] fn method_calls_expr_coverage() { check_percentage("method_calls", 1.0f64, true); } #[test] #[ignore] fn benchmark_coverage() { let test = "benchmark_coverage"; check_percentage(test, 0.0f64, true); let mut config = Config::default(); config.run_types = vec![RunType::Benchmarks]; check_percentage_with_config(test, 1.0f64, true, config); } #[test] fn examples_coverage() { let test = "example_test"; check_percentage(test, 0.0f64, true); let mut config = Config::default(); config.run_types = vec![RunType::Examples]; check_percentage_with_config(test, 1.0f64, true, config); }