use assert_cmd::cargo::cargo_bin_cmd;
use predicates::prelude::*;
use std::fs;
use tempfile::tempdir;
#[test]
fn test_grouped_output_format() {
let temp_dir = tempdir().unwrap();
let test_file = temp_dir.path().join("test.md");
let content = format!(
r#"# Heading
Content with trailing space{}
*Emphasis without space*
"#,
" "
);
fs::write(&test_file, content).unwrap();
let mut cmd = cargo_bin_cmd!("rumdl");
cmd.arg("check")
.arg("--output-format")
.arg("grouped")
.arg(test_file.to_str().unwrap());
cmd.assert()
.failure()
.stdout(predicate::str::contains("test.md:"))
.stdout(predicate::str::contains("MD022:")) .stdout(predicate::str::contains("MD009:")); }
#[test]
fn test_pylint_output_format() {
let temp_dir = tempdir().unwrap();
let test_file = temp_dir.path().join("test.md");
let content = format!(
r#"# Heading
Content with trailing space{}
"#,
" "
);
fs::write(&test_file, content).unwrap();
let mut cmd = cargo_bin_cmd!("rumdl");
cmd.arg("check")
.arg("--output-format")
.arg("pylint")
.arg(test_file.to_str().unwrap());
cmd.assert()
.failure()
.stdout(predicate::str::contains(":1:1: [CMD022]"))
.stdout(predicate::str::contains(":2:28: [CMD009]"));
}
#[test]
fn test_azure_output_format() {
let temp_dir = tempdir().unwrap();
let test_file = temp_dir.path().join("test.md");
let content = format!(
r#"# Heading
Content with trailing space{}
"#,
" "
);
fs::write(&test_file, content).unwrap();
let mut cmd = cargo_bin_cmd!("rumdl");
cmd.arg("check")
.arg("--output-format")
.arg("azure")
.arg(test_file.to_str().unwrap());
cmd.assert()
.failure()
.stdout(predicate::str::contains("##vso[task.logissue type=warning;sourcepath="))
.stdout(predicate::str::contains("code=MD009]"))
.stdout(predicate::str::contains("code=MD022]"));
}
#[test]
fn test_rumdl_output_format_env_var() {
let temp_dir = tempdir().unwrap();
let test_file = temp_dir.path().join("test.md");
let content = format!(
r#"# Heading
Content with trailing space{}
"#,
" "
);
fs::write(&test_file, content).unwrap();
let mut cmd = cargo_bin_cmd!("rumdl");
cmd.env("RUMDL_OUTPUT_FORMAT", "github")
.arg("check")
.arg(test_file.to_str().unwrap());
cmd.assert()
.failure()
.stdout(predicate::str::contains("::warning file="));
}
#[test]
fn test_rumdl_output_format_env_var_cli_override() {
let temp_dir = tempdir().unwrap();
let test_file = temp_dir.path().join("test.md");
let content = format!(
r#"# Heading
Content with trailing space{}
"#,
" "
);
fs::write(&test_file, content).unwrap();
let mut cmd = cargo_bin_cmd!("rumdl");
cmd.env("RUMDL_OUTPUT_FORMAT", "github")
.arg("check")
.arg("--output-format")
.arg("azure")
.arg(test_file.to_str().unwrap());
cmd.assert()
.failure()
.stdout(predicate::str::contains("##vso[task.logissue type=warning;"));
}
#[test]
fn test_rumdl_output_format_env_var_overrides_config() {
let temp_dir = tempdir().unwrap();
let test_file = temp_dir.path().join("test.md");
let config_file = temp_dir.path().join(".rumdl.toml");
let config_content = r#"[global]
output-format = "pylint"
"#;
let md_content = format!(
r#"# Heading
Content with trailing space{}
"#,
" "
);
fs::write(&test_file, md_content).unwrap();
fs::write(&config_file, config_content).unwrap();
let mut cmd = cargo_bin_cmd!("rumdl");
cmd.current_dir(&temp_dir)
.env("RUMDL_OUTPUT_FORMAT", "azure")
.arg("check")
.arg("test.md");
cmd.assert()
.failure()
.stdout(predicate::str::contains("##vso[task.logissue type=warning;"));
}