Skip to content

Commit bbbcffd

Browse files
committed
test: add unit test for trailing whitespace
I guess this worked already?
1 parent 277a93d commit bbbcffd

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

tests/integration_test.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use assert_cmd::Command;
3-
use insta::{assert_yaml_snapshot, assert_snapshot};
3+
use insta::{assert_snapshot, assert_yaml_snapshot};
44
use lintrunner::lint_message::{LintMessage, LintSeverity};
55
use regex::Regex;
66
use serde_json;
@@ -703,3 +703,50 @@ fn tee_json() -> Result<()> {
703703

704704
Ok(())
705705
}
706+
707+
#[test]
708+
fn linter_replacement_trailing_newlines() -> Result<()> {
709+
let data_path = tempfile::tempdir()?;
710+
let lint_message = LintMessage {
711+
path: Some("tests/fixtures/fake_source_file.rs".to_string()),
712+
line: Some(9),
713+
char: Some(1),
714+
code: "DUMMY".to_string(),
715+
name: "dummy failure".to_string(),
716+
severity: LintSeverity::Advice,
717+
original: Some(
718+
"\
719+
foo \n\
720+
bar \n\
721+
baz \n\
722+
foo \n\
723+
"
724+
.to_string(),
725+
),
726+
replacement: Some(
727+
"\
728+
foo\n\
729+
bar\n\
730+
baz\n\
731+
foo\n\
732+
"
733+
.to_string(),
734+
),
735+
description: Some("A dummy linter failure".to_string()),
736+
};
737+
let config = temp_config_returning_msg(lint_message)?;
738+
739+
let mut cmd = Command::cargo_bin("lintrunner")?;
740+
cmd.arg(format!("--config={}", config.path().to_str().unwrap()));
741+
cmd.arg(format!(
742+
"--data-path={}",
743+
data_path.path().to_str().unwrap()
744+
));
745+
cmd.arg(format!("--force-color"));
746+
// Run on a file to ensure that the linter is run.
747+
cmd.arg("README.md");
748+
cmd.assert().failure();
749+
assert_output_snapshot("linter_replacement_trailing_newlines", &mut cmd)?;
750+
751+
Ok(())
752+
}

0 commit comments

Comments
 (0)