Skip to content

Commit

Permalink
Add integration tests for output verification
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse committed Aug 14, 2023
1 parent 50ea93c commit c4cd82c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ mod tests {
&self.settings,
Some(cache),
flags::Noqa::Enabled,
flags::FixMode::Generate,
flags::FixMode::Generate(true),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ mod test {
&Overrides::default(),
flags::Cache::Disabled,
flags::Noqa::Disabled,
flags::FixMode::Generate,
flags::FixMode::Generate(true),
)
.unwrap();
let mut output = Vec::new();
Expand Down
58 changes: 58 additions & 0 deletions crates/ruff_cli/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,63 @@ fn unreadable_dir() -> Result<()> {
str::from_utf8(&output.get_output().stderr)?,
"warning: Encountered error: Permission denied (os error 13)\n"
);

Ok(())
}

#[test]
fn applies_safe_fixes_only() -> Result<()> {
let mut cmd = Command::cargo_bin(BIN_NAME)?;

// `--fix` should only apply safe fixes, but should tell the user about `--fix --unsafe` if
// there are remaining unsafe fixes.
let output = cmd
.args([
"-",
"--format",
"text",
"--isolated",
"--select",
"F601",
"--fix",
])
.write_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n")
.assert()
.failure();
assert_eq!(
str::from_utf8(&output.get_output().stdout)?,
r#"-:1:11: F601 Dictionary key `'a'` repeated
Found 1 error.
1 potentially fixable with the --fix --unsafe options.
"#
);

Ok(())
}

#[test]
fn applies_all_fixes() -> Result<()> {
let mut cmd = Command::cargo_bin(BIN_NAME)?;

// `--fix --unsafe` should apply both safe and unsafe fixes.
let output = cmd
.args([
"-",
"--format",
"text",
"--isolated",
"--select",
"F601,UP034",
"--fix",
"--unsafe",
])
.write_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n")
.assert()
.success();
assert_eq!(
str::from_utf8(&output.get_output().stdout)?,
"x = {'a': 1}\nprint('foo')\n"
);

Ok(())
}

0 comments on commit c4cd82c

Please sign in to comment.