Skip to content

Commit

Permalink
test: add unit test for trailing whitespace
Browse files Browse the repository at this point in the history
I guess this worked already?
  • Loading branch information
suo committed Aug 25, 2022
1 parent 277a93d commit bbbcffd
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use assert_cmd::Command;
use insta::{assert_yaml_snapshot, assert_snapshot};
use insta::{assert_snapshot, assert_yaml_snapshot};
use lintrunner::lint_message::{LintMessage, LintSeverity};
use regex::Regex;
use serde_json;
Expand Down Expand Up @@ -703,3 +703,50 @@ fn tee_json() -> Result<()> {

Ok(())
}

#[test]
fn linter_replacement_trailing_newlines() -> Result<()> {
let data_path = tempfile::tempdir()?;
let lint_message = LintMessage {
path: Some("tests/fixtures/fake_source_file.rs".to_string()),
line: Some(9),
char: Some(1),
code: "DUMMY".to_string(),
name: "dummy failure".to_string(),
severity: LintSeverity::Advice,
original: Some(
"\
foo \n\
bar \n\
baz \n\
foo \n\
"
.to_string(),
),
replacement: Some(
"\
foo\n\
bar\n\
baz\n\
foo\n\
"
.to_string(),
),
description: Some("A dummy linter failure".to_string()),
};
let config = temp_config_returning_msg(lint_message)?;

let mut cmd = Command::cargo_bin("lintrunner")?;
cmd.arg(format!("--config={}", config.path().to_str().unwrap()));
cmd.arg(format!(
"--data-path={}",
data_path.path().to_str().unwrap()
));
cmd.arg(format!("--force-color"));
// Run on a file to ensure that the linter is run.
cmd.arg("README.md");
cmd.assert().failure();
assert_output_snapshot("linter_replacement_trailing_newlines", &mut cmd)?;

Ok(())
}

0 comments on commit bbbcffd

Please sign in to comment.